Beruflich Dokumente
Kultur Dokumente
#include<conio.h>
void main()
int a=10,b=20;
a=a+b;
b=a-b;
a=a-b;
getch();
OUTPUT:
2. /*wap TO PRINT THE DATA
12
123
#include<iostream.h>
#include<conio.h>
void main()
int a;
clrscr();
cin>>a;
for(int i=1;i<=a;i++)
for(int j=1;j<=i;j++)
cout<<j;
cout<<endl;
getch();
Output:
3. /*WAP to print the data
1
21
321
4321
#include<iostream.h>
#include<conio.h>
void main()
int a;
clrscr();
cin>>a;
for(int i=1;i<=a;i++)
for(int j=i;j>=1;j--)
cout<<j;
cout<<endl;
getch();
OUTPUT:
4. /*WAP to use WS manipulator*/
#include<iostream.h>
#include<conio.h>
void main()
char name[20];
cin>>ws;
cin>>name;
getch();
OUTPUT:
5./*WAP to find the biggest number in an array*/
#include<iostream.h>
#include<conio.h>
void main()
int a[10],i,n,big;
clrscr();
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
big=a[0];
for(i=1;i<n;i++)
if(a[i]>big)
big=a[i];
getch();
}
OUTPUT:
6./*WAP to explain the concept of return statement without
condition*/
#include<iostream.h>
#include<conio.h>
int mul(int,int);
void main()
int x,y,z;
cin>>x>>y;
z=mul(x,y);
getch();
int s;
s=p*q;
return(s);
OUTPUT:
7. /*WAP with no argument and no return */
#include<iostream.h>
#include<conio.h>
void si(void);
void printline();
void main()
printline();
si();
printline();
getch();
void printline()
int i;
for(i=1;i<=40;i++)
cout<<"-";
return;
void si()
int p,r,t,s;
cin>>p>>r>>t;
s=(p*r*t)/100;
return;
OUTPUT:
8. /*WAP with argument and with return value*/
#include<iostream.h>
#include<conio.h>
int simple(int,int,int);
void main()
int p,r,t,si;
clrscr();
cin>>p>>r>>t;
si=simple(p,r,t);
getch();
int m;
clrscr();
m=(x*y*z)/100;
return(m);
OUTPUT:
9. /*WAP to using the concept of the value of structure variable of
library data*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
struct library
char title[30];
char author[20];
int pages;
float price;
};
strcpy(book1.author,"AMARDEEP GUPTA");
book1.pages=549;
book1.price=450.50;
getche();
}
OUTPUT:
10. /*WAP to find the average marks of two student having 3 subject
by using array of structure*/
#include<iostream.h>
#include<conio.h>
void main()
struct student
int subject1;
int subject2;
int subject3;
};
int i,n,total;
float av;
cin>>n;
for(i=1;i<=n;i++)
cin>>std[i].subject1>>std[i].subject2>>std[i].subject3;
total=std[i].subject1+std[i].subject2+std[i].subject3;
av=total/3;
getch();
}
OUTPUT:
11. /*WAP to find the average the marks of 2 student having M
subject by using array within structure*/
#include<iostream.h>
#include<conio.h>
void main()
struct student
int rn;
int sub[10];
};
int i,j,total,n,m;
float av;
cin>>n;
cin>>m;
for(i=1;i<=n;i++)
total=0;
for(j=1;j<=m;j++)
cin>>std[i].sub[j];
total=total+std[i].sub[j];
}
av=total/m;
cout<<"Average="<<av<<endl;
getch();
OUTPUT:
12. /*WAP to read and display student data to using passing
structure to function*/
#include<iostream.h>
#include<conio.h>
struct student
int rn;
char name[20];
char grade;
}s;
void main()
clrscr();
cin>>s.rn>>s.name>>s.grade;
display(s);
getch();
void display(student m)
return;
}
OUTPUT:
13. /*WAP to change the price of book by using structure with
function*/
#include<iostream.h>
#include<conio.h>
struct book
char title[20];
char author[20];
int price;
};
void main()
clrscr();
book a;
cin>>a.price;
a=change(a);
getch();
b.price+=100;
return b;
}
OUTPUT:
14. /*WAP to find the Factorial of a number using structure*/
#include<iostream.h>
#include<conio.h>
struct fact
int n;
}s;
void main()
clrscr();
cin>>s.n;
int m=1;
for(int i=1;i<=s.n;i++)
m=m*i;
getch();
OUTPUT:
15. /*WAP to print the record of a student by using structure*/
#include<iostream.h>
#include<conio.h>
void main()
struct student
int rollno;
char name[20];
char classes[20];
float fees;
};
cin>>st1.rollno>>st1.name>>st1.classes>>st1.fees;
getch();
}
OUTPUT:
16. /*WAP to use the concept of one class with one object by taking
student data*/
#include<iostream.h>
#include<conio.h>
class student
private:
int rn;
char name[20];
public:
void read()
cin>>rn;
cin>>name;
void write()
};
void main()
std1.read();
std1.write();
getch();
OUTPUT:
17. /*WAP to use the concept of one class with two object*/
#include<iostream.h>
#include<conio.h>
class student
private:
int rn;
char name[20];
public:
void read()
cin>>rn;
cin>>name;
void write()
};
void main()
clrscr();
std1.read();
std1.write();
std2.read();
std2.write();
getch();
OUTPUT:
18. /*WAP to show the relationship of class and object by taking
student data*/
#include<iostream.h>
#include<conio.h>
void main(void)
class student
public:
};
st.rn=227;
st.fees=45000;
getch();
OUTPUT:
19. /*WAP to define the member function outside the class*/
#include<iostream.h>
#include<conio.h>
class account
private:
int accno;
char name[20];
float bal;
public:
void read();
void write();
};
void account::read()
cin>>accno>>name>>bal;
void account::write()
void main()
{
clrscr();
a1.read();
a1.write();
getch();
OUTPUT:
20. /*WAP to find a number is even or odd by using inline function*/
#include<iostream.h>
#include<conio.h>
return !(n%2);
void main()
int a;
clrscr();
cin>>a;
if(even(a))
cout<<a<<"is even";
else
cout<<a<<"is odd";
getch();
OUTPUT:
21. /*WAP to use Friend Class*/
#include<iostream.h>
#include<conio.h>
class xxx
private:
int x,y;
public:
x=xx;y=yy;
};
class yyy
public:
cout<<"x="<<objx.x;
cout<<"\n y="<<objy.y;
}
};
void main()
xxx ob1(10,15);
yyy ob2;
ob2.f1(ob1);
ob2.f2(ob1);
getch();
OUTPUT:
22. /*WAP to define Virtual Destructor*/
#include<iostream.h>
#include<conio.h>
class Base
public:
// this is a destructor:
};
public:
};
void main()
delete basePtr;
}
Output:
Constructing Base
Constructing Derive
23. /*WAP to display and read rollno and fees to use the Dynamic
Constructor*/
#include<iostream.h>
#include<conio.h>
class abc
int rn;
float fees;
public:
abc(int a,float b)
rn=a;
fees=b;
abc(abc&m)
rn=m.rn;
fees=m.fees;
};
void main()
clrscr();
int x;
float y;
cout<<"\n Enter the rollno of the student";
cin>>x;
cin>>y;
abc m1(x,y);
getch();
OUTPUT:
24. /*WAP to define Constructor and Destructor*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
private:
int rn;
char name[20];
public:
rn=27;
strcpy(name,"SUKHBINDER");
void dispdata()
cout<<"Destructor invoked";
};
void main()
{
clrscr();
s1.dispdata();
getch();
OUTPUT:
25. /*WAP to set Overloading of Constructor*/
#include<iostream.h>
#include<conio.h>
class student
private:
int rn;
public:
student()
rn=0;
student(int n)
rn=n;
} //overloading of constructor
void getdata()
cin>>rn;
void dispdata()
{
cout<<"\n ROLL NUMBER is:"<<rn;
};
void main()
clrscr();
class student a;
a.getdata();
a.dispdata();
b.dispdata();
getch();
OUTPUT:
26. /*WAP to Assignment operator overloading*/
#include<iostream.h>
#include<conio.h>
class abc
private:
int a;
float b;
public:
abc(int,float);
void display();
};
abc::abc(int x,float y)
a=x;
b=y;
void abc::display()
void main ()
clrscr();
abc m1(10,22.2);
abc m2(30,7.7);
m1.display();
m2.display();
getch();
OUTPUT:
27. /*WAP of Single Inheritance*/
#include<iostream.h>
#include<conio.h>
class abc
protected:
char name[20];
char village[10];
int age;
};
float hight;
float weight;
public:
void getdata()
cin>>name>>village>>age;
cin>>hight>>weight;
void show()
};
void main()
clrscr();
abcd x;
x.getdata();
x.show();
getch();
OUTPUT:
28. /*WAP to initialize the pointer values*/
#include<iostream.h>
#include<conio.h>
void main()
int x,*q;
x=200;
q=&x;
getch();
OUTPUT:
29. /*WAP to access the value by using pointer*/
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
char ab;
int x;
float p,q;
ab='Z';
x=28;
p=3.12;
q=4.7;
getch();
OUTPUT:
30. /*WAP to using the concept of Pointer to Pointer*/
#include<iostream.h>
#include<conio.h>
void main(void)
int a,*p1,**p2;
clrscr();
a=27;
p1=&a;
p2=&p1;
getch();
OUTPUT:
31. /*WAP to print a table using Pointer*/
#include<iostream.h>
#include<conio.h>
void main()
int n,i,p,*pt;
clrscr();
cin>>n;
*pt=1;
do
p=*pt*n;
cout<<n<<"*"<<*pt<<"="<<p<<endl;
(*pt)++;
while(*pt<=10);
getch();
OUTPUT:
32. /*WAP to use of Overloading function*/
#include<iostream.h>
#include<conio.h>
void display(int a)
cout<<a;
cout<<a<<endl;
cout<<n;
void main()
clrscr();
void display(int);
void display(int,int);
int a=10;
int b=20;
display(a);
display(a,b);
getch();
OUTPUT:
33. /*WAP to use Virtual function*/
#include<iostream.h>
#include<conio.h>
class base
public:
cout<<"\n Base";
};
public:
void display()
cout<<"\n Derived";
};
void main()
ptr->display();
getch();
OUTPUT:
34. /*WAP to illustrate the concept of Static Binding(Early Binding)*/
#include<iostream.h>
#include<conio.h>
class base
public:
void display()
cout<<"\n Base";
};
public:
void display()
cout<<"\n Derived";
};
void main()
ptr->display();
getch();
OUTPUT:
35. /*WAP to using the Write() function from the file*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
int main()
ofstream myfile;
myfile.open("example.txt");
myfile.close();
return 0;
}
36. /*WAP to using the Read() function from the file*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
int main()
ofstream abc;
abc.open("Raj.dat");
for(int i=1;i<=100;i++)
abc<<i<<endl;
abc.close();
return 0;
}
37./*WAP to read a number from a text file*/
#include<iostream.h>
#include<fstream.h>
int n;
void main()
ifstream num;
num.open("Sukhbinder");
num>>n;
cout<<"output is"<<n;
num.close();