Answer:
The c++ program for the given scenario is given below.
#include <iostream>
using namespace std;
int main() {
int age;
string person;
cout << "This program prints whether the person is an infant, a child, a teenager or an adult based on the age entered by the user." << endl;
cout << "Enter the age in completed years" << endl;
cin >> age;
if( age>=0 && age<=1 )
person = "infant";
else if( age>1 && age<13 )
person = "child";
else if( age>=13 && age<20 )
person = "teenager";
else
person = "adult";
cout << "The person is " << person << " at the age of " << age << endl;
return 0;
}
OUTPUT
This program prints whether the person is an infant, a child, a teenager or an adult based on the age entered by the user.
Enter the age in completed years
1
The person is infant at the age of 1
Step-by-step explanation:
This program prints the phase of the human life based on the age entered by the user. The program executes as follows.
1. User is prompted to enter the age in completed years. The program does not validates the user inputted age since it is not specifically mentioned in the question.
2. An integer variable, age, is declared which is initialized to the age entered by the user.
3. A string variable, person, is declared which is initialized to the phase of the person based on the entered age. The variable person is not initialized.
4. The age of the user is tested using multiple if else statements. Based on the age criteria given in the question, the variable person is assigned a value. This value represents the phase of the person which is equivalent to the age.
5. The program terminates with a return statement since the main method has the return type of integer.