This C++ program defines a base class and a derived class, where the base class contains a method to read an integer input. The derived class extends the base class by adding another integer input method and a method to calculate the product of the two integers. The main function creates an object of the derived class, calls the methods to read inputs, and displays the product of the inputs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
1 views1 page
Single Inheritance
This C++ program defines a base class and a derived class, where the base class contains a method to read an integer input. The derived class extends the base class by adding another integer input method and a method to calculate the product of the two integers. The main function creates an object of the derived class, calls the methods to read inputs, and displays the product of the inputs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
#include <iostream>
using namespace std;
class base { public: int x; void readdata() { cout<<"\n enter the number:"; cin>>x; } }; class derived:public base { public: int y; void getdata() { cout<<"\n enter the number:"; cin>>y; } void product() { cout<<"\n product="<<x*y; } }; int main() { derived obj; obj.readdata(); obj.getdata(); obj.product(); return 0;