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...
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.
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
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...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.