
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to read the height of a person and the print person is taller, dwarf, or average height person
A person’s height determines whether he/ she is tall, dwarf, or average height person. In different regions of the world, the height ranges are different. We are considering Indian standards. In this article, we shall cover how to write a simple program to determine whether a person is taller, dwarf, or of average height person in C++.
Let us define the height range and corresponding classification first, then we can use them in the algorithm as well as in our implementation.
Height (cm) | Type |
150 – 170 | Average |
170 – 195 | Tall |
Below 150 | Dwarf |
Anything else | Abnormal height |
Now let us see the algorithm and implementation for the same.
Algorithm
- Read the height h .
- If h is within 150 and 170, then.
- The person is of average height.
- Otherwise when h is within 170 and 195, then.
- The person is tall.
- Otherwise when h is below 150, then.
- Person is dwarf.
- For some other cases,
- The person has the abnormal height
- End if.
Example
#include <iostream> using namespace std; void solve( int h ) { if (h >= 150 && h <= 170 ) { cout << "The person is of average height" << endl; } else if (h >= 170 && h <= 195 ) { cout << "The person is tall" << endl; } else if (h < 150 ) { cout << "The person is dwarf" << endl; } else { cout << "The person has abnormal height" << endl; } } int main() { cout << "Height of person A: 172" << endl; solve( 172 ); cout << "Height of person B: 130" << endl; solve( 130 ); cout << "Height of person C: 198" << endl; solve( 198 ); cout << "Height of person D: 160" << endl; solve( 160 ); }
Output
Height of person A: 172 The person is tall Height of person B: 130 The person is dwarf Height of person C: 198 The person has abnormal height Height of person D: 160 The person is of average height
Conclusion
Classification using height is a simple problem where we just use the decision-making with certain conditions. In our implementation there are four classes have been shown, these are tall, dwarf, average, and abnormal height. The height ranges are also defined in the above table. From a simple condition checking if-else solution, the program can classify the person based on his/her given height value.
- Related Articles
- Haskell Program to read the height of a person and the print person is taller, dwarf, or average height person
- The height of a person is 1.65 m. Express it into cm and mm.
- What is the daily routine of an average person?
- The height of a person is ( 1.45 mathrm{~m} ). Express it into ( mathrm{c} mathrm{m} ) and ( mathrm{mm} ).
- Why a living person sinks and a dead person floats in water?
- The average breathing rate of an adult is 15 - 18 times a min, so what will be the breathing rate when a person is running and when a person is sleeping?
- A person can read a book clearly only if he holds it at an arm's length from him. Name the defect of vision:(a) if the person is an old man (b) if the person is a young man
- When is a person said to have developed cataract in his eye? How is the vision of a person having cataract restored?
- Program to find number of possible position in n-person line with few person at front and back in Python
- What is the far point of a person suffering from myopia (or short-sightedness)?
- Where is the near point of a person suffering from hypermetropia (or long-sightedness)?
- Python Program to Read Height in Centimeters and convert the Height to Feet and Inches
- Who is the most accidentally famous person ever?
- Rights of an Arrested Person
- How to Take Care of a Drunk Person?
