Class

  • + 2 comments

    Can someone please specify why this doesn't work? Thanks.

    #include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    
    class Student {
        private:
        int a, st;
        string fn, ln;
        public:
        int age, standard;
        string first_name, last_name;
        void set_age(int age) {
            age = a;
        }
        void set_standard(int standard) {
            standard = st;
        }
        void set_first_name(string first_name) {
            first_name = fn;
        }
        void set_last_name(string last_name) {
            last_name = ln;
        }
        int get_age() {
            return age;
        }
        int get_standard() {
            return standard;
        }
        string get_last_name() {
            return last_name;
        }
        string get_first_name() {
            return first_name;
        }
        string to_string() {
            stringstream ss;
            char c = ',';
            ss << age << endl << last_name << c << first_name << endl << standard << age << c << last_name << c << first_name << c << 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.get_standard();
        cout << st.to_string();
    
        return 0;
    }