Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Q1. i. Define a base class with following member data and member function: int i, j accessible in base class. void set(int a, int b)

Q1.

i. Define a base class with following member data and member function: int i, j accessible in base class. void set(int a, int b) to initialize i .j. void show() to display the values of i, j. ii.

Define a derived class from base class with public access having following data member and member functions: int k; void setk() to set the val of k void showk() Creat an object of type derived class. Initialize the values of i,j,k for this object and display these values.

Q2.

i. Define a base class with following member data and member function: private int i and public type: void seti(int a) to initialize i. int geti() to store the value of i; ii.

Define a derived class from base class with public access having following data member and member functions: private int j and public type; void setj(int n) to set the val of j; int mul() to multiply j and geti() Create an object of type derived class. Initialize the values of i, j and geti() for this object and display the multiple of i and j;

Q3

• Define a base class with two int variable i,j accessible in derived class should not be public. Define a function set the values of above variables and another function to display the values of these variables. • Define a derived class1 from base class with public access having a private int k variable and public type function to set the value of k variable to i*j. Define a function to display the value of k. • Define a 2nd derived class2 from derived class1 with public access having a private int m variable and public function to set the value of m such that m=i-j; display the value of m with a function. Define two objects of derived class1 and class2 to prove show that these objects can access the functions of their parent class.

Q4.

• Define a class Area with public member height and width.

• Derive a class rectangle from Area with public constructor to initialize height and width and a returnable function double area() to calculate area of rectangle.

• Derive a class Isosceles with public access from Area class having public member constructor to initialize height and width and member function double area() to calculate area of isosceles.

• Derive a class cylinder from Area class with public access having a public constructor to initialize height and width and member function double area() to calculate area of cylinder

• Define objects of class rectangle, isosceles and cylinder and calculate area of each object.

Q5

• Define a class circle with protected member double diameter and a function to set the value of diameter.

• Derive a class sphere from circle as public with public member function double area() Define an object of class sphere and find its area.

Step by Step Solution

3.27 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

The detailed answer for the above question is provided below Q1 include using namespace std class Base protected int i j public void setint a int b i ... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students explore these related Programming questions

Question

What is the distinction between 33L and 33?

Answered: 3 weeks ago