C# Progrmming The body mass index (BMI) is a measure of relative weight based on
ID: 3747804 • Letter: C
Question
C# Progrmming
The body mass index (BMI) is a measure of relative weight based on height and weight.
Write a program that calculates and prints the BMI for a person; the program allows user to enter values for the name, weight and height of the person,
The formula for BMI is: BMI = (Weight in Pounds / (Height in inches) 2) * 703
Write the following 5 methods: input(3), calculation(1) and display(1).
1.Input method prompts user to enter name of the person and returns name (a string).
2.Input methods (2) prompts user to enter weight in pounds, height in inches of the person and returns weight (a double) and height (a double).
3.Calculation method: parameters of calculation method are weight and height (doubles); the method calculates and returns the BMI corresponding to its input parameters.
4.Display method: print out name, weight, height and BMI of the person showing 2 places behind the decimal point for every double value.
Your Main() will call the input, calculation and display method.
Evaluation
1.Input Method for name exists and returns a string value – 10 points
2.Weight and Height Input Methods exist and return double values – 20 points
3.Calculation Method exists, has appropriate input parameters and returns a double value – 10 points
4.Display Method exists and displays appropriate name, height, weight and BMI values – 20 points
5.Proper Main() method, calls the appropriate methods – 10 points.
6.BMI calculation is correct – 10 points.
7.Output formatting is correct – 10 points.
8.Comments – 10 points.
PLEASE USE THE VISUAL STUDIO 2017 TO MAKE IT EASIER AND FOLLOW ALL THE INSTUCTIONS
Explanation / Answer
using System; namespace BMI { class Program { public static string getName() { Console.Write("Enter name: "); return Console.ReadLine(); } public static void getWeightAndHeight(ref double weight, ref double height) { Console.Write("Enter weight: "); weight = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter height: "); height = Convert.ToDouble(Console.ReadLine()); } public static double calculateBMI(double weight, double height) { return (weight * 703) / (height * height); } public static void display(string name, double weight, double height, double BMI) { Console.WriteLine("BMI of {0} with weight {1:F2} and height {2:F2} is {3:F2}", name, weight, height, BMI); } static void Main(string[] args) { string name; double weight = 0, height = 0, BMI; name = getName(); getWeightAndHeight(ref weight, ref height); BMI = calculateBMI(weight, height); display(name, weight, height, BMI); } } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.