Question #255085

(1)Define a class student in C++ with the following description. a) data member roll number, name, score, and remarks b) member function to allow user (i) to enter the details (ii) to view the contents of all the data members.

Expert's answer

Source code



#include <iostream>
using namespace std;
class Student{
    private:
        int roll_number;
        string name;
        int score;
        string remarks;
    public:
        void getDetails(){
            cout<<"\nEnter roll number: ";
            cin>>roll_number;
            cout<<"\nEnter name: ";
            cin>>name;
            cout<<"\nEnter score: ";
            cin>>score;
            cout<<"\nEnter remarks: ";
            cin>>remarks;
        }
        void displayDetails(){
            cout<<"\nRoll number: "<<roll_number;
            cout<<"\nName: "<<name;
            cout<<"\nScore: "<<score;
            cout<<"\nRemarks: "<<remarks;
        }
};
int main()
{
    Student s;
    s.getDetails();
    s.displayDetails();


    return 0;
}


Output


LATEST TUTORIALS
APPROVED BY CLIENTS