Professional Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int x,y=1;
cin>>x;
for(int i=1;i<=x;i++)
y=y*i;
cout<<"Factorial="<<y;
getch();
Page 1
PROGRAM-2
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a=1,b=2,c=0,d;
cin>>d;
while(c<=d)
c=a+b;
cout<<c;
a=b;
b=c;
cout<<" ";
c++;
getch();
Page 2
Page 3
PROGRAM-3
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int x,y;
cout<<"value of x:";
cin>>x;
cout<<"value of y:";
cin>>y;
if(x>y)
if(y>x)
getch();
Page 4
PROGRAM-4
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int n;
cout<<"number=";
cin>>n;
if(n%2==0)
cout<<"number is even";
else
cout<<"number is odd";
getch();
Page 5
PROGRAM-5
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int x,y,z;
cout<<"value of x:";
cin>>x;
cout<<"value of y:";
cin>>y;
cout<<”value of z:";
cin>>z;
if(x>y&&x>z)
else if(b>a&&b>c)
else
getch();
Page 6
Page 7
PROGRAM-6
#include<iostream.h>
#include<conio.h>
class complex
int i,r;
public:
void input()
cout<<"real part:";
cin>>r;
cout<<"imaginary part:";
cin>>i;
complex t;
t.r=r+c.r;
t.i=i+c.i;
return(t);
void output()
Page 8
cout<<r<<"+i"<<i<<endl;
};
void main()
clrscr();
complex c1,c2,c3;
c1.input();
c2.input();
cout<<"complex c1:";
c1.output();
cout<<"complex c2:";
c2.output();
cout<<"complex c3:";
c3=c1+c2;
c3.output();
getch();
Page 9
PROGRAM-7
#include<iostream.h>
#include<conio.h>
class data
public:
cout<<"value of x:"<<x<<endl;
cout<<"value of y:"<<y<<endl;
cout<<"value of a:"<<a<<endl;
cout<<"value of b:"<<b<<endl;
cin>>b;
};
void main()
clrscr();
data d;
d.input(3,5);
Page 10
d.input(5656,6554);
getch();
Page 11
PROGRAM-8
#include<iostream.h>
#include<conio.h>
class complex
int r1,r2,i1,i2,r,i;
public:
complex()
r1=4;
r2=3;
i1=5;
i2=6;
void getdata()
cout<<"Complex 1:-"<<r1<<"+i"<<i1<<endl;
cout<<"Complex 2:-"<<r2<<"+i"<<i2<<endl;
r=r1+r2;
i=i1+i2;
void display()
Page 12
cout<<"Sum "<<r<<"+i"<<i;
};
void main()
clrscr();
complex c1;
c1.getdata();
c1.display();
getch();
Page 13
PROGRAM-9
#include<iostream.h>
#include<conio.h>
class complex
int r1,r2,i1,i2,r,i;
public:
r1=a;
r2=b;
i1=c;
i2=d;
void getdata()
cout<<"Complex no.1:-"<<r1<<"+i"<<i1<<endl;
cout<<"Complex no.2:-"<<r2<<"+i"<<i2<<endl;
r=r1-r2;
i=i1-i2;
void display()
Page 14
cout<<"difference "<<r<<"+i"<<i;
};
void main()
clrscr();
complex c(7,3,8,6);
c.getdata();
c.display();
getch();
Page 15
PROGRAM-10
AIM:-Program to display name and roll number of student using single inheritance.
#include<iostream.h>
#include<conio.h>
class student
protected:
char n[10];
public:
void getdata()
cout<<"name of student:";
cin>>n;
};
long r;
public:
void roll()
cin>>r;
Page 16
void displaydata()
cout<<"Name-"<<n<<endl<<"Roll No.-"<<r;
};
void main()
clrscr();
rollnumber r1;
r1.getdata();
r1.roll();
clrscr();
r1.displaydata();
getch();
Input:
Output:
Page 17
PROGRAM-11
#include<iostream.h>
#include<conio.h>
class student
protected:
char n[10];
public:
void getdata()
cout<<"name of student:";
cin>>n;
};
protected:
int mar[5],total;
public:
void getmarks();
};
void marks::getmarks()
Page 18
cout<<"marks of "<<name<<":";
total=0;
for(int i=0;i<5;i++)
cin>>mar[i];
total=total+mar[i];
float avg;
public:
void getresult()
avg=total/5;
};
void main()
clrscr();
result r;
r.getdata();
r.getmarks();
Page 19
r.getresult();
getch();
Page 20
PROGRAM-12
#include<iostream.h>
#include<conio.h>
class complexb
protected:
int r1,i1;
public:
void getdata()
cin>>r1;
cin>>i1;
cout<<"Complex no.1:"<<r1<<"+i"<<i1<<endl;
};
class compd
protected:
int r2,i2;
public:
void get()
Page 21
{
cin>>r2;
cin>>i2;
cout<<"Complex no.2:"<<r2<<"+i"<<i2<<endl;
};
int r,i;
public:
void display()
r=r1+r2;
i=i1+i2;
cout<<"sum"<<r<<"+i"<<i;
};
void main()
clrscr();
add a;
a.getdata();
Page 22
a.get();
a.display();
getch();
Page 23
PROGRAM-13
AIM:-Program to display the result of any student using multilevel inheritance of virtual base
class.
#include<iostream.h>
#include<conio.h>
class student
protected:
char n[10];
public:
void getdata()
cout<<”name of student:";
cin>>n;
};
protected:
int m[5],total;
public:
void getmarks();
};
void marks::getmarks()
{
Page 24
cout<<”marks of "<<name<<":";
total=0;
for(int i=0;i<5;i++)
cin>>m[i];
total=total+mar[i];
float avg;
public:
void getresult()
avg=total/5;
};
void main()
clrscr();
result r;
r.getdata();
r.getmarks();
Page 25
r.getresult();
getch();
PROGRAM-14
Page 26
AIM:-Program to display the result of a student using hierarchal inheritance.
#include<iostream.h>
#include<conio.h>
class student
protected:
char n[10];
public:
void getdata()
cout<<"name of student:";
cin>>n;
};
protected:
long r;
public:
void getroll()
cin>>r;
Page 27
};
protected:
int m[5],total;
public:
void getmarks();
};
void marks::getmarks()
cout<<"marks of "<<name<<":";
total=0;
for(int i=0;i<5;i++)
cin>>mar[i];
total=total+mar[i];
float avg;
public:
void getresult()
Page 28
avg=total/5;
};
void main()
clrscr();
result r;
r.getdata();
r.getroll();
r.getmarks();
r.getresult();
getch();
PROGRAM-15
Page 29
Aim:-Program to find address of variable using pointers.
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a,*i;
cin>>a;
i=&a;
getch();
PROGRAM-16
Page 30
AIM:-Program to add two numbers and copy it to another variable using copy constructor.
#include<iostream.h>
#include<conio.h>
class add
int a,b;
public:
add(int x, int y)
a=x;
b=y;
add(add &i)
a=i.a;
b=i.b;
void showdata();
};
void add::showdata()
Page 31
void main()
clrscr();
add a(3,6);
add a1(a);
a.showdata();
getch();
Page 32
PROGRAM-17
#include<iostream.h>
#include<conio.h>
class add
int a,b;
public:
add()
a=0;
b=0;
add(int x, int y)
a=x;
b=y;
add(add &i)
a=i.a;
b=i.b;
void showdata();
Page 33
};
void add::showdata()
void main()
clrscr();
add a1;
add a2(5,7);
add a3(a2);
a1.showdata();
a2.showdata();
a3.showdata();
getch();
Page 34
PROGRAM-18
#include<iostream.h>
#include<conio.h>
class salary;
class employee
char name[10];
public:
};
class salary
int slr;
public:
};
cin>>e.name;
cin>>s1.slr;
Page 35
void main()
clrscr();
employee e;
salary s1;
getdata(e,s1);
getch();
Page 36
PROGRAM-19
AIM:- WAP to demonstrate the arithmetic operation after assigning the value of two variable.
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a,b,c,d,e,f;
cin>>a>>b;
c=a+b;
cout<<"Sum: "<<c<<endl;
d=a*b;
cout<<"Multiplication:"<<d<<endl;
e=a/b;
cout<<"Divide:"<<e<<endl;
f=a-b;
cout<<"Subtract:"<<f;
getch();
Page 37
PROGRAM-20
#include<iostream.h>
#include<conio.h>
class add
int a,b;
public:
add()
x=7;
cout<<”Value of x=”<<x<<endl;
y=3;
cout<<”Value of y=”<<y<<endl;
~add()
x=0;
cout<<”Value of x=”<<x<<endl;
y=0;
cout<<”Value of y=”<<y<<endl;
};
Page 38
void main()
clrscr();
add a;
getch();
Page 39
PROGRAM-21
#include<iostream.h>
#include<conio.h>
class xyz;
class abc
int a;
public:
};
class xyz
int x;
public:
};
int temp;
cin>>a1.a;
Page 40
cin>>x1.x;
temp=a1.a+x1.x;
cout<<"Sum="<<temp;
void main()
clrscr();
abc a1;
xyz x1;
getdata(a1,x1);
getch();
Page 41
PROGRAM-22
# include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()
clrscr();
int a=2,b=4;
cout<<"BEFORE SWAPPING"<<endl;
cout<<"AFTER SWAPPING"<<endl;
swap(a,b);
cout<<"AFTER SWAPPING"<<endl;
getch();
int t;
t=x;
x=y;
y=t;
Page 42
cout<<"Value of a:"<<x<<endl<<"Value of b:"<<y<<endl;
Page 43
PROGRAM-23
# include<iostream.h>
#include<conio.h>
void swap(int&,int&);
void main()
clrscr();
int a=2,b=4;
cout<<"BEFORE SWAPPING"<<endl;
cout<<"AFTER SWAPPING"<<endl;
swap(a,b);
cout<<"AFTER SWAPPING"<<endl;
getch();
int t;
t=x;
x=y;
y=t;
Page 44
cout<<"Value of a:"<<x<<endl<<"Value of b:"<<y<<endl;
Page 45
PROGRAM-24
#include<iostream.h>
#include<conio.h>
class example
private:
int a;
public:
void getdata(int b)
this->a=b;
void showdata()
cout<<"Value of a="<<this->a<<endl;
};
void main()
clrscr();
example e;
Page 46
e.getdata(7);
e.showdata();
getch();
Page 47