Sie sind auf Seite 1von 24

Experiment No: 1

Aim:-Introduction to C++
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
cout<<"\n";
for(j=1;j<=i;j++)
{
cout<<"\t *";
}
}
getch();
}

Experiment No:-2
Aim:-Control Structure in C++
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b,choice;
float result;
clrscr();
cout<<"Enter the value of a";
cin>>a;
cout<<"Enter the value of b";
cin>>b;
do
{
cout<<"\n Enter the choice:\n1.Addition\n2.Substraction\n3.Multiplication\n4.Division\n5.Exit";
cin>>choice;
switch(choice)
{
case 1:
result=a+b;
break;
case 2:
result=a-b;
break;
case 3:

result=a*b;
break;
case 4:
result=(float)a/b;
break;
case 5: exit(0);
break;
default:
cout<<" \n Enter correct choice \n";
break;
}
cout<<"\n Result is:"<<result;
}
while(choice!=5);
getch();
}

Experiment No:-3
Aim:-Operators in C++
#include<iostream.h>
#include<conio.h>
void main()
{
unsigned int a=60; //60=0011 1100
unsigned int b=13; //13=0000 1101
int c=0;
clrscr();
c=a&b; //12=0000 1100
cout<<"line1-value of c is:"<<c<<endl;
c=a/b; //61=0011 1101
cout<<"line2-value of c is:"<<c<<endl;
c=a^b; //49=0011 0001
cout<<"line3-value of c is:"<<c<<endl;
c=~a;

//-61=1100 0011

cout<<"line4-value of c is:"<<c<<endl;
c=a<<2;

//240=1111 0000

cout<<"line5-value of c is:"<<c<<endl;
c=a>>2; //15=0000 1111
cout<<"line6-value of c is:"<<c<<endl;
getch();
}

Experiment No:-4
Aim:-Implementation of Structure
#include<iostream.h>
#include<conio.h>
struct employee
{
int empid;
char add[10];
int sal;
};
void main()
{
employee e[5];
clrscr();
for(int i=0;i<5;i++)
{
cout<<"\nEneter the employee id:";
cin>>e[i].empid;
cout<<"\nEneter the employee adddress:";
cin>>e[i].add;
cout<<"\nEneter the employee salary:";
cin>>e[i].sal;
}
for(i=0;i<5;i++)
{
cout<<"\n Employee id="<<e[i].empid;
cout<<"\n Employee address="<<e[i].add;

cout<<"\n Employee salary="<<e[i].sal;


}
getch();
}

Experiment No:-5
Aim:-Implementation of Classes and Object
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
public:
void getdata();
void putdata();
};
void student::getdata()
{
cout<<"\nEnter rollno";
cin>>rollno;
cout<<"\n Enter ur name";
cin>>name;
}
void student::putdata()
{
cout<<"\n Roll no is="<<rollno;
cout<<"\n name is= "<<name;
}
void main()
{
student s[3];

clrscr();
for(int i=0;i<3;i++)
{
s[i].getdata();
}
for(i=0;i<3;i++)
{
s[i].putdata();
}
getch();
}

Experiment No:-6
Aim:-Implementation of Constructor and Destructor
Default Constructor:#include<iostream.h>
#include<conio.h>
class rect
{
private:
float l,a,b;
public:
rect()

//default constructer

{
cout<<"\n Enter Length:";
cin>>l;
cout<<"\n Enter breadth:";
cin>>b;
}
void display()
{
a=l*b;
cout<<"Area:"<<a;
}
};
void main()
{
clrscr();
rect r;
r.display();
getch(); }

Parameterized Constructer:#include<iostream.h>
#include<conio.h>
class rect
{
int l,m;

public:
rect(int a, int b) //default constructer
{
l=a;
m=b;
}
void display()
{
cout<<"\n length:"<<l;
cout<<"\n bredth:"<<m;
}
};
void main()
{
clrscr();
rect r1(10,20); //const called implicitly
rect r2=rect(25,50);

//const called explicitly

cout<<"\n obj 1:"<<endl;


r1.display();
cout<<"\n\n obj2:"<<endl;
r2.display();
getch();}

Destructor:#include<iostream.h>
#include<conio.h>
int c=0;
class rect
{
public:
rect()
{
c++;
cout<<"\n No of object created :"<<c;
}
~rect()
{
cout<<"\n No. of object destroyed:"<<c;
c--;
}
};
void main()
{
clrscr();
rect r1,r2;
{
rect r3,r4;
}
getch();
}

Experiment No:-7
Aim:-Implementation of Function Overloading

#include<iostream.h>
#include<conio.h>
int volume (int);
float volume(float,int);
long volume(long,int,int);

int volume(int s)
{
return(s*s*s);
}
float volume(float r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
}
void main()
{
clrscr();
cout<< volume(20)<<"\n";
cout<<volume(3.6,10)<<"\n";
cout<<volume(100,70,10)<<"\n";
getch();
}

Experiment No:-8
Aim:-Implementation of Friend Function
#include<iostream.h>
#include<conio.h>
class sample
{
int a,b;

public:
void setvalue()
{
a=25;
b=40;
}
friend float mean(sample s);
};
float mean(sample s)
{
return float (s.a+s.b)/2.0;
}
void main()
{
clrscr();
sample x;
x.setvalue();
cout<<"\n Mean value:"<<mean(x)<<"\n";
getch();
}

Experiment No:-9
Aim:-Implementation of Inline Function

#include<iostream.h>
#include<conio.h>
inline float mul(float x,float y)
{
return (x*y);
}
inline double div(double p,double q)
{
return(p/q);
}
void main()
{
clrscr();
float a=12.345;
float b=9.82;

cout<<mul(a,b)<<"\n";
cout<<div(a,b)<<"\n";

getch();
}

Experiment No:-10
Aim:-Implementation of Inheritance

#include<iostream.h>
#include<conio.h>
class triangle
{
protected:
float b,h;

public:
void get()
{
cout<<"\n Enter base and height of triangle";
cin>>b>>h;
}
};
class rectangle
{
protected:
float length,breadth;
public:
void getdata()
{
cout<<"\n Enter the length and breadth of rectangle:";
cin>>length>>breadth;
}
};

class area:public triangle,public rectangle


{
protected :
float area;
public:
void areatriangle()
{
area=0.5*b*h;
cout<<"\n area of triangle "<<area<<"in sq mr";
}
void arearectangle()
{
area=length*breadth;
cout<<"\n area of rectangle "<<area<<"in sq mr";
}
};
void main()
{
clrscr();
area a;
a.get();
a.getdata();
a.areatriangle();
a.arearectangle();
getch();
}

Das könnte Ihnen auch gefallen