2202 - IP_2020_YOU_LAB10 Scoreboard

Time

2020/12/08 15:30:00 2020/12/08 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13040 Pyramid
13041 When Peter meets Peter

13040 - Pyramid   

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:

#include <iostream> // std::cout, std::fixed
#include <iomanip> // std::setprecision
 
std::cout << std::fixed  << std::setprecision(2) << some_double_variable;

 

main.cpp

#include <iostream>
#include <iomanip>
 
using namespace std;
 
void check();
 
class Rectangle
{
public:
    Rectangle() : l(0), w(0) {}
    Rectangle(int _lint _w) : l(_l), w(_w) {}
 
    int getLength() { return l; }
    int getWidth() { return w; }
 
protected:
    int lw;
    int calculateArea() { return l * w; }
};
 
/* Todo */
// Create a class named Pyramid, derived from class Rectangle
// 1. Three constructors: Pyramid(), Pyramid(int _l, int _w, int _h), Pyramid(Rectangle& rect, int _h)
// 2. Four public methods: getHeight(), calculateVolume(), printBasicInfo(), printFullInfo()
/* You may use the below functions directly */
// void printBasicInfo() { cout << "Length: " << getLength() << ", Width: " << getWidth() << ", Height: " << getHeight() << endl; }
// void printFullInfo() { cout << "Length: " << getLength() << ", Width: " << getWidth() << ", Height: " << getHeight() << ", Area: " << calculateArea() << ", Volume: " << fixed << setprecision(2) << calculateVolume() << endl; }
// 3. One protected variable: h
 
// Don't touch below functions when submitting the code
void check()
{
    int testcase;
    cin >> testcase;
 
    if (testcase == 1)
    {
        Pyramid pyrm1 = Pyramid();
        pyrm1.printBasicInfo();
 
        Pyramid pyrm2 = Pyramid(345);
        pyrm2.printBasicInfo();
    }
 
    if (testcase == 2)
    {
        Pyramid pyrm1 = Pyramid();
        pyrm1.printFullInfo();
 
        Pyramid pyrm2 = Pyramid(131415);
        pyrm2.printFullInfo();
    }
 
    if (testcase == 3)
    {
        Rectangle rect = Rectangle(1010);
        Pyramid pyrm = Pyramid(rect30);
        pyrm.printFullInfo();
    }
 
    if (testcase == 4)
    {
        Pyramid pyrm1 = Pyramid(233455);
        pyrm1.printFullInfo();
 
        Rectangle rect = Rectangle(1111);
        Pyramid pyrm2 = Pyramid(rect, 17);
        pyrm2.printFullInfo();
    }
 
    if (testcase == 5)
    {
        Pyramid pyrm = Pyramid(100100100);
        pyrm.printFullInfo();
    }
}
 
int main()
{
    check();
    return 0;
}

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




13041 - When Peter meets Peter   

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

#include <iostream>
#include <string>
 
using namespace std;
 
void check();
 
class Speak
{
public:
    void speak(string sentence)
    {
        cout << ":" << sentence << endl;
    }
};
 
class Greet
{
public:
    string greet_toString()
    {
        return "How's it going?";
    }
};
 
class AngryGreet // 生氣氣??
{
public:
    string angryGreet_toString()
    {
        return "...(Angry men won't greet)";
    }
};
 
class AmericanStyle
{
public:
    string american_toString()
    {
        return "Yo!";
    }
};
 
class Curse
{
public:
    string curse_toString(int type)
    {
        string curse = "......";
        switch (type)
        {
        case 1:
            if (type <= level)
                curse = "You stupid!";
            break;
 
        case 2:
            if (type <= level)
                curse = "Asshole!";
            break;
 
        case 3:
            if (type <= level)
                curse = "F*** you!!!";
            break;
 
        case 4:
            if (type <= level)
                curse = "You Son of a b****!!!";
            break;
        }
        return curse;
    }
 
protected:
    void set_curseLevel(int _l)
    {
        level = _l;
    }
 
private:
    int level;
};
 
/* Todo */
// 1. Please design four classes named Peter, AmericanPeter, AngryPeter, AmericanAngryPeter, respectly
// 2. Peter without anger may do greet() with sentence from class Greet
//    Peter with anger may do greet() with sentence from class AngryGreet, and curse(int i)
// 3. American Peter or American angry Peter need to have an american style beginning everytime they greet() and curse(int i);
// Hint:
// 1. Properly inherit above class may help!!
// 2. Angry Peter might set his curse_level before he curses
 
// Don't touch below functions when submitting the code
void check()
{
    int testcase;
    cin >> testcase;
 
    if (testcase == 1)
    {
        // when Peter meets Peter
        Peter peter1 = Peter();
        Peter peter2 = Peter();
        peter1.greet();
        peter2.greet();
    }
 
    if (testcase == 2)
    {
        // when Peter meets Peter from America
        Peter peter1 = Peter();
        AmericanPeter peter2 = AmericanPeter();
        peter1.greet();
        peter2.greet();
    }
 
    if (testcase == 3)
    {
        // when Peter meets level 1 angry Peter
        Peter peter1 = Peter();
        AngryPeter peter2 = AngryPeter(1);
        peter1.greet();
        peter2.greet();
        peter1.greet();
        peter2.curse(1);
    }
 
    if (testcase == 4)
    {
        // when level 1 angry Peter from America meets an level 4 angry Peter
        AmericanAngryPeter peter1 = AmericanAngryPeter(1);
        AngryPeter peter2 = AngryPeter(4);
        peter1.greet();
        peter2.greet();
        peter1.curse(1);
        peter2.curse(1);
        peter1.curse(2);
        peter2.curse(2);
        peter1.curse(3);
        peter2.curse(3);
        peter1.curse(4);
        peter2.curse(4);
    }
 
    if (testcase == 5)
    {
        // when level 4 angry Peter meets an level 4 angry Peter from America
        AngryPeter peter1 = AngryPeter(4);
        AmericanAngryPeter peter2 = AmericanAngryPeter(4);
        peter1.greet();
        peter2.greet();
        peter1.curse(1);
        peter2.curse(1);
        peter1.curse(2);
        peter2.curse(2);
        peter1.curse(3);
        peter2.curse(3);
        peter1.curse(4);
        peter2.curse(4);
    }
}
 
int main()
{
    check();
    return 0;
}

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