# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13040 | Pyramid |
|
13041 | When Peter meets Peter |
|
Description
Design a class named Pyramid which is derived from an existed class named Rectangle.
Rectangle:
Protected Variables:
- l(int) as rectangle’s length.
- w(int) as rectangle’s width.
note that 0 <= l, w <= 100.
Constructors:
- The default constructor of the class should initialize l, and w to 0.
- The parameterized constructor Rectangle(int _l, int _w) should initialize rectangle's l, and w to _l, and _w.
Methods:
- int getLength() - Return rectangle's l.
- int getWidth() - Return rectangle's w.
- int calculateArea() - Return rectangle's area(l * w).
Pyramid:
Protected Variables:
- l(int) as pyramid’s length.
- w(int) as pyramid’s width.
- h(int) as pyramid’s height.
note that l, w is derived from Rectangle.
Constructors:
- The default constructor of the class should initialize pyramid’s l, w, h to 0.
- The parameterized constructor Pyramid(int _l, int _w, int _h) should initialize pyramid’s l, w, h to _l, _w, _h.
- The parameterized constructor Pyramid(Rectangle& rect, int _h) should initialize pyramid’s l, w, h to rect’s l, rect’s w, _h.
Methods:
- int getLength() - Return pyramid’s l.
- int getWidth() - Return pyramid’s w.
- int getHeight() - Return pyramid’s h.
- int calculateArea() - Return pyramid’s base area(l * w).
- double calculateVolume() - Return pyramid’s volume(1/3 * base area * h).
// YOU DON’T NEED TO IMPLEMENT BELOW TWO METHODS
- void printBasicInfo() – print Length: l, Width: w, Height: h. For example: “Length: 20, Width: 30, Height: 40”.
- void printFullInfo() – print Length: l, Width: w, Height: h, Area: base area, Volume: volume. For example: “Length: 20, Width: 30, Height: 40, Area: 600, Volume: 8000.00”. Note that, std::fixed() and std::setpercision(int) is help to print a floating variable to 2nd decimal place.
Example:
main.cpp
Input
No need to handle input. (Input would be number 1~5 to represent the index of test-case)
Output
No need to handle output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Design four classes named Peter, AmericanPeter, AngryPeter, AmericanAngryPeter. Please smartly derived these four classes from five existed classes Speak, Greet, AngryGreet, AmericanStyle, Curse.
Note that there is a private variable named level in Curse which controls what kinds of curse words that can be used. For example, people with curse level 1, may use level 1 curse word like: “You stupid!”, but cannot use level 2 curse word like: “Asshole!” or above. People with curse level 2 may use both level 1 and level 2 curse words, but cannot use level 3 curse word like: “F*** You!!!” or above.
Speak:
Public Methods:
- void speak(string sentence) – Should print :sentence. For example, if parsed sentence is “Hello world!”, than print “:Hello world!”.
Greet:
Public Methods:
- string greet_toString() – Should return string “How’s it going?”.
AngryGreet:
Public Methods:
- string angryGreet_toString() – Should return string “...(Angry men won't greet)”.
AmericanStyle:
Public Methods:
- string american_toString() – Should return string “Yo!”.
Curse:
Private Variable:
- level(int) as curse level.
Public Methods:
- string curse_toString(int type) – Should return different type of curse word. For example, curse_toString(2), should return string “Asshole!”. If the curse word is beyond its curse level, should return string “……”.
Protected Methods:
- void set_curseLevel(int _l) – Should set curse level to _l.
// YOU NEED TO IMPLEMENT BELOW FOUR CLASSES
Peter:
Public Methods:
- void greet() – Should print “:How’s it going?”, just like a normal person.
AmericanPeter:
Public Methods:
- void greet() – Should print “:Yo! How’s it going?”, just like a normal American
AngryPeter: (must derived from Curse)
Constructors:
- The parameterized constructor AngryPeter(int _l) should initialize AngryPeter’s curse level to _l.
Public Methods:
- void greet() – Should print “:...(Angry men won't greet)”, just like a normal angry person.
- void curse(int t) – Should print 4 different kinds of curse words based on t and curse level.
t = 1 & curse level !< 1, print “:You stupid!”
t = 2 & curse level !< 2, print “:Asshole!”
t = 3 & curse level !< 3, print “:F*** you!!!”
t = 4 & curse level !< 4, print “:You Son of a b****!!!”
all the other cases should print “:……”.
AmericanAngryPeter: (must derived from Curse)
Constructors:
- The parameterized constructor AmericanAngryPeter(int _l) should initialize AmericanAngryPeter’s curse level to _l.
Public Methods:
- void greet() – Should print “:Yo! ...(Angry men won't greet)”, just like a normal angry American.
- void curse(int t) – Should print 4 different kinds of curse words based on t and curse level.
t = 1 & curse level !< 1, print “:Yo! You stupid!”
t = 2 & curse level !< 2, print “:Yo! Asshole!”
t = 3 & curse level !< 3, print “:Yo! F*** you!!!”
t = 4 & curse level !< 4, print “:Yo! You Son of a b****!!!”
all the other cases should print “:Yo! ……”.
main.cpp
Input
No need to handle input. (Input would be number 1~5 to represent the index of test-case)
Output
No need to handle output.