Beruflich Dokumente
Kultur Dokumente
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int r,s;
clrscr();
cout<<"Enter first number =";
cin>>r;
cout<<"Enter second number =";
cin>>s;
if((s%r==0))
cout<<r<<" is multiple of ="<<s<<endl;
else
cout<<r<<"is not multiple of = "<<s<<endl;
getch();
}
Output:
#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int n,q,c1,c2,c3,c4,c5;
float price,s1,s2,s3,s4,s5;
char ch;
float sum;
clrscr();
do
{
cout<<"product 1:Rs 40.95 \nproduct 2:Rs 99.15 \nproduct 3:Rs 127.50
\nproduct 4:Rs 265 \nproduct 5:Rs 796.10";
cout<<"\nenter product no:";
cin>>n;
cout<<"\nenter qty:";
cin>>q;
switch(n)
{
case 1:
c1++;
price=40.95;
s1=s1+(price*q);
break;
case 2:
c2++;
price=99.15;
s2=s2+(price*q);
break;
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
case 3:
c3++;
price=127.50;
s3=s3+(price*q);
break;
case 4:
c4++;
price=265.00;
s4=s4+(price*q);
break;
case 5:
c5++;
price=796.10;
s5=s5+(price*q);
break;
}
cout<<"do u want to continue:";
cin>>ch;
}while(ch=='y' || ch=='Y');
sum=s1+s2+s3+s4+s5;
cout<<"total retail value:"<<sum;
getch();
}
Output:
enter qty:25
do u want to continue:n
total retail value:1023.75
void fibo(int,int,int,int);
#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int n,a=0,b=1,i=3;
clrscr();
cout<<"\n enter no of terms u want to display:";
cin>>n;
cout<<"\n FABONACCI SERIES";
if(n==1)
cout<<"\n"<<a;
else
{
cout<<"\n"<<a<<"\n"<<b;
fibo(a,b,n,i);
}
getch();
}
void fibo(int a,int b,int n,int i)
{
int c;
if(i<=n)
{
c=a+b;
cout<<"\n"<<c;
a=b;
b=c;
i++;
fibo(a,b,n,i);
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void sqr(int);
void sqr(int,int);
void main()
{
int a,b;
clrscr();
cout<<"Enter first number = ";
cin>>a;
cout<<"Enter second number = ";
cin>>b;
sqr(a);
sqr(a,b);
getch();
}
void sqr(int x)
{
int y=x*x;
cout<<"square is = "<<y<<endl;
}
void sqr(int x,int y)
{
int z;
z=x*y;
cout<<"product is = "<<z;
}
Output:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#define PI 3.14159
inline float circlearea(float r)
{
float area;
area=PI*r*r;
return(area);
}
void main()
{
float radius;
clrscr();
cout<<"Enter radius of circle";
cin>>radius;
cout<<"Area of circle is = "<<circlearea(radius);
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int value(int);
int adress(int*);
int reference(int&);
void main()
{
int a;
clrscr();
cout<<"Enter any number ";
cin>>a;
cout<<"triplicate value using call by value = "<<value(a)<<endl;
cout<<"triplicate value using call by adress = "<<adress(&a)<<endl;
cout<<"triplicate value using call by reference = "<<reference(a)<<endl;
getch();
}
int value(int a)
{
return(a*a*a);
}
int adress(int *a)
{
return((*a)*(*a)*(*a));
}
int reference(int &a)
{
return(a*a*a);
}
Output:
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
Enter any number 25
triplicate value using call by value = 15625
triplicate value using call by adress = 15625
triplicate value using call by reference = 15625
#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[20],a[20];
clrscr();
int p=0;
int fl=0;
cout<<"Enter 20 nos(10-100)inclusive:";
for(int i=0;i<20;i++)
{
cin>>arr[i];
for(int j=0;j<i;j++)
{
if(arr[i]==arr[j])
{
fl=1;
break;
}
}
if(fl!=1)
a[p++]=arr[i];
}
cout<<"Elements are ";
for(i=0;i<p;i++)
{
cout<<endl<<a[i];
}
if(p==20)
{
cout<<"\nElements are unique";
}
Enter 20 nos(10-100)inclusive:55
54
52
58
59
57
65
64
62
63
67
12
22
23
30
47
85
99
97
11
Elements are
55
54
52
58
59
57
65
64
62
63
67
12
22
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int rec(int[],int);
void main()
{
int a[15],n,min,i;
clrscr();
cout<<"Enter the size of array";
cin>>n;
cout<<"Enter the element of array";
for(i=0;i<n;i++)
{
cin>>a[i];
}
min=rec(a,n);
cout<<"Minimum number is = "<<min;
getch();
}
Output:
#include<conio.h>
#include<iostream.h>
# include<string.h>
void main()
{
char str[50],ch;
int count=0;
int i,n;
clrscr();
cout<<"Enter any character :";
cin>>str;
cout<<endl;
n=strlen(str);
cout<<"Enter the chracter which you want to search: \n" ;
cin>>ch;
for(i=0;i<n;i++)
{
if(ch==str[i])
{
count++;
}
}
cout<<"The character "<<ch<<" occur "<<count<<" Times\n";
getch();
}
Output:
#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int a[10][15],m,n,sum=0,sumc=0,sumr=0;
clrscr();
cout<<"\nenter no of stores in chain(<=10) and department in each
store(<=15):";
cin>>m>>n;
cout<<"enter weekly sales of each dept:";
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<"\nenter weekly sale of "<<i+1<<" store's"<<j+1<<"dept:";
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
sumr=0;
for(int j=0;j<n;j++)
{
sum+=a[i][j];
sumr+=a[i][j];
}
cout<<"\ntotal weekly sales of "<<i+1<<" store: "<<sumr;
}
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
for(int j=0;j<n;j++)
{
sumc=0;
for(int i=0;i<m;i++)
{
sumc+=a[i][j];
}
cout<<"\ntotal weekly sales of "<<j+1<<" dept: "<<sumc;
}
cout<<"\n total weekly sales of chain:"<<sum;
getch();
}
Output:
#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
void main()
{
int a[20][20],m,n,count=0,c[20][20],max=0,max1=0;
clrscr();
cout<<"enter rows and columns of matrix:\n";
cin>>m>>n;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
count=0;
for(int j=0;j<n;j++)
{
if(a[i][j]<0)
{
c[i][j]=++count;
}
if(max<count)
{
max=count;
max1=i+1;
}
}
cout<<"row containing no of negative terms"<<i+1<<":"<<count<<endl;
}
#include<conio.h>
#include<iomanip.h>
#include<iostream.h>
#include<string.h>
struct state
{
char name[20];
char cap[20];
char cm[20];
}s1;
void main()
{
int n;
clrscr();
cout<<"1.to know abt capital of state and its CM\n2.to know abt name of
state and its capital\n3.to know abt name of state and its CM\n";
cout<<"enter your choice\n";
cin>>n;
if(n==1)
{
cout<<"1.punjab\t2.haryana\t3.himachal pradesh\n";
cout<<"enter name of state:";
cin>>s1.name;
if(strcmpi(s1.name,"punjab")==0)
{
cout<<"capital=Chandigarh \t CM=Mr Prakash singh badal\n";
}
else if(strcmpi(s1.name,"haryana")==0)
getch();
}
Output:
#include<iostream.h>
#include<conio.h>
class employee
{
char name[17];
float salary;
float bonus;
public:
void input();
float computebonus(float);
void display();
};
void employee::input()
{
cout<<"\nEnter your name:";
cin>>name;
cout<<"\nEnter your salary:";
cin>>salary;
bonus=computebonus(salary);
}
float employee::computebonus(float a)
{
if(a<5000)
return(((a*10)/100));
else
return(((a*15)/100));
}
void employee::display()
{
cout<<"\nName:"<<name<<"\tSalary:"<<salary<<"\tBonus:"<<bonus;
}
void main()
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
int count=0;
class sample
{
public:
sample()
{
count++;
cout<<"\n constructor invoked"<<"\n current object count="<<count<<endl;
}
~sample()
{
count--;
cout<<"\n destructor invoked"<<"\n current object count="<<count<<endl;
}
};
void main()
{
cout<<"\n main block";
sample s1,s2,s3;
{
cout<<"\n first nested block\n";
sample s4;
cout<<" leaving first block";
}
{
cout<<"\n second nested block\n";
sample s5;
cout<<"\n leaving second block";
}
cout<<"\nout of main block";
getch();
}
VISIT www.educationjockey.com for old papers, practical file samples.
This file is for reference purpose only.
Output:
main block
constructor invoked
current object count=1
constructor invoked
current object count=2
constructor invoked
current object count=3
constructor invoked
current object count=4
leaving first block
destructor invoked
current object count=3
constructor invoked
current object count=4
destructor invoked
current object count=1
#include<iostream.h>
#include<conio.h>
class time
{
int hrs;
int mint;
public:
time()
{
hrs=0;
mint=0;
}
time(int h,int m)
{
hrs=h;
mint=m;
}
time(int m)
{
hrs=m/60;
mint=m%60;
}
void display()
{
cout<<"\nhours"<<hrs<<"\nmint"<<mint;
}
};
void main()
{
clrscr();
time t1,t2(4,65);
#include<iostream.h>
#include<conio.h>
class time
{
int hrs;
int mint;
public:
time()
{
hrs=0;
mint=0;
}
time(int h,int m)
{
hrs=h;
mint=m;
}
operator int()
{
return((hrs*60)+mint);
}
void display()
{
cout<<"\nhours"<<hrs<<"\nmint"<<mint;
}
};
void main()
{
clrscr();
time t1,t2(1,30);
int m=t2;
cout<<m;
getch();
}
Output:
90
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
fstream file;
file.open("seema.txt",ios::in,ios::out);
int n,i;
char ch[40];
cout<<"Enter number of chars you want to enter :";
cin>>n;
cout<<"\nEnter characters:";
for(i=0;i<n;i++)
{
cin>>ch[i];
file.put(ch[i]);
}
file.seekg(0);
cout<<"\nCharacter read from file:";
for(i=0;i<n;i++)
{
file.get(ch[i]);
cout<<ch[i];
}
getch();
}
Output:
WAP to copy the contents of one file byte by byte. The names of files are
taken as command line argument.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main(int argc,char *argv[])
{
char ch;
ifstream file1(argv[1],ios::binary);
ofstream file2(argv[2],ios::binary);
if(argc!=3)
cout<<"error in input";
else
while(!file1.eof())
{
file1.get(ch);
file2.put(ch);
}
getch();
}
Output:
D:\>type sachin1.txt
hi i am sachin.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
int i;
ifstream file("s.txt");
char ch;
cout<<"vowels:";
while(file)
{
file.get(ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
cout<<ch;
}
i=file.tellg();
cout<<"\ntotal number of characters"<<i;
getch();
}
Output:
vowels:i
total number of characters3