write a complete C++ program that: a) initially asks the user to enter five sets of first name, last name and age; b) extracts the first name initial from the entered first name; c) uses arrays to store the entered information; and d) displays on the output monitor all the five sets of entered information in a table form as shown in sample output below.
#include <iostream>
#include <string>
using namespace std;
int main () {
//uses arrays to store the entered information
string firstNames[5];
string lastNames[5];
int ages[5];
//initially asks the user to enter five sets of first name, last name and age
for(int i=0;i<5;i++){
cout<<"Enter first name "<<(i+1)<<": ";
getline(cin,firstNames[i]);
//extracts the first name initial from the entered first name
firstNames[i]=firstNames[i][0];
cout<<"Enter last name "<<(i+1)<<": ";
getline(cin,lastNames[i]);
cout<<"Enter age "<<(i+1)<<": ";
cin>>ages[i];
cout<<"\n";
cin.ignore();
}
//displays on the output monitor all the five sets of entered information in a table form as shown in sample output below.
cout<<"Last name\t\tFirst name\tAge\n";
for(int i=0;i<5;i++){
cout<<lastNames[i]<<"\t\t\t"<<firstNames[i]<<"\t\t"<<ages[i]<<"\n";
}
//Delay
system("pause");
return 0;
}
Comments
Leave a comment