Answer:
Sorting Algorithm
Explanation:
Here we are arraigning the elements in ascending order. Using for loop we are iterating through all the elements. in one iteration the first minimum element in the list is at 1st place and in the second iteration the second minimum element is in 2nd position and so on
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:
- In the addStudent method, increment the counter and as the value of variable s to the the stud array.
- In the getAllStudents method, return all the students.
- Finally in the main method, display the name and roll no. of students.
D, a customer service oriented, problem solver with strong communication skills