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.
/*
Enter code for class Student here.
Read statement for specification.
*/
class Student
{
private:
int a;
int class1;
string f,l;
public:
void set_age(int age);
int get_age(void);
void set_first_name(string first_name);
string get_first_name(void);
void set_last_name(string last_name);
void set_standard(int standard);
string get_last_name();
int get_standard();
string to_string();
I used class, methods stringstream for the first time.
Learned typically we set properties in private then access to them using setters and getters for each properties.
#include<iostream>#include<sstream>usingnamespacestd;/*Enter code for class Student here.Read statement for specification.*/classStudent{private:intstudent_age,student_standard;stringstudent_first_name,student_last_name;stringstreamcombined_attrs;public:voidset_age(intage){student_age=age;}voidset_standard(intstandard){student_standard=standard;}voidset_first_name(stringfirst_name){student_first_name=first_name;}voidset_last_name(stringlast_name){student_last_name=last_name;}intget_age(){returnstudent_age;}intget_standard(){returnstudent_standard;}stringget_first_name(){returnstudent_first_name;}stringget_last_name(){returnstudent_last_name;}stringto_string(){combined_attrs<<student_age<<","<<student_first_name<<","<<student_last_name<<","<<student_standard;returncombined_attrs.str();}};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;}
i am getting ssame output as expected output but after that also it is showing wrong answer please help why?
include
include
include "string"
using namespace std;
/* Enter code for class Student here. Read statement for specification. */ class Student { private: int a; int class1; string f,l; public: void set_age(int age); int get_age(void); void set_first_name(string first_name); string get_first_name(void); void set_last_name(string last_name); void set_standard(int standard); string get_last_name(); int get_standard(); string to_string();
}; void Student :: set_standard(int standard) { class1 = standard; } void Student :: set_age(int age) { a = age; } int Student :: get_age(void) { return a; } void Student :: set_first_name(string first_name) { f = first_name; } string Student :: get_first_name(void) { return f; } void Student :: set_last_name(string last_name) { l = last_name; } string Student :: get_last_name() { return l; } int Student :: get_standard() { return class1; } string Student :: to_string() { stringstream var; var << a << "," << f << "," << l << "," << class1; return var.str(); }
int main() { int age, standard; string first_name, last_name;
}
I used class, methods stringstream for the first time. Learned typically we set properties in private then access to them using setters and getters for each properties.