0% found this document useful (0 votes)
6 views29 pages

CPP Pranit

The document outlines a series of C++ programming experiments, each demonstrating different programming concepts such as scope resolution, function overloading, call by value and reference, friend functions, constructors and destructors, tokens, inheritance, polymorphism, and operator overloading. Each experiment includes code snippets and their expected outputs. The experiments are structured with titles, code examples, and comments indicating the purpose of each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views29 pages

CPP Pranit

The document outlines a series of C++ programming experiments, each demonstrating different programming concepts such as scope resolution, function overloading, call by value and reference, friend functions, constructors and destructors, tokens, inheritance, polymorphism, and operator overloading. Each experiment includes code snippets and their expected outputs. The experiments are structured with titles, code examples, and comments indicating the purpose of each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Experiment No.

1
Date: / /
Roll No:140

Title: C++ program on manipulation of scope Resolution


Operator .
#include<iostream.h>
#include<conio.h>
class EODD{
int x;
public:
void getdata();
void check();
};
void EODD::getdata()
{
cout<<"Enter Number: ";
cin>>x;
}
void EODD::check()
{ if(x
%2==0)
cout<<x<<" is even";
else
cout<<x<<" is odd";
}
void main()
{
EODD obj;
clrscr();
obj.getdata();
obj.check();
getch();
}

Output :
Experiment No.2
Date: / /
Roll No:140

Title: Write a CPP program on Function Overloading .

#include<conio.h>
#include<iostream.h>
void add(int a,int b);
void add(int a,int b,int c);
void main()
{
clrscr();
add(5,8);
add(10,99,12);
getch();
}
void add(int a,int b)
{
cout<<"Addition:"<<a+b<<endl;
}
void add(int a,int b,int c)
{
cout<<"Addition:"<<a+b+c<<endl;
}
Output:
Experiment No.3
Date: / /
Roll No:140

Title: CPP program on fuction by call by value and call by


reference.
#include<iostream.h>
#include<conio.h>
void swap(int *a,int *b);
void change(int x);
void main()
{
int
a=876,b=560;
int x=65;
clrscr();
change(x);
cout<<"Value is:"<<x<<endl;
swap(&a,&b);
cout<<"value of a: "<<a<<endl;
cout<<"Value of b: "<<b;
getch();
}
void swap(int *a,int *b)
{
int swap;
swap=*a;
*a=*b;
*b=swap;
}
void change(int x)
{ x=
3;
}

Output :
Experiment No
4 Date: / /
Roll No:140

Title : C++ program on Friend Function and Friend Class .

#include<iostream.h>
#include<conio.h>
class XYZ;
class ABC{
int X;
public:
void getdata();
friend void AOpertn(ABC,XYZ);
};
class XYZ{
int Y;
public:
void getdata();
friend void AOpertn(ABC,XYZ);
};
void ABC::getdata()
{ cout<<"Enter 1st number:";
cin>>X;
}
void XYZ::getdata()
{ cout<<"Enter 2nd Number:";
cin>>Y;
}
void AOpertn(ABC aa,XYZ bb){
cout<<"Addition:"<<aa.X+bb.Y;
}
void main()
{
ABC aa;
XYZ bb;
aa.getdata();
bb.getdata();
AOpertn(aa,bb);
getch();
}

Output :
Experiment No.5
Date: / /
Roll No:140

Title:C++ program to manipulate constructor and destructor.


1)Default Constructor
: #include<iostream.h>
#include<conio.h>
class abc{
public:
abc()
{
cout<<"This is an Default Constructor";
}};
void main()
{
abc aa;
getch();
}

Output:
2) Parameterized Constructor:
#include<iostream.h>
#include<conio.h>
class abc{
int a;
public:
abc(int x)
{
a=x;
}
void putdata()
{
cout<<"
}
};
void main()
{
int b;
clrscr();
cout<<"Enter value: ";
cin>>b;
abc aa(b);
aa.putdata();
getch();
}

Output :

3) Copy Constructor
: #include<iostream.h>
#include<conio.h>
class abc{
int x,y;
public:
abc()
{ x=
7;
}
abc(abc &aa)
{
y=aa.x;
}
void putdata1()
{
cout<<"Value in first object: "<<x<<endl;
}
void putdata2()
{
cout<<"Value in second object: "<<y<<endl;
}
};
void main()
{
clrscr();
abc aa;
aa.putdata1();
abc bb(aa);
bb.putdata2();
getch();
}

Output:
4) Destructor :
#include<iostream.h>
#include<conio.h>
int x=0;
class abc{
public:
abc()
{
x=x+1;
cout<<"Constructor created: "<<x<<endl;
}
~abc()
{
x=x-1;
cout<<"Constructor destroyed: "<<x<<endl;
}
};
void main()
{
clrscr();
{
abc aa,bb,cc;
{
abc dd;
}
}
getch();
}

Output:
Experiment No.6
Date: / /
Roll No:140

Title: CPP program to demonstrate Tokens


. #include<iostream.h>
#include<conio.h>
void main()
{
//Keywords Ex. int,char,void
int age=20; //identifire
char name[10]="Pranit"; //string
float pi=3.14;
clrscr();
cout<<"My name is "<<name<<" and I am "<<age<<"years
old"<<endl;
cout<<"Value of Pi: "<<pi;
getch();
}
Output :
Experiment No.7
Date: / /
Roll No:140

Title:Write Cpp program to manipulate Inheritance.


1)Single Inheritance:
#include<iostream.h>
#include<conio.h>
class A{
protected:
int x;
public:
void getdata()
{ cout<<"Enter Number:";
cin>>x;
}};
class B:public A
{
public:
void showdata(){
cout<<"Given Value:"<<x;
}};
void main()
{
B bb;
bb.getdata();
bb.showdata();
getch();
}

Output:

2)Multiple Inheritance:
#include<iostream.h>
#include<conio.h>
class A
{protected:
int x;
public:
void getdata1()
{cout<<"Enter First Number:";
cin>>x;
}};
class B
{protected:
int y;
public:
void getdata2()
{cout<<"Enter second Number:";
cin>>y;
}};
class c: public A,public B
{public:
void add(){
cout<<"Addition="<<x+y;
}};
void main()
{c zz;
zz.getdata1();
zz.getdata2();
zz.add();
getch();
}

Output:
3)Multilevel Inheritance:
#include<iostream.h>
#include<conio.h>
class A{
protected:
int x;
public:
void getdata1()
{cout<<"Enter First value:";
cin>>x;
}};
class B:public A
{protected:
int y;
public:
void getdata2()
{cout<<"Enter second value:";
cin>>y;
}};
class c: public B
{public:
void mult()
{cout<<"Multiplication is="<<x*y;
}};
void main()
{c zz;
zz.getdata1();
zz.getdata2();
zz.mult();
getch();
}

Output:

4) Hirarchical
Inheritance:
#include<iostream.h>
#include<conio.h>
class
A{ public:
void msg1()
{cout<<"This is class A"<<endl;
}};
class B: public A
{ public:
void msg2()
{cout<<"This is class B"<<endl;
}};
class C: public A
{ public:
void msg3()
{cout<<"This is class c";
}};
void main()
{clrscr();
B bb;
C cc;
bb.msg1();
bb.msg2();
cc.msg1();
cc.msg3();
getch();
}

Output:
5)Hybrid Inheritance:

#include<iostream.h>
#include<conio.h>
class A{
public:
void msg1()
{cout<<"This is class A"<<endl;
}};
class B: public A
{ public:
void msg2()
{cout<<"This is class B"<<endl;
}};
class C
{ public:
void msg3()
{cout<<"This is class C"<<endl;
}};
class D: public B,public C
{ public:
void msg4()
{cout<<"This is class D"<<endl;
}};
void main()
{clrscr();
D dd;
dd.msg1();
dd.msg2();
dd.msg3();
dd.msg4();
getch();
}
Output:
Experiment No.8
Date: / /
Roll No:140

Title:Write a program to manipulate Polymorphism.


#include<iostream.h>
#include<conio.h>
class poly
{
int x;
public:
void input()
{
cout<<"Enter value: ";
cin>>x;
}
void output()
{
cout<<"Addition: "<<x;
}
poly operator+(poly bb)
{
poly cc;
cc.x=x+bb.x;
return cc;
}
};
void main()
{
poly aa,bb,cc;
aa.input();
bb.input();
cc=aa+bb;
cc.output();
getch();
}
Output:
Experiment No.9
Date: / /
Roll No:140

Title:Write a program to calculate area of circle using operator.

#include<iostream.h>
#include<conio.h>
void main()
{
float
A,r;
clrscr();
cout<<"Enter Radius: ";
cin>>r;
A=r*r*3.14;
cout<<"Area: "<<A;
getch();
}

Output:
Experiment No.10
Date: / /
Roll No:140

Title:Write a program to show class object relation manipulation


in C++.

#include<iostream.h>
#include<conio.h>
class akash{
int a,b,c;
public:
void getdata()
{cout<<"Enter 1st value:";
cin>>a;
cout<<"Enter 2nd value: ";
cin>>b;
}
void putdata()
{
c=a*b;
cout<<"MUltiplication is:"<<c;
}};
void main()
{
clrscr();
akash obj;
obj.getdata();
obj.putdata();
getch();
}

Output:

You might also like