Please Login in order to post a comment
Here is Class problem solution in C++ - https://programmingoneonone.com/hackerrank-class-solution-in-cpp.html
using namespace std;
class Student { private: int age; int standard; string first_name; string last_name;
public: void input() { cin >> age >> first_name >> last_name >> standard; }
void answer() { cout<<age<<endl; cout<<last_name<<", "<<first_name<<endl; cout<<standard<<endl<<endl; cout << age << "," << first_name << "," << last_name << "," << standard; }
};
int main() { Student st; st.input(); st.answer(); return 0; }
Here is a simplified version I have Taken just Two function input and answers where everything is easy....
#include <iostream> #include <sstream> using namespace std; class Student{ private: int age; int standard; string first_name; string last_name; public: void set_age(int a){ age = a; } void set_standard(int s){ standard = s; } void set_first_name(string fn){ first_name = fn; } void set_last_name(string ln){ last_name = ln; } int get_age(){ return age; } string get_last_name(){ return last_name; } string get_first_name(){ return first_name; } int get_standard(){ return standard; } void to_string(){ cout<<age<<","<<first_name<<","<<last_name<<","<<standard; } }; 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"; st.to_string(); return 0; }
/* Enter code for class Student here. Read statement for specification. */ class Student{ private : int age , standard; string first_name; string last_name; public : Student(){} Student(int Age , string firstName , string lastName , int Standard){ set_age(Age); set_first_name(firstName); set_last_name(lastName); set_standard(Standard); } int get_age(){ return age; } void set_age(int Age){ age=Age; } string get_first_name(){ return first_name; } void set_first_name(string firstName){ first_name=firstName; } string get_last_name(){ return last_name; } void set_last_name(string lastName){ last_name=lastName; } int get_standard(){ return standard; } void set_standard(int Standard){ standard=Standard; } 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;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Here is Class problem solution in C++ - https://programmingoneonone.com/hackerrank-class-solution-in-cpp.html
include
include
using namespace std;
class Student { private: int age; int standard; string first_name; string last_name;
public: void input() { cin >> age >> first_name >> last_name >> standard; }
};
int main() { Student st; st.input(); st.answer(); return 0; }
Here is a simplified version I have Taken just Two function input and answers where everything is easy....
include
include
using namespace std;
class Student { private: int age; int standard; string first_name; string last_name;
public: void input() { cin >> age >> first_name >> last_name >> standard; }
};
int main() { Student st; st.input(); st.answer(); return 0; }
include
include
using namespace std;
/* Enter code for class Student here. Read statement for specification. */ class Student{ private : int age , standard; string first_name; string last_name; public : Student(){} Student(int Age , string firstName , string lastName , int Standard){ set_age(Age); set_first_name(firstName); set_last_name(lastName); set_standard(Standard); } int get_age(){ return age; } void set_age(int Age){ age=Age; } string get_first_name(){ return first_name; } void set_first_name(string firstName){ first_name=firstName; } string get_last_name(){ return last_name; } void set_last_name(string lastName){ last_name=lastName; } int get_standard(){ return standard; } void set_standard(int Standard){ standard=Standard; } 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;
}