Question

In: Computer Science

C++: Design a program that takes the height of 10 people (you may take the heights...

C++: Design a program that takes the height of 10 people (you may take the heights in inches) and calculates average height. Based on the average height of these 10 people, determine if this group is better suited to be an MLB team, NBA team, or a group of Jockeys (e.g. Kentucky Derby).

The program is to be user friendly, meaning it is to be used by someone who has never programed.

This program is to loop with a “way out.” “Way out” meaning, a way to shut the program down without closing the window. And, when I mean by loop, I mean the program just restarts after analyzing the first 10 people.

Other requirements

-incorporate an array in collecting your data.

-demonstrate the use of if statements

-demonstrate the use of a loop or loops (if necessary)

-round to whole numbers

-output the average height in feet and inches the average

Solutions

Expert Solution

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    char ch;
    float heights[10],sum=0.0,avg,average_height;
    int i,feet,inches;
    do
    {
        cout<<"Enter the height in inches of a group of 10 students : "<<endl;;
        for(i=0;i<10;i++)       //Taking input of heights of 10 persons
            cin>>heights[i];
        for(i=0;i<10;i++)
            sum=sum+heights[i];
        avg=sum/10;
        average_height=avg*0.08333;
        feet=(int)average_height;       //Average height in feet and inches
        inches=ceil(average_height-feet);   //ceil function is defined in the library header file math.h
        cout<<"The average height of the group of 10 students is : "<<feet<<" feet "<<inches<<" inches"<<endl;
        if(avg>=73)
           cout<<"The group is best suited to be an MLB team "<<endl;
        else if(avg>=70 && avg<73)
           cout<<"The group is best suited to be a NBA team "<<endl;
        else
            cout<<"The group is best suited to be on the team of jockeys"<<endl;
        cout<<"Press 'y' to enter another set of heights or '#' to quit : ";        //A way out of the program
        cin>>ch;
    }while(ch!='#');
    return 0;
}

The output of the code is :

PLEASE LIKE THE ANSWER IF YOU FIND IT HELPFUL OR YOU CAN COMMENT IF YOU NEED CLARITY / EXPLANATION ON ANY POINT.


Related Solutions

Design a program that takes the height of 10 people (you need to take the heights...
Design a program that takes the height of 10 people (you need to take the heights and inches) and calculates average height. Based on the average height of these 10 people, determine if this group is better suited to be an MLB team, NBA team, or a group of Jockeys (e.g. Kentucky Derby). The Input should be be inputed Feet, inches and the output should also feet ,inches. This program should also have a loop as to provide the user...
C language you are to write a a program that will first read in the heights...
C language you are to write a a program that will first read in the heights and weights of a series of people from a file named values.dat. Create this file using your editor so that each line contains a height and corresponding weight. For instance, it might look likea: 69.0 125.0 44.0 100.0 60.0 155.0 49.0 190.0 65.0 115.0 50.0 80.0 30.0 129.0 72.0 99.0 68.0 122.0 50.0 105.0 and so on. The formula for the standard deviation of...
Problem 2: (10 marks) Write a program in C or C++ that takes a number series...
Problem 2: Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print...
A sample of 10 employee’s height is taken to design the height of doorway. The measurements...
A sample of 10 employee’s height is taken to design the height of doorway. The measurements (in cm) are in the following table 167.87 153.24 150.39 173.38 177.91 155.88 171.06 155.57 171.43 178.62 What should be the height of the doorway if you want that just a 0.1% of the employees have troubles passing through it? You think that the initial 10-employee sample is too small and you want to ensure a confidence level of 97% with an error in...
Write a Python program that takes as input two numbers, the height, and width of a...
Write a Python program that takes as input two numbers, the height, and width of a rectangle. It then prints a rectangle with height lines and width characters in each line. The rectangle should contain information regarding its dimensions and area inside (centered vertically but not horizontally). If any part of the information (including two stars on each end and a space before and after the line) does not fit in the rectangle, then print the complete information after the...
Write a C++ program that takes 4 readings of temperature, each reading is between -10 and...
Write a C++ program that takes 4 readings of temperature, each reading is between -10 and 55. The program should: • Computes and print out the average temperature (avgTemp), maximum temperature (maxTemp) and minimum temperature (minTemp) of the day. • The program should also compute and print out the number of temperature readings (numTemp) that exceed 35. • Enforce validation on the user input (using while loop) and use appropriate format for the output. The average temperature should be rounded...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
Does knee height predict overall height? Since elderly people may have difficulty standing to have their...
Does knee height predict overall height? Since elderly people may have difficulty standing to have their heights measured, a study looked at predicting overall height (y) in centimeters, from height to the knee (x) in centimeters. Use this data to answer the following questions. Data looking at knee height (in cm) and overall height (in cm) Knee Height (cm) 57.70 47.40 43.50 44.80 55.20 54.60 Overall Height (cm) 192.10 153.30 146.40 162.70 169.10 177.80 What is the mean x and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT