Answer to Question #341861 in C++ for Milly

Question #341861

How to display a c++program showing five students plus there registration numbers.





1
Expert's answer
2022-05-17T16:06:00-0400
#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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS