Display students details in the following format using manipulats
Rollno Name Marks average
------ --- ---- -------
1 Ram 490 98.17
2 Kala 450 96.23
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
struct Student {
int no;
string name;
int marks;
double avrg;
};
void PrintStudents(const Student* students, int n) {
cout << fixed << setprecision(2) << left;
cout << "Rollno" << " " << setw(8) <<"Name" << " "
<< setw(5) << "Marks" << " " << setw(7) <<"average" << endl;
cout << "------" << " " << "--------" << " "
<< "-----" << " " << "-------" << endl;
for (int i=0; i<n; i++) {
cout << setw(6) << students[i].no << " "
<< setw(8) << students[i].name << " "
<< setw(5) << students[i].marks << " "
<< setw(7) << students[i].avrg << endl;
}
}
int main() {
Student students[] = { {1, "Ram", 490, 98.17},
{2, "Kala", 450, 96.23} };
PrintStudents(students, sizeof(students)/sizeof(students[0]));
}
Comments
Leave a comment