|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
Description
Design a class named Student. Data which are stored in Student class consists of age(int), first_name(string), last_name(string), student_id(string).
Constructors:
- The default constructor of the class should initialize age to 0, and initialize first_name, last_name, student_id to empty string.
- The parameterized constructor Student(int a, string s, string f, string l) should initialize Box's age, student_id, first_name, last_name to a, s, f and l.
Methods:
- void setAge(int a) – Should set student’s age to a
- void setStudentId(string s) - Should set student’s student_id to s
- void setFirstName(string f) - Should set student’s first_name to f
- void setLastName (string l) - Should set student’s last_name to l
- int getAge () - Return student’s age
- string getStudentId() - Return student’s student_id
- string getFirstName() - Return student’s first_name
- string getLastName() - Return student’s last_name
- void yearAfter() – Should add 1 to the student’s age. And add 1 to the first letter of student_id; if the first letter is ‘9’ than turn it to ‘0’.
- string toString() - Return the new string: first_name last_name, student_id, age
ref: https://www.hackerrank.com/challenges/c-tutorial-class/problem
function.cpp
#include "function.h"
//#include <sstream>
Student::Student() : age(0), student_id(""), first_name(""), last_name("") {}
/* Todo */
void Student::setAge(int _a) { age = _a; }
/* Todo */
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.
Partial Judge Code
13028.cpp
Partial Judge Header
13028.h
Tags