Finding the oldest person in a large family can be a tedious task. Unfortunately
ID: 3677688 • 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.
Explanation / Answer
Answer==1
#include<stdio.h>
#include<conio.h>
struct oldest
{
int age;
char name[30];
};
void main()
{
struct oldest temp;
int i,j,n;
cout<<" enter the number of record ";
cin>>n;
for(i=0;i<=n;i++)
{
cout<<" Enter the name and age";
cin>>name,age;
}
for(i=1;i<=n;i++)
{
temp=oldest[i];
for(j=i; j>=0 && oldest[j].age>temp.age; j--)
oldest[j+1]=oldest[j];
oldest[j+1]=temp;
}
for(i=0;oldest[i]!=0,i++)
{
//return the last element of the array
return(i)
cout<<" The oldest person is <<i";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.