13781 - EE2310_Lab_13_1   

Description

Basic Inheritance

What You Need to Do

  1. Define a class Shape that contains two data members of int type: location_x and location_y. It also contains another data member color of string class (#include <string> for using the string class).
  2. Shape contains 3 member functions get_x(), get_y(), get_color(), and a constructor Shape(int, int, string).
  3. Define another two derived classes Rectangle and Triangle that inherit from Shape. Both of them have a constructor with 3 arguments (int, int, string). Note that in these constructors you need to use the C++ initializer list to call Shape's constructor, otherwise only the default constructor of Shape will be called.
  4. Both Rectangle and Triangle have a member function output().
  5. The main function is given as follows. Do not change it.
// Do NOT CHANGE main()! You may get penalty points.
int main() {
    int x, y;
    string str;
    cin >> x >> y >> str;
    Rectangle rec(x, y, str);
    cin >> x >> y >> str;
    Triangle  tri(x, y, str);

    rec.output();
    tri.output();
    
    return 0;
}

Input

10 7 blue
10 5 black

Output

I'm a Rectangle: location_x = 10, location_y = 7, color = blue
I'm a Triangle: location_x = 10 , location_y = 5, color = black

Sample Input  Download

Sample Output  Download

Tags




Discuss