We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<sstream>#include<string>usingnamespacestd;/*Enter code for class Student here.Read statement for specification.*/classStudent{private:intst_age;stringst_first_name;stringst_last_name;intst_standard;public:Student():st_age(0),st_standard(0){}voidset_age(constintage){st_age=age;}voidset_standard(constintstandard){st_standard=standard;}voidset_first_name(conststring&name){st_first_name=name;}voidset_last_name(conststring&lastName){st_last_name=lastName;}intget_age(){returnst_age;}stringget_last_name(){returnst_last_name;}stringget_first_name(){returnst_first_name;}intget_standard(){returnst_standard;}stringto_string(){conststringx=std::to_string(st_age);conststringy=std::to_string(st_standard);conststrings=x+","+st_first_name+","+st_last_name+","+y;returns;}};intmain(){intage,standard;stringfirst_name,last_name;cin>>age>>first_name>>last_name>>standard;Studentst;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();return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Class
You are viewing a single comment's thread. Return to all comments →
My C++ code 😎😁