Write a program that allows a user to use the keyboard to input the first and last names
of 40 friends, up to 50 characters each. Display the names 15 at a time, pausing to let the
user press a key before the list continues. Save the file as Friends40.cpp.
1
Expert's answer
2015-02-25T09:56:51-0500
Program: Friends40.cpp #include <iostream> #include <string> #include <stdlib.h> #define MAX_LEN 50 #define MAX_STUD 20 using namespace std; /*Write a program that allows a user to use the keyboard to input the first and last names of 40 friends, up to 50 characters each. Display the names 15 at a time, pausing to let the user press a key before the list continues. Save the file as Friends40.cpp*/ struct friends { char FirstName[MAX_LEN]; char LastName[MAX_LEN]; }; int main() { friends MyFriends[MAX_STUD]; int i; for(i=0;i<MAX_STUD;i++) { cout<<"Input first name for "<<(i+1)<<": "; cin>>MyFriends[i].FirstName; cout<<"Input last name for "<<(i+1)<<": "; cin>>MyFriends[i].LastName; } cout<<"List of friends"<<endl; for(i=0;i<MAX_STUD;i++) { if((i==0)&&(i>0)) //every 15 lines (if not first line) system("pause"); cout<<(i+1)<<". "<<MyFriends[i].FirstName<<" "<<MyFriends[i].LastName<<endl; } return 0; }
Comments
Leave a comment