Write a C program to store 10 student names and grade point
Write a C++ program to store 10 student names and grade point averages (GPAs) from the user. Display all student information in a tabular format. Ensure that each column heading aligns correctly with its respective column and that each name (first and last) is capitalized. Finally, display each GPA with two significant decimals. Sample inputs and outputs are as follows: Sample Input (for only 3 students) Smith, Tom 4.0 Jones, Bob 5.555 Washington, George 3.00 Sample Output (using input above) Name (Last, First) GPA Smith, Tom 4.00 Jones, Bob 5.56 Washington, George 3.00
Solution
C++ code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
std::vector<string> names;
std::vector<float> gpas;
int i = 0;
while(i<10)
{
cout << \"Enter Name of student with ID \" << i+1 << endl;
string s;
getline(cin,s);
names.push_back(s);
cout << \"Enter GPA of student with ID \" << i+1 << endl;
getline(cin,s);
gpas.push_back(atof(s.c_str()));
i++;
}
i = 0;
cout << \"----------------------------------------------------------\ \";
cout << \"Name\\t\\t\\tGPA\ \";
cout << \"----------------------------------------------------------\ \";
while(i < 10)
{
cout << names[i] << \"\\t\\t\\t\" << (gpas[i])*100.0/100.0 << endl;
i++;
}
return 0;
}
