How to display a c++program showing five students plus there registration numbers.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int SIZE = 5;
class Student
{
private:
string name;
string number;
public:
void addRecord( string name, string number )
{
this->name = name;
this->number = number;
}
void display()
{
cout << left << setw(25) << name << left << setw(22) << number << endl;
}
};
int main()
{
Student s[SIZE];
string name, number;
for(unsigned int i = 0; i < SIZE; ++i)
{
cout << i + 1 <<") Enter name: ";
getline(cin, name);
cout << setw(17) <<"Enter number: ";
getline(cin, number);
s[i].addRecord(name, number);
cout << endl;
}
cout << left << setw(25) << " Name" << left << setw(22) << " Registration number" << endl;
cout << endl;
for(unsigned int i = 0; i < SIZE; ++i)
{
cout << i + 1 <<")";
s[i].display();
}
}
Comments
Leave a comment