Question

in c++ Write a program that asks the user for the speed of a vehicle (in...

in c++ Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should use a loop to display the total distance traveled. The speed traveled should be limited by the fastest speed achieved by a car thus far. Values should not be negative.•Ex: if hours = 3 and speed = 40, then the program should display•Hour 1: Distance Traveled: 40 miles•Hour 2: Distance Traveled: 80 miles•Hour 3: Distance Traveled: 120 miles

continued•Write a program that asks a person for their weight then converts their weight to the weight on the planet of their choice. This program should use a switch. You may have to use google to look up some conversions. •Example: If the user entered a weight of 180 lbs and chose the planet Jupiter. The program should return: “Your weight on Jupiter is 455 lbs.

Homework Answers

Answer #1

1.

Source Code:

Output:

Code in text format (See above images of code for indentation):

#include <iostream>
using namespace std;
/*main function*/
int main()
{
   /*variables*/
   int speed,hours,i;
   /*read speed from user*/
   cout<<"Enter the speed of the vehicle(in miles per hour): ";
   cin>>speed;
   /*read hours from user*/
   cout<<"Enter number of hours travelled: ";
   cin>>hours;
   /*using a for loop to display the total distance traveled*/
   for(i=1;i<=hours;i++)
   {
       /*calculate and print distance*/
       int d=speed*i;
       cout<<"Hour "<<i<<": Distance Travelled: "<<d<<" miles"<<endl;
   }
   return 0;
}

2.

Source Code:

Output:

Code in text format (See above images of code for indentation):

#include <iostream>
using namespace std;
/*main function*/
int main()
{
   /*variables*/
   double weight;
   int user;
   string planet;
   /*enum planets names*/
   enum planets{mercury,mars,uranus,venus,saturn,neptune,jupiter};
   /*read weight from the user*/
   cout<<"Enter you weight: ";
   cin>>weight;
   /*display and ask the user to choose planet*/
   cout<<"1. Mercury 2.mars 3. uranus 4. venus 5. saturn 6. neptune 7.jupiter\n";
   cout<<"Choose a planet: ";
   cin>>user;
   /*switch block*/
   switch(user-1)
   {
       /*for mercury*/
       case mercury:
           weight=((weight)/9.81)*3.7;
           planet="mercury";
           break;
       /*for mars*/
       case mars:
           weight=((weight)/9.81)*3.711;
           planet="mars";
           break;
       /*for uranus*/
       case uranus:
           weight=((weight)/9.81)*8.69;
           planet="uranus";
           break;
       /*for venus*/
       case venus:
           weight=((weight)/9.81)*8.87;
           planet="venus";
           break;
       /*for saturn*/
       case saturn:
           weight=((weight)/9.81)*10.44;
           planet="saturn";
           break;
       /*for neptune*/
       case neptune:
           weight=((weight)/9.81)*11.15;
           planet="neptune";
           break;
       /*for jupiter*/
       case jupiter:
           weight=((weight)/9.81)*24.79;
           planet="jupiter";
           break;
       /*if invalid option*/
       default:
           cout<<"You choose invalid planet!";
           exit(0);
   }
   /*print weight*/
   cout<<"Your weight on "<<planet<<" is "<<weight<<" lbs";
   return 0;
}

Know the answer?
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
Similar Questions
do the java code below and prove that it works. 2. Distance Traveled The distance a...
do the java code below and prove that it works. 2. Distance Traveled The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed *...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display the distance a vehicle has traveled for each hour of a...
Write a program that asks the user for the name of a file. The program should...
Write a program that asks the user for the name of a file. The program should display only the first five lines of the file’s contents. If the file contains less than five lines, it should display the file’s entire contents. by python using while loop
write a C++ program that asks the user to enter 4 integer numbers then use if...
write a C++ program that asks the user to enter 4 integer numbers then use if ….. elseif ….. elseif ….. else to find the smallest number then display it.
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Write a C++ program that sets the maximum speed limit as a constant integer to be...
Write a C++ program that sets the maximum speed limit as a constant integer to be 120 Km/Hour. The program should read from the user an integer value representing the speed of a car. Use a nested if else to display a message based on the input speed: Speed < 10                      display      “Invalid speed” 10 <= Speed <= 120       display      “Speed is within limit” Speed > 120                    display      “Speed limit exceeded” At the end the program should display a message...
In one C++ program: a.) Write a code to asks the user for her/his full name...
In one C++ program: a.) Write a code to asks the user for her/his full name b.) Write a code that asks the user to enter information related to a car the user likes (year, make, model) c.) Write a code that asks the user to enter the amount of time or gas or money the user spends to commute weekly d.) Write a code that asks the user to enter the number Kwh (used monthly) and compute the user...
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
Please Write code in visual studio Roman Numeral Converter Write a program that asks the user...
Please Write code in visual studio Roman Numeral Converter Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number. Input Validation: Decide how the program should handle an input that is less then 1 or greater than 10.
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...