Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
71 views

Array of Objects

The document defines a Student class with name and marks data members and getName(), getMarks(), and displayInfo() member functions. The main() function creates an array of 5 Student objects, uses a for loop to get name and marks input for each student using the member functions, and another for loop to display each student's name and marks using displayInfo().

Uploaded by

amolia2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Array of Objects

The document defines a Student class with name and marks data members and getName(), getMarks(), and displayInfo() member functions. The main() function creates an array of 5 Student objects, uses a for loop to get name and marks input for each student using the member functions, and another for loop to display each student's name and marks using displayInfo().

Uploaded by

amolia2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

class Student
{
string name;
int marks;

public:

void getName()
{
cin>>name;
}
void getMarks()
{
cin >> marks;
}
void displayInfo()
{
cout << "Name : " << name << endl;
cout << "Marks : " << marks << endl;
}
};

int main()
{
Student st[5];
for( int i=0; i<5; i++ )
{
cout << "Student " << i + 1 << endl;
cout << "Enter name" << endl;
st[i].getName();
cout << "Enter marks" << endl;
st[i].getMarks();
}
for( int i=0; i<5; i++ )
{
cout << "Student " << i + 1 << endl;
st[i].displayInfo();
}
return 0;
}

You might also like