EX.NO : 1 / CLASS AND OBJECT IMPLEMENTATION
Date :

AIM:

To write a basicC++program to implement classand object concepts.

ALGORITHM:

1)Start the program

2)Declare a class "Rectangle" with variables and functions.

3)Getlength and breadth using "getdata()" function.

4)Find and display the area of rectangle in "putdata()" function.

5)Stop the program

PROGRAM:

#include<iostream.h

#include<conio.h

class Rectangle

{

intl,b;

public:

voidgetdata();

voidputdata();

};

void Rectangle::getdata()

{

cout<"Enter length: ";

cin>l;

cout<"Enter breath: ";

cin>b;

}

void Rectangle::putdata()

{

cout<"Area of rectangle: "< l*b;

}

void main()

{

clrscr();

Rectangle rect;

rect.getdata();

rect.putdata();

getch();

}

OUTPUT:

Enter length: 3

Enter breath: 4

Area of rectangle: 12

RESULT:

Thus theC++ program to implement class and object concepts has been executed and verified successfully.

EX.NO : 2 / CONSTRUCTORS & DESTRUCTORS, COPY CONSTRUCTOR
Date :

AIM:

To write a basic C++ program to implement different type of constructors

ALGORITHM:

1)Start the program.

2)Declare a class recta with three types of constructors.

3)Constructors with Default contractor, parameterized constructor, and copy constructor are defined inside the class recta.

4)Call the constructors from the main function

5)Display the Output

6)Stop the program.

PROGRAM:

#include<iostream.h

#include<conio.h

classrecta

{

public:

intbreadth,height,area;

recta()

{

breadth=10;

height=20;

}

recta(intb,int h)

{

breadth=b;

height=h;

}

recta(recta &s)

{

breadth=s.breadth;

height=s.height;

}

void display()

{

cout<"\n Area of The Rectangle :"<breadth*height;

}

};

void main()

{

clrscr();

recta a;

cout<"\n ===> Default Constructor <=== ";

a.display();

recta b(30,20);

cout<"\n ===> Parameterized Constructor <==";

b.display();

recta c(b);

cout<"\n ===> Copy Contructor <===";

c.display();

getch();

}

OUTPUT:

===> Default Constructor <===

Area of The Rectangle :200

===> Parameterized Constructor <==

Area of The Rectangle :600

===> Copy Constructor <===

Area of The Rectangle :600

RESULT:

Thus theC++ program to implementdifferent type of constructorshas been executed and verified successfully.

EX.NO : 3 / FRIEND FUNCTION & FRIEND CLASS
Date :

3.1 Area of rectangle using "friend" Function

AIM:

To write a C++ program to find area of rectangle using "friend" Function.

ALGORITHM:

1)Start the program.

2)Declare a class Rectangle with a "friend" function.

3)Define the friend function.

4)Call the friend function from the main function using object as argument.

5)Display the Output.

6)Stop the program.

PROGRAM:

#include<iostream.h

#include<conio.h

class Rectangle

{

intl,b;

public:

voidgetdata()

{

cout<"Enter length and breadth:";

cin>l>b;

}

friendint area(Rectangle r1);

};

int area(Rectangle r1)

{

returnint(r1.l * r1.b);

}

void main()

{

clrscr();

Rectangle rect;

rect.getdata();

cout<"Area of rectangle= "<area(rect);

getch();

}

OUTPUT:

Enter length and breadth : 10 20

Area of The Rectangle :200

RESULT:

Thus theC++ program to find area of rectangle using "friend" Function has been executed and verified successfully.

3.2Mean Value using "friend" Function

AIM:

To write a C++ program to find mean value of given numbers using "friend" Function.

ALGORITHM:

1)Start the program.

2)Declare a class "myclass" with a "friend" function.

3)Define the friend function.

4)Call the friend function from the main function using object as argument.

5)Display the Output.

6)Stop the program.

PROGRAM:

#include<iostream.h

#include<conio.h

classmyclass

{

int val1,val2;

public:

voidgetdata()

{

cout<"Enter two values:";

cin>val1>val2;

}

friend void mean(myclass m2);

};

void mean(myclass m2)

{

cout<"Mean value: "<(m2.val1 + m2.val2)/2;

}

void main()

{

clrscr();

myclass m1;

m1.getdata();

mean(m1);

getch();

}

OUTPUT:

Enter two values: 10 20

Mean value: 15

RESULT:

Thus theC++ program tomean value of given numbers using "friend" Function has been executed and verified successfully.

EX.NO : 4 / INHERITANCE
Date :

4.1 Single Inheritance

AIM:

To write a C++ program to implement Single Inheritance.

ALGORITHM:

1)Start the program.

2)Declare a Base class and a Derived classusing "class Derived : public Base".

3)Create an object to the Derived class in the main function.

4)Access the members of both Base and Derived class using this object.

5)Display the Output.

6)Stop the program.

PROGRAM:

#include <iostream.h

#include<conio.h

class Base

{

public:

int x;

voidsetx(int n)

{

x = n;

}

voidshowx( )

{

cout<"\n In base class :";

cout <"\n X = "<x;

}

};

class Derived : public Base

{

int y;

public:

voidsety(int n)

{

y = n;

}

void showy()

{

cout<"\n In derived class :";

cout<"\n X = "<x;

cout <"\n Y = "<y;

}

};

void main()

{

clrscr();

Derived d1;

intx,y;

cout<"\n Enter the value of x:";

cin>x;

cout<"\n Enter the value of y:";

cin>y;

d1.setx(x);

d1.sety(y);

d1.showx();

d1.showy();

getch();

}

OUTPUT:

Enter the value of x :10

Enter the value of y :20

In base class :

X =10

In derived class :

X =10

Y = 20

RESULT:

Thus theC++ program toimplement Single Inheritance has been executed and verified successfully.

4.2 Multilevel Inheritance

AIM:

To write a C++ program for Student Mark Analysis using Multilevel Inheritance.

ALGORITHM:

1)Start the program.

2)Declare a Base class and a Derived classusing "class Derived : public Base".

3)Create an object to the Derived class in the main function.

4)Access the members of both Base and Derived class using this object.

5)Display the Output.

6)Stop the program.

PROGRAM:

#include<iostream.h

#include<conio.h

class Student

{

protected:

intrno;

public:

voidgetnumber(int x)

{

rno=x;

}

voidputnumber()

{

cout<"Reg.no:"<rnoendl;

}

};

classTest:public Student

{

protected:

float sub1,sub2;

public:

voidgetmarks(float x,float y)

{

sub1=x;

sub2=y;

}

voidputmarks()

{

cout<"Sub1= "<sub1<endl;

cout<"Sub2= "<sub2<endl;

}

};

classResult:public Test

{

float total;

public:

void display()

{

total=sub1+sub2;

putnumber();

putmarks();

cout<"Total= "<total<endl;

cout<"Avg= "<total/2<"\n\n";

}

};

void main()

{

clrscr();

Result s1,s2,s3;

s1.getnumber(4001);

s2.getnumber(4002);

s1.getmarks(85,75);

s2.getmarks(50,55);

s1.display();

s2.display();

getch();

}

OUTPUT:

Reg.no: 4001

Sub1=85

Sub2= 75

Total=160

Avg=80

Reg.no: 4002

Sub1=50

Sub2= 55

Total=105

Avg=52.5

RESULT:

Thus theC++ program for Student Mark Analysis using Multilevel Inheritance has been executed and verified successfully.