13028 - Student   

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:

  1. The default constructor of the class should initialize age to 0, and initialize first_name, last_name, student_id to empty string.
  2. 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:

  1. void setAge(int a) – Should set student’s age to a
  2. void setStudentId(string s) - Should set student’s student_id to s
  3. void setFirstName(string f) - Should set student’s first_name to f
  4. void setLastName (string l) - Should set student’s last_name to l
  5. int getAge () - Return student’s age
  6. string getStudentId() - Return student’s student_id
  7. string getFirstName() - Return student’s first_name
  8. string getLastName() - Return student’s last_name
  9. 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’.
  10. 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.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13028.cpp

Partial Judge Header

13028.h

Tags




Discuss