2197 - IP_2020_YOU_LAB9 Scoreboard

Time

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

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13030 Box
13032 Time

13030 - Box   

Description

Design a class named Box whose dimensions are integers and private to the class. The dimensions are labelled: length, width, and height.

 

Constructors:

  1. The default constructor of the class should initialize length, width, and height to 0.
  2. The parameterized constructor Box(int l, int w, int h) should initialize Box's length, width and height to l, w and h.
  3. The copy constructor Box(Box& b) should set length, width and height to b's length, width and height, respectively.

 

Methods:

  1. void setLength(int l) – Should set box's length to l
  2. void setWidth(int w) - Should set box's width to w
  3. void setHeight(int h) - Should set box's height to h
  4. int getLength() - Return box's length
  5. int getWidth() - Return box's width
  6. int getHeight() - Return box's height
  7. long long CalculateVolume() - Return the volume of the box (Hint: cout << volume << endl; )

 

ref: https://www.hackerrank.com/challenges/box-it/proble

 

main.cpp

#include <iostream>
#include <string>
 
using namespace std;
 
class Box
{
public:
    Box() : length(0), width(0), height(0) {}
    /* Todo */
 
    void setLength(int _l) { length = _l; }
    /* Todo */
 
    int getLength() { return length; }
    /* Todo */
 
    /* Todo */
    // 1. calculateVolume() 2. calculateSurfaceArea()
 
private:
    int lengthwidthheight;
};
 
// Don't touch main()
int main()
{
    int testcase = 0;
    cin >> testcase;
 
    if (testcase == 1)
    {
        Box box = Box();
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight() << endl;
        box.setLength(300);
        box.setWidth(400);
        box.setHeight(500);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight() << endl;
    }
    else if (testcase == 2)
    {
        Box box = Box(171734);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight() << endl;
        box.setLength(101);
        box.setWidth(50);
        box.setHeight(34);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight() << endl;
    }
    else if (testcase == 3)
    {
        Box box = Box(1001717);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight();
        cout << ", Surface Area: " << box.calculateSurfaceArea() << ", Volume: " << box.calculateVolume() << endl;
    }
    else if (testcase == 4)
    {
        Box box = Box();
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight();
        cout << ", Surface Area: " << box.calculateSurfaceArea() << ", Volume: " << box.calculateVolume() << endl;
        box.setLength(44);
        box.setWidth(200);
        box.setHeight(1);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight();
        cout << ", Surface Area: " << box.calculateSurfaceArea() << ", Volume: " << box.calculateVolume() << endl;
    }
    else if (testcase == 5)
    {
        Box box = Box(100002000030000);
        cout << "Length: " << box.getLength() << ", Width: " << box.getWidth() << ", Height: " << box.getHeight();
        cout << ", Surface Area: " << box.calculateSurfaceArea() << ", Volume: " << box.calculateVolume() << endl;
    }
 
    return 0;
}

Input

No need to handle input. (Input would be number 1~5 to represent the index of test-case)

Output

Depend on test case show in main.cpp.

Sample Input  Download

Sample Output  Download

Tags




Discuss




13032 - Time   

Description

Design a class named Time. Data which are stored in Time class consists of year(int), month(int), day(int), hour(int), minute(int), second(int).

 

Constructors:

  1. The default constructor of the class should initialize year(int), month(int), day(int), hour(int), minute(int), second(int) to -1.
  2. The parameterized constructor Time(int h, int mi, int s) should initialize Time's hour, minute and second to h, mi and s.
  3. The parameterized constructor Time(int y, int mo, int d, int h, int mi, int s) should initialize Time's year, month, day, hour, minute and second to y, mo, d, h, mi and s.

 

Methods:

  1. void setAll(int y, int mo, int d, int h, int mi, int s) – Should set time's year, month, day, hour, minute, second to y, mo, d, h, mi and s, repectively.
  2. void setTime(int h, int mi, int s) – Should set time's hour, minute, second to h, mi and s, repectively.
  3. void setDate(int y, int mo, int d) – Should set time's year, month, day to y, mo, and d, repectively.
  4. void print() - Should print out time’s data.
  • If all time’s data are set, print: h:mi:s d, mo, y. Example, time -> year(2020), month(11), day(29), hour(9), minute(2), second(49), print: 9:2:49 11 29 2020 (Hint: cout << hour << “:” << minute << “:” << second << “ ” << month << “ ” << day << “ ” << year << endl; )
  • If one of year, month, day is not set, print: h:mi:s. Example, time -> year(-1), month(11), day(29), hour(9), minute(2), second(49), print: 9:2:49
  • If one of hour, minute, second is not set, print: d, mo, y. Example, time -> year(2020), month(11), day(29), hour(-1), minute(-1), second(49), print: 11 29 2020
  • If one of year, month, day is not set, and one of hour, minute, second is not set, print "Time is not set". Example, time -> year(2020), month(-1), day(29), hour(9), minute(2), second(-1), print: Time is not set

 

main.cpp

#include <iostream>
#include <string>
 
using namespace std;
 
class Time
{
public:
    Time() : year(-1), month(-1), day(-1), hour(-1), minute(-1), second(-1) {}
    /* Todo */
    // Implement 2 parameterized constructors
 
    /* Todo */
    // Implment setAll(), setTime(), setDate(), print()
 
private:
    int yearmonthdayhourminutesecond;
};
 
// Don't touch main()
int main()
{
    int testcase = 0;
    cin >> testcase;
 
    if (testcase == 1)
    {
        Time time = Time(2020121121634);
        time.print();
    }
    else if (testcase == 2)
    {
        Time time1 = Time(155431);
        time1.print();
        Time time2 = Time();
        time2.print();
    }
    else if (testcase == 3)
    {
        Time time = Time();
        time.print();
        time.setDate(2021324);
        time.print();
        time.setTime(71517);
        time.print();
    }
    else if (testcase == 4)
    {
        Time time = Time(17, -145);
        time.print();
        time.setDate(20225, -1);
        time.print();
        time.setAll(2024, -14, -12322);
        time.print();
    }
    else if (testcase == 5)
    {
        Time time = Time(-1, -1, -1101010);
        time.print();
        time.setAll(30311225, -1, -1, -1);
        time.print();
        time.setTime(123117);
        time.print();
        time.setDate(2020121);
        time.print();
    }
 
    return 0;
}

Input

No need to handle input. (Input would be number 1~5 to represent the index of test-case)

Output

Depend on test case show in main.cpp.

Sample Input  Download

Sample Output  Download

Tags




Discuss