Finding the oldest person in a large family can be a tedious task. Unfortunately
ID: 3677691 • Letter: F
Question
Finding the oldest person in a large family can be a tedious task. Unfortunately, that's exactly what your dad has asked you to do. He will give you a list of your relatives with their ages, and he expects you to give him the name of the oldest person.
Write a program that reads in a list of names and ages until the user enters "quit" as a person’s name. When the sentinel (quit) appears as the name, your program should display the name of the oldest person in the list and then terminate. For example, with the list of entries
Tommy
17
Don Hodges
42
Kathy
51
Ken Summers
19
Elsa Turner
35
quit
the program will print
The oldest person is Kathy.
Name this program Oldest.cpp.
NOTE: The 10 program standards are given below:
1. Program Header . In addition to you name and project number, include a brief description of the program functionality in the header comment for the program
2. Variables and Constants. All variables and constants in a program must be declared at the beginning of the program
3. Initialization. Variables may not be initialized in their declaration.
4. Printing of if-then. Use one of the following
if (expression) statement
if (expression)
Single-statement
if (expression) {
Multiple-statements
}
5. Printing of if-then-else. Use one of the following
if (expression) statement
else statement
if (expression)
Single-statement
else
Single-statement
if (expression) {
Multiple-statements
} else {
Multiple-statements
}
6. Printing of while loops. Use one of the following
while (expression) statement
while (expression)
Single-statement
while (expression) {
Multiple-statements
}
For loops. The bodies of all for-loops must be indented at least 3 (but no more than 5) spaces:
for(int i = 0; i < n; i++) {
cout << "Enter the number:" << flush;
cin >> num;
if (num < 0) num_neg++;
else if (num > 0) num_pos++;
else num_zero++;
}
Methods. The bodies of all functions must be indented at least 3 (but no more than 5) spaces:
double CircleArea(double r) {
const double Pi = 3.1415;
return Pi * r * r;
}
Variable names. Variables that denote things should have names that are nouns or noun phrases.
Method names. Methods that have side effects should have names that are verbs or verb phrases. Methods that return a value should have names that are nouns or noun phrases.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int age,max;
string name="";
cout<<"Enter the name: "<<endl;
cin>>name;
cout<<"Enter the age: "<<endl;
cin>>age;
while(name!='quit')
{
name++;
cout<<"Enter the next person's name: "<<endl;
cin>>name;
cout<<"Enter the next person's age: "<<endl;
cin>>age;
age++;
}
max = age;
if (age > max)
{
max = age
oldest = name
}
cout << "Max age is: " <<name;
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.