Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 6, 2019 22:06
Show Gist options
  • Save lazycipher/21911e2a00ca95a7a95bfd64f9fa431e to your computer and use it in GitHub Desktop.
Save lazycipher/21911e2a00ca95a7a95bfd64f9fa431e to your computer and use it in GitHub Desktop.
Class Problem HackerRank in C++
#include <iostream>
#include <sstream>
using namespace std;
class Student{
private:
int age, standard;
string first_name, last_name;
public:
// Setter
void set_age(int age) { this->age = age; }
void set_standard(int standard) { this->standard = standard; }
void set_first_name(string first_name) { this->first_name = first_name; }
void set_last_name(string last_name) { this->last_name = last_name; }
// Getter
int get_age() { return this->age; }
int get_standard() { return this->standard; }
string get_first_name() { return this-> first_name; }
string get_last_name() { return this->last_name; }
// String Operation
string to_string(){
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment