Hackerrank-C++-Class solution
#include <iostream>
#include <sstream>
#include <string.h>
using namespace std;
class Student{
public:
int age;
int standard;
string first_name;
string last_name;
void set_age(int a)
{
age=a;
}
void set_standard(int s)
{
standard=s;
}
void set_first_name(string s1)
{
first_name=s1;
}
void set_last_name(string s2)
{
last_name=s2;
}
int get_age()
{
return age;
}
string get_last_name()
{
return last_name;
}
string get_first_name()
{
return first_name;
}
int get_standard()
{
return standard;
}
string to_string()
{
string data_1,data_2,data_3,data_4;
stringstream ss1;
ss1<<age;
ss1>>data_1;
data_2=first_name;
data_3=last_name;
stringstream ss2;
ss2<<standard;
ss2>>data_4;
string data_5=data_1+","+data_2+","+data_3+","+data_4;
return data_5;
}
};
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;
}
Comments
Post a Comment