12.0k views
0 votes
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

User Boel
by
5.8k points

1 Answer

5 votes

Answer:

Answer to this question is given below in the explanation section.

Step-by-step explanation:

#include <iostream>

#include<iomanip>

#include <string>

#include <cctype>

using namespace std;

int main()

{

string firstName[10], lastName[10];//variable declaration

double gpa[10];

for(int i=0; i<10;i++)//loop for entering 10 students record

{

cout<<"Enter data for student: "<<i+1;//start from 1

cout<<"\\Enter First Name: ";

cin>>firstName[i];

cout<<"Enter Last Name: ";

cin>>lastName[i];

cout<<"Enter the GPA: ";

cin>>gpa[i];

}

cout<<"\\*********************************************************************";

cout<<"\\"<<setw(30)<<"Student Data";//setw set the space to 30

cout<<"\\*********************************************************************";

cout<<"\\";

cout<<setw(10)<<"First Name"<<setw(25)<<"Last Name"<<setw(25)<<"GPA";//display column header

for(int i=0; i<10; i++)//display student entered record

{

cout<<"\\"<<setw(10)<<firstName[i]<<setw(25)<<lastName[i]<<setw(25)<< setprecision(3)<<gpa[i];//setprecision function set the decimal limit to 2

}

cout<<"\\*********************************************************************";

cout<<"\\"<<setw(30)<<"Finished";

cout<<"\\*********************************************************************";

return 0;

}

User Francesco Meli
by
5.6k points