C++ program to read and print Student information

 

C++ program to define a Student class to read and print Student information using an array of objects

Problem Definition:

Write a C++ program to define a Student class with following Members:

Data  Members: Roll No, Name, Average Marks

Member Functions: to read a data and to print the data.

Program should read 3 student information and print the 3 student information.

Video Tutorial:

Source Code for C++ program to define a Student class to read and print Student information

 #include<iostream>
 using namespace std;
 class Student
 {
     private:
         int rno;
         char name[20];
         float avgmarks;
     public:
         void read_data();
         void print_data();
 };
 void Student::read_data()
 {
     cout<<"Enter the roll no. ";
     cin>>rno;
     cout<<"Enter name. ";
     cin>>name;
     cout<<"Enter Average Marks. ";
     cin>>avgmarks;
 }
 void Student::print_data()
 {
     cout<<rno<<"\t"<<name<<"\t"<<avgmarks<<endl;
 }
 int main()
 {
     Student std[5];
     for (int i=0;i<3;i++)
     {
         std[i].read_data();
     }
     cout<<"Student Information is"<<endl;
     cout<<"RNo\tName\tAvg Marks"<<endl;
     for (int i=0;i<3;i++)
     {
         std[i].print_data();
     }
     return 0;
 }

Output:

Enter the roll no. 1

Enter name. Mahesh

Enter Average Marks. 95.98

Enter the roll no. 2

Enter name. Rahul

Enter Average Marks. 99.99

Enter the roll no. 3

Enter name. Prabhas

Enter Average Marks. 100

Student Information is

RNo Name Avg Marks

1 Mahesh 95.98

2 Rahul 99.99

3 Prabhas 100

4 Sachin 97

5 Virat 96

In this tutorial, we understand how to write C++ program to define a Student class to read and display Student information like roll number, name and average marks.

If you like the material share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds