Question
Part 1) This exercise is about Inheritance. Write a program in C++. Write each class interface and implementation, in a different .h and .cpp file,
Part 1)
This exercise is about Inheritance.
Write a program in C++. Write each class interface and implementation, in a different .h and .cpp file, respectively.
a) Create a class called Student that has a name (string) and ID (int) as member variables.
b) Create a derived (child) class called ComputerSystemsStudent that inherits from class Student. Class ComputerSystemsStudent has also a track (string) as member variable. A track takes values such a "Programming", "Web Design", "Networking", etc.
c) Write a default constructor with all default parameters for both classes Student and ComputerSystemsStudent.
d) Write printInfo() function for classses Student and ComputerSystemsStudent classes. -- class ComputerSystemsStudent class must override the printInfo of the base class Student. e) Create a test program that includes an object of class Student and another object of class ComputerSystemsStudent. Write test code print information about each object.
Note that you need submit a total of five files for this part.
Part 2
Your job is to complete this program and make it work by
a) by adding a default constructor with all default parameters to the class rectangle. Note that class rectangle is a composed class (has composition since class rectangle contains objects of class Point)
b) by completing the body of the area function of class rectangle.
p.s. there are other ans of this same questions in here but please do not use those. thanks.
USE THIS CODE
#includeusing namespace std; class point { public: // constructor with default parameters point(double xcoordinate = 0.0, double ycoordinate = 0.0) { x = xcoordinate; y = ycoordinate; } void print() const { cout << "x: " << x << "\t" << "y: " << y << endl; } double getX() const { return x; } double getY() const { return y; } private: double x; double y; }; class rectangle { public: // (A) implement default constructor with all default parameters // .... void print() const { cout << "upper left point: "; upperLeftPoint.print(); cout << "lower right point: "; lowerRightPoint.print(); } // (B) implement the area function whose header is given b double area() const { // ... complete here... } private: point upperLeftPoint; point lowerRightPoint; }; int main() { rectangle r1; rectangle r2(10, 90); // Note that: 10 and 90 are the x and y coordinates of the upper left point of the rectangle rectangle r3(10, 90, 110, 20); // Note that: 10 and 90 are the x and y coordinates of the upper left point of the rectangle; while //110 and 20 are the x and y coordinates of the lower right point of the rectangle //----------------------------------- --------------------------------- // Hint: If your code is implemented correctly, the area of // the area of r1 should print 0 // the area of r2 should print 900 // the area of r3 should print 7000 //----------------------------------- --------------------------------- cout << "Area1 is: " << r1.area() << endl; cout << "Area2 is: " << r2.area() << endl; cout << "Area3 is: " << r3.area() << endl; system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started