-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassWithGettersSetters.cpp
More file actions
66 lines (58 loc) · 1.69 KB
/
Copy pathclassWithGettersSetters.cpp
File metadata and controls
66 lines (58 loc) · 1.69 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
61
62
63
64
65
66
#include <iostream>
//#include <sstream>
using namespace std;
class Student{
private:
int age, std;
string first_name, last_name;
public: //setters
void set_age(int ageS){
age = ageS;
}
void set_std(int stdS){ //data type to represent non-negative int no.s
std = stdS;
}
void set_first_name(string first_nameS){
first_name = first_nameS;
}
void set_last_name(string last_nameS){
last_name = last_nameS;
}
//getters
int get_age(){
return age;
}
int get_std(){
return std;
}
string get_first_name(){
return first_name;
}
string get_last_name(){
return last_name;
}
//now to display , seperated values output in the same line
string to_string(){ //std::to_string, Convert numerical value to string
//string result = std::to_string(age)+','+get_first_name()+','+get_last_name()+','+std::to_string(std);
string result = std::to_string(age) +','+get_first_name()+','+get_last_name()+','+std::to_string(std);
return result;
}
};
int main() {
int age;
int std;
string f_name;
string l_name;
cin>>age>>f_name>>l_name>>std;
Student st;
st.set_age(age);
st.set_first_name(first_name);
st.set_last_name(last_name);
st.set_std(std);
cout << st.get_age() << "\n";
cout << st.get_last_name() << ", " << st.get_first_name() << "\n";
cout << st.get_std() << "\n";
cout << "\n";
cout << st.to_string();
return 0;
}