Write a complete C++ program called hw14.cpp defines a struct called person as f
ID: 3625773 • Letter: W
Question
Write a complete C++ program called hw14.cpp defines a struct called person as followsstruct person
{ string first;
string last;
int age;
};
Your program should prompt the user for a value for each field. It should then store the user’s input in such a struct. It should then print out the student’s name and age.
SAMPLE RUN
Please enter your first name: Jane
Please enter your last name: Doe
Please enter your age: 19
Hi Jane Doe! You are 19 years old.
NOTE: Recall that you can read a string in directly using cin, you DON’T have to read it in char by char
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
struct person
{ string first;
string last;
int age;
};
int main ()
{person p;
cout<<"Please enter your first name: ";
cin>>p.first;
cout<<"Please enter your last name: ";
cin>>p.last;
cout<<"Please enter your age: ";
cin>>p.age;
cout<<"Hi "<<p.first<<" "<<p.last<<"! You are "<<p.age<<" years old"<<endl;
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.