The perfect place for easy learning...

OOPs using C++

×

List of Programs


C++ Practical Programs


Aim


Write a C++ Program to display Names, Roll No., and grades of 3 students who have appeared in the examination. Declare the class of name, Roll No. and grade. Create an array of class objects. Read and display the contents of the array.

Procedure


  • Step 1 - Include the required header files (iostream.h and conio.h).
  • Step 2 - Create a class (StudentInfo) with the following class members as public members.
    • student_name, roll_number and grade as data members.
    • read_info() and display_info() as member functions.
  • Step 3 - Implement the read_info() and display_info() member functions.
  • Step 4 - Create a main() method.
  • Step 5 - Create an object of the above class inside the main() method.
  • Step 6 - Make function calls to read_info() and display_info() using class object.

Implementation


C++ Program
#include <iostream>

using namespace std;

class Student_Info{
    int roll_number;
    char student_name[50], grade[2];

    public:
        void read_data(int count){
            cout<<"\n\n--------- Enter student "<<count+1<<" information ---------\n";
            cout<<"Name of the Student (Max. 50 characters only): ";
            cin>>student_name;
            cout<<"Roll Number: ";
            cin>>roll_number;
            cout<<"Grade (O, A+, A, B+, B, C, D, F): ";
            cin>>grade;
            cout<<"\nStudent information with roll number "<<roll_number<<" has saved!";
        }
        void display_data(int count){
            cout<<"\n\n******** Student "<<count+1<<" Information ********";
            cout<<"\nName of the Student: "<<student_name;
            cout<<"\nRoll Number: "<<roll_number;
            cout<<"\nGrade Secured: "<<grade;
            cout<<"\n---------------------------------------\n";
        }
};

int main(){
    Student_Info stud[3];
    int i;
    for(i=0; i<3; i++)
        stud[i].read_data(i);
    cout<<"\n\n+++++++++++++++++++++++++++++++++++++++++++++++\n";
    cout<<"The information of 3 students has been saved.";
    cout<<"\n+++++++++++++++++++++++++++++++++++++++++++++++\n";
    for(i=0; i< i++)
        stud[i].display_data(i);
    return 0;
}

Result



   Download Source Code

Place your ad here
Place your ad here