Class and object in C++

 HEY CHECK THIS ONE ALSO ..........


Hacker Rank Class Code Solution............

#include <iostream>
#include <sstream>
#include<string.h>
using namespace std;

/*
Enter code for class Student here.
Read statement for specification.
*/
class Student {
    public:
    int age;
    string first_name, last_name;
    int standard;
    
    public:
    void set_age(int a)
    {
        age = a;
    }
    void set_standard(int s)
    {
        standard = s;
    }
    void set_first_name(string firstname)
    {
        first_name = firstname;
    }
    void set_last_name(string lastname)
    {
        last_name = lastname;
    }
    
    int get_age()
    {
        return age;
    }
    string get_last_name()
    {
        return last_name;
    }
    string get_first_name()
    {
        return first_name;
    }
    int get_standard()
    {
      return standard;  
    }
    string to_strings()
    {
      return to_string(age)+","+first_name+","+last_name+","+to_string(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";
    cout << st.to_strings();
    
    return 0;
}

Comments

Popular posts from this blog

About RAM

Class and object in c++