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

Answer :

asarwar

Answer:

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

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<<"\nEnter First Name: ";

       cin>>firstName[i];

       cout<<"Enter Last Name: ";

       cin>>lastName[i];

       cout<<"Enter the GPA: ";

       cin>>gpa[i];

   }

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

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

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

  cout<<"\n";

  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<<"\n"<<setw(10)<<firstName[i]<<setw(25)<<lastName[i]<<setw(25)<< setprecision(3)<<gpa[i];//setprecision function set the decimal limit to 2

  }

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

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

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

   

   

   return 0;

}

                                                                                                                                                                                                                                                             

Other Questions