Answer:
#include<iostream>
#include<cstring>
#include <algorithm>
using namespace std;
class Student{
public:
string name;
int rollNo;
Student(){
}
Student(string n, int r){
name = n;
rollNo = r;
}
};
class ClassRoom{
public:
Student stud[10];
int count;
ClassRoom(){
count = 0;
}
void addStudent(string str,int roll){
Student s(str,roll);
stud[count++] = s;
}
Student * getAllStudents(){
return stud;
}
};
int main()
{
string name;
char temp[20];
int rollNo, N, i;
Student * students;
ClassRoom classRoom;
i=0;
while(getline(cin, name) && cin.getline(temp,20)&&i<10){
rollNo = atoi(temp);
classRoom.addStudent(name, rollNo);
i++;
}
N = i;
students = classRoom.getAllStudents();
for(int i=0 ; i < N; i++){
cout << (students+i)->rollNo << " - " << (students+i)->name;
if(i<N-1)
cout<<endl;
}
return 0;
}
Explanation: