Answer to Question #212802 in C++ for shahil

Question #212802

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.


1
Expert's answer
2021-07-03T04:46:45-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS