0% found this document useful (0 votes)
5 views6 pages

C++_Programs

The document outlines three C++ programs demonstrating key concepts: implementation of class and object, constructor, and single inheritance. Each section includes the aim, algorithm, program code, output, and a result statement confirming successful execution. The programs cover basic functionalities such as addition, area calculation, and inheritance in C++.

Uploaded by

3atntv9hpx
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)
5 views6 pages

C++_Programs

The document outlines three C++ programs demonstrating key concepts: implementation of class and object, constructor, and single inheritance. Each section includes the aim, algorithm, program code, output, and a result statement confirming successful execution. The programs cover basic functionalities such as addition, area calculation, and inheritance in C++.

Uploaded by

3atntv9hpx
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/ 6

C++ PROGRAMS REPORT

1. Implementation of Class and Object

Aim:
To write a C++ program to implement class and object.

Algorithm:
1. Start the program.
2. Declare a class named 'add' with data members 'a', 'b', and 'sum'.
3. Create member functions 'getdata()' to input values and 'add_data()' to perform
addition.
4. In the main function, create an object of the class.
5. Call the 'getdata()' and 'add_data()' functions using the object.
6. Display the result of the addition.
7. Stop the program.

Program:

#include <iostream.h>
#include <conio.h>

class add {
int a, b, sum;
public:
void getdata() {
cout << "Enter the First value: ";
cin >> a;
cout << "Enter the Second value: ";
cin >> b;
}

void add_data() {
sum = a + b;
cout << "The Result = " << sum;
}
};

void main() {
clrscr();
cout << "\tImplementation Of Class and Object\n";
add al;
al.getdata();
al.add_data();
getch();
}

Output:

Implementation Of Class and Object

Enter the First value: 40


Enter the Second value: 60

The Result = 100

Result:
Thus, the C++ program for the implementation of Class and Object was successfully
executed and the output was verified.
2. Implementation of Constructor

Aim:
To write a C++ program to implement constructor.

Algorithm:
8. Start the program.
9. Declare a class named 'Rectangle' with data members 'length' and 'breadth'.
10. Create a constructor to initialize the values and calculate the area.
11. In the main function, create an object of the class.
12. The constructor will automatically execute and display the area.
13. Stop the program.

Program:

#include <iostream.h>
#include <conio.h>

class Rectangle {
int length, breadth;
public:
Rectangle() {
cout << "Enter your length: ";
cin >> length;
cout << "Enter your breadth: ";
cin >> breadth;
cout << "\nArea of rectangle = " << length * breadth;
}
};

void main() {
clrscr();
cout << "\tImplementation of Constructor\n";
Rectangle obj;
getch();
}

Output:

Implementation of Constructor

Enter your length: 10


Enter your breadth: 5
Area of rectangle = 50

Result:
Thus, the C++ program for the implementation of Constructor was successfully executed
and the output was verified.
3. Single Inheritance

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

Algorithm:
14. Start the program.
15. Declare a base class with a display function.
16. Declare a derived class that inherits the base class.
17. Define display functions for both classes.
18. In the main function, create an object of the derived class.
19. Call both display functions using the derived class object.
20. Stop the program.

Program:

#include <iostream.h>
#include <conio.h>

class base {
public:
void display() {
cout << "BASE CLASS\n";
}
};

class derived : public base {


public:
void display1() {
cout << "DERIVED CLASS";
}
};

void main() {
clrscr();
cout << "\tSingle Inheritance\n";
derived d;
d.display();
d.display1();
getch();
}
Output:

Single Inheritance

BASE CLASS

DERIVED CLASS

Result:
Thus, the C++ program for the implementation of Single Inheritance was successfully
executed and the output was verified.

You might also like