Question

Language: C# In this assignment we are going to convert weight and height. So, the user...

Language: C#

In this assignment we are going to convert weight and height. So, the user will have the ability to convert either weight or height and as many times as they want. There conversions will only be one way. By that I mean that you will only convert Pounds to Kilograms and Feet and Inches to Centimeters. NOT the other direction (i.e. to Pounds). There will be 3 options that do the conversion, one for each type of loop. In the beginning and after each module has run the menu will be shown.

Hint: create the main conversion routine and then that routine should be the same inside each loop.

Assignment requirements:

  • The user will be able to convert either weight or height as many times as they want
    • Option A, the While loop – they will also have the choice of not doing any conversions
    • Option B, the Do-While – they will always do at least one conversion
    • Option C, the For loop –they will do 5 conversions every time
    • Don’t forget about the option to exit
  • With the correct answer you will also display the number(s) entered
  • You must use meaningful variable names
  • You must have the following 4 classes and functions in your project
  • Your heading class. Only getName, getHeading and getClosing functions will exist in this class
  • “YourName” + Assignment5 (mine would be SchuettAssignment5)
    • This class file is for the main which runs the whole program.
    • Only the main() will exist in this class
  • The ConversionMenu
    • You will create a menu that is displayed at the beginning of the program and after each conversion. The goal here is ease of use for the user.
    • Your header that will run at the beginning of the Menu
    • Only the menu() function will exist in this class and it will return a string of the users’ choice
    • Your Menu will give the options to run A, B, C (i.e. the three different loops) or to exit
    • Each time an option is run it will go back to the Menu. Except for the exit option
    • You will give the user the choice of converting feet and inches to centimeters or pounds to kilograms
    • NOTE: to get this to work with only one menu, you will need to pass in arguments so the menu knows which part of the program it’s presenting information for. Be Creative!
  • The Conversions
    • This class file for the functions used for converting weight and a separate C# file for the functions that convert height as well as the output
    • All of the conversion functions needed for this project, that are not mentioned above, will be in this class
    • Format the output so you are showing 2 decimal places (i.e. ###.##)
    • Functions names and return types:
      • heightConversion and returns a double
      • Cm = (feet * 30.48) + (inches * 2.54)
    • weightConversion and returns a double
        • Kg = lbs * 0.45359
      • GetLBS and returns a double
      • GetFeet and returns a double
      • GetInches and returns a double
      • KiloPrint and is a void
      • CMPrint and is a void
    • You will have to figure out what each function needs for an argument list
0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
public class Header{
string name,header,closing;
public Header(string name,string header,string closing){
this.name=name;
this.header=header;
this.closing=closing;
}
public string getName(){
return name;
}
public string getHeader(){
return header;
}
public string getClosing(){
return closing;
}
public void Menu(){
Console.WriteLine("\nA-You will also have the choice of not doing any conversions");
Console.WriteLine("B-You will always do at least one conversion");
Console.WriteLine("C-You will do 5 conversions every time");
Console.WriteLine("E- Exit\n");
}
}
public class Weight{
double lbs;
public Weight(double lbs){
this.lbs=lbs;
}
double GetLBS(){
return lbs;
}
public double weightConversion(){
return lbs * 0.45359;
}
public void KiloPrint(){
Console.WriteLine(lbs+" pounds = "+Math.Round(weightConversion(),2)+" kgs");
}
}
public class Height{
double feet,inches;
public Height(double feet,double inches){
this.feet=feet;
this.inches=inches;
}
double GetFeet(){
return feet;
}
double getInches(){
return inches;
}
public double heightConversion(){
return (feet * 30.48) + (inches * 2.54);
}
public void CMPrint(){
Console.WriteLine(feet+" feet "+inches+" inches = "+Math.Round(heightConversion(),2)+" Centimeters");
}
}
public class ConversionMenu{
public static void Main(string[] args){
int choice;
string name;
Console.WriteLine("Enter your name:");
name=Console.ReadLine();
Header hd=new Header(name,"conversion",".");
Console.WriteLine("\nHello!.."+name+"\n");
Console.WriteLine("Enter a Integer 1 :convert pounds to kilograms");
Console.WriteLine("Enter a Integer other than 1 :convert feet and inches to centimeters");
choice=Convert.ToInt32(Console.ReadLine());
try{
if(choice==1){
double lbs,kg;
int weightExit=0;
while(weightExit==0){
hd.Menu();
Console.WriteLine("Enter your option:");
string option=Console.ReadLine();
switch(option){
case "A":
while(true){
Console.WriteLine("enter weight in pounds (press -1 to exit):");
lbs=Convert.ToDouble(Console.ReadLine());
if(lbs==-1)
break;
Weight w=new Weight(lbs);
kg=w.weightConversion();
if(lbs>=0)
w.KiloPrint();
else
Console.WriteLine("Enter positive numbers");
}
break;
case "B":
int doStop=0;
do{
Console.WriteLine("enter weight in pounds(press -1 to exit):");
lbs=Convert.ToDouble(Console.ReadLine());
if(lbs==-1 && doStop==1)
break;
Weight w=new Weight(lbs);
kg=w.weightConversion();
if(lbs>=0)
w.KiloPrint();
else
Console.WriteLine("Enter positive numbers");
doStop=1;
}while(true);
break;
case "C":
for(int i=1;i<=5;i++){
Console.WriteLine("enter weight in pounds(conversion:"+i+"):");
lbs=Convert.ToDouble(Console.ReadLine());
Weight w=new Weight(lbs);
kg=w.weightConversion();
if(lbs>=0)
w.KiloPrint();
else
Console.WriteLine("Enter positive numbers");
}
break;
case "E":
weightExit=1;
break;
default:
Console.WriteLine("Enter proper option");
break;
}
}
}
else{
double inches,feet,cm;
int heightExit=0;
while(heightExit==0){
hd.Menu();
Console.WriteLine("Enter your option:");
string option=Console.ReadLine();
switch(option){
case "A":
while(true){
Console.WriteLine("enter Feet:(press -1 to exit)");
feet=Convert.ToDouble(Console.ReadLine());
if(feet==-1)
break;
Console.WriteLine("enter inches:");
inches=Convert.ToDouble(Console.ReadLine());
Height h=new Height(feet,inches);
cm=h.heightConversion();
if(feet>=0 && inches>=0)
h.CMPrint();
else
Console.WriteLine("Enter positive numbers");
}
break;
case "B":
int doStop=0;
do{
Console.WriteLine("enter Feet:(press -1 to exit)");
feet=Convert.ToDouble(Console.ReadLine());
if(feet==-1 && doStop==1)
break;
Console.WriteLine("enter inches:");
inches=Convert.ToDouble(Console.ReadLine());
Height h=new Height(feet,inches);
cm=h.heightConversion();
if(feet>=0 && inches>=0)
h.CMPrint();
else
Console.WriteLine("Enter positive numbers");
doStop=1;
}while(true);
break;
case "C":
for(int i=1;i<=5;i++){
Console.WriteLine("enter Feet:(press -1 to exit)");
feet=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("enter inches:");
inches=Convert.ToDouble(Console.ReadLine());
Height h=new Height(feet,inches);
cm=h.heightConversion();
if(feet>=0 && inches>=0)
h.CMPrint();
else
Console.WriteLine("Enter positive numbers");
}
break;
case "E":
heightExit=1;
break;
default:
Console.WriteLine("Enter proper option");
break;
}
}
}
}
catch(Exception e){
Console.WriteLine("\nplease input carefully\n"+e);
}
}
  

Add a comment
Know the answer?
Add Answer to:
Language: C# In this assignment we are going to convert weight and height. So, the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class...

    In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files.  One (.h) file for the class definitions, both of them.  The class implementation file which has the member function definitions. And the main project file where your main...

  • Write a Program that has a menu with a  layout below, that asks the user if they...

    Write a Program that has a menu with a  layout below, that asks the user if they want to: 1. Converts from feet and inches to meter and centimeters 2. Converts from meter and centimeters to feet and inches 3. Quit the program The program should continue as long as the user asks it to. The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall...

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • Write a single C++ program that performs the following conversion (The modulus divide will help you...

    Write a single C++ program that performs the following conversion (The modulus divide will help you get the remainder as shown in class) 39 / 12 = 3 and 39 % 12 = 3, so 3 feet 3 inch(es) Height conversion 1 meter = 39 inches 12 inches = 1 foot Ask/Prompt the user to enter in the height in meters, convert and output the result in feet and inches Example 1 meters as input should produce 3 feet (foot)...

  • /////////////////////////////////////////////////////////////////////////////////// //This program // 1. asks the user her/his weight and height // 2. then calculates...

    /////////////////////////////////////////////////////////////////////////////////// //This program // 1. asks the user her/his weight and height // 2. then calculates the user's body-mass-index (BMI) // 3. and then prints an appropriate message based on the user's BMI /////////////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; void printWelcome(); // ask the weight (in pounds) and height (in inches) of the user and store the values in formal // parameters weight and height, respectively void getWeightAndHeight(float& weight, float& height); // calculate and return the BMI (Body-Mass-Index) based on...

  • I have this c++ program that i have to create but i am stuck on it....

    I have this c++ program that i have to create but i am stuck on it. Write a height conversion program that shall allow user to convert from feet and inches to meters (option 1) and vice versa (option 2). User shall be able to specify the type of conversion (a menu of two options). Display an error message if an invalid option is specified. Otherwise, the program would read in a length in feet and inches (two separate integer...

  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • In this exercise, you’ll add code to a form that converts the value the user enters...

    In this exercise, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: 1. Open the Conversions project. Display the code for the form, and notice the rectangular array whose rows contain the value to be displayed in the combo box, the text for the labels that identify the two text boxes, and the multiplier for the conversion as shown above. Note: An array...

  • Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds:...

    Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds: "message and store in the weight variable. 6. Initialize an int variable named heightIn Inches to feet OſHeight times 12 plus Inches OfHeight. 7. Initialize a double variable named BMI to weight * 703.0 heightIrinches El VB 8. Initialize a double variable named ratio to height In Inches? 703.0 9. Initialize a double variable named lower Normal to 18.5 times ratio. 10. Initialize a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT