Question: Write C++ code for a class named MyDerivedClass , which is derived from the MyClass you wrote in questions 6 and 7. Add two member

Write C++ code for a class named MyDerivedClass, which is derived from the MyClass you wrote in questions 6 and 7. Add two member variables of type float. Include functions to get and modify these .

Code from Question 6:

#include 

using namespace std;

class MyClass {

private:

int integer;

float number;

public:

MyClass(int integer, float number);

int getInteger() const;

void setInteger(int integer);

float getNumber() const;

void setNumber(float number);

void print();

};

MyClass::MyClass(int integer, float number) : integer(integer), number(number) {}

int MyClass::getInteger() const {

return integer;

}

void MyClass::setInteger(int integer) {

MyClass::integer = integer;

}

float MyClass::getNumber() const {

return number;

}

void MyClass::setNumber(float number) {

MyClass::number = number;

}

void MyClass::print() {

cout << "Integer: " << integer << ", Float: " << number << endl;

}

int main() {

MyClass obj(2, 7.5);

obj.print();

obj.setInteger(5);

obj.setNumber(3.75);

obj.print();

return 0;

}

Code from Question 7:

  1. #include using namespace std;

class MyClass { int no; string name;

public:

MyClass() { no=0; name=""; }

MyClass(int no1, string name1) { no=no1; name=name1; }

int getNo() { return no; }

string getName() { return name; }

};

class MyDerivedClass: public MyClass { string address;

public: MyDerivedClass(int no1, string name1, string address1):MyClass(no1,name1) { address=address1; }

string getAddress() { return address; } };

int main() { int no1; string name1,address1;

cout<<"Enter a number: "; cin>>no1; cin.ignore(); cout<<"Enter a name: "; getline(cin,name1); cout<<"Enter an address: "; getline(cin,address1);

MyDerivedClass mdc(no1,name1,address1); cout<<" ---------------------------------- "; cout<<"No: "<

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!