-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathc-tutorial-class.cpp
More file actions
60 lines (49 loc) · 1.41 KB
/
c-tutorial-class.cpp
File metadata and controls
60 lines (49 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Class
// Learn how to create and use classes.
//
// https://www.hackerrank.com/challenges/c-tutorial-class/problem
//
#include <iostream>
#include <sstream>
using namespace std;
/*
Enter code for class Student here.
Read statement for specification.
*/
class Student
{
int age = 0;
int standard = 0;
string first_name, last_name;
public:
void set_first_name(const string& s) { first_name = s; }
const string& get_first_name() const { return first_name; }
void set_last_name(const string& s) { last_name = s; }
const string& get_last_name() const { return last_name; }
void set_age(int s) { age = s; }
int get_age() const { return age; }
void set_standard(int s) { standard = s; }
int get_standard() const { return standard; }
string to_string() const
{
stringstream ss;
ss << age << "," << first_name << "," << last_name << "," << standard;
return ss.str();
}
};
int main() {
int age, standard;
string first_name, last_name;
cin >> age >> first_name >> last_name >> standard;
Student st;
st.set_age(age);
st.set_standard(standard);
st.set_first_name(first_name);
st.set_last_name(last_name);
cout << st.get_age() << "\n";
cout << st.get_last_name() << ", " << st.get_first_name() << "\n";
cout << st.get_standard() << "\n";
cout << "\n";
cout << st.to_string();
return 0;
}