Answer to Question #172079 in C++ for Kamalakannan.E

Question #172079

Display students details in the following format using manipulats

Rollno Name Marks average

------  ---   ----   -------

1        Ram  490    98.17

2        Kala  450     96.23


1
Expert's answer
2021-03-16T05:08:36-0400
#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]));
}

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