Write a C++ program to store 10 student names and grade point averages (GPAs) fr
ID: 3795879 • Letter: W
Question
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
Explanation / Answer
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 GPA ";
cout << "---------------------------------------------------------- ";
while(i < 10)
{
cout << names[i] << " " << (gpas[i])*100.0/100.0 << endl;
i++;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.