1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nady [450]
3 years ago
6

Two cars A and B leave an intersection at the same time. Car A travels west at an average speed of x miles per hour and car B tr

avels south at an average speed of y miles per hour. Write a program that prompts the user to enter: The average speed of both the cars The elapsed time (in hours and minutes, separated by a space) Ex: For two hours and 30 minutes, 2 30 would be entered

Computers and Technology
1 answer:
drek231 [11]3 years ago
3 0

Answer:

Here is the C++ program:

#include <iostream>  // to use input output functions

#include <cmath>  // to use math functions like sqrt()

#include <iomanip>  //to use setprecision method

using namespace std;   //to access objects like cin cout

int main ()  {  //start of main function

  double speedA;  //double type variable to store average speed of car A

  double speedB;  //double type variable to store average speed of car B

  int hour;  //int type variable to hold hour part of elapsed time

  int minutes;  //int type variable to hold minutes part of elapsed time

  double shortDistance;  // double type variable to store the result of shortest distance between car A and B

  double distanceA;  //stores the distance of carA

  double distanceB;  //stores the distance of carB

  double mins,hours;   //used to convert the elapsed time

cout << "Enter average speed of car A: " << endl;  //prompt user to enter the average speed of car A

cin >> speedA;   //reads the input value of average speed of car A from user

cout << "Enter average speed of car B: " << endl ;  //prompt user to enter the average speed of car B

cin >> speedB;   //reads the input value of average speed of car A from user

cout << "Enter elapsed time (in hours and minutes, separated by a space): " << endl;  //prompts user to enter elapsed time

cin>> hour >> minutes;    //reads elapsed time in hours and minutes

  mins = hour * 60;  //computes the minutes using value of hour

  hours = (minutes+mins)/60;     //computes hours using minutes and mins

distanceA = speedA * (hours);  // computes distance of car A

distanceB = speedB * (hours);   //computes distance of car B

   shortDistance =sqrt((distanceA * distanceA) + (distanceB * distanceB));   //computes shortest distance using formula √[(distanceA)² + (distanceB)²)]

cout << "The (shortest) distance between the cars is: "<<fixed<<setprecision(2)<<shortDistance;

//display the resultant value of shortDistance up to 2 decimal places

Explanation:

I will explain the program with an examples:

Let us suppose that the average speeds of cars are:

speedA = 70

speedB = 55

Elapsed time in hours and minutes:

hour = 2

minutes = 30

After taking these input values the program control moves to the statement:

mins = hour * 60;  

This becomes

mins = 2 * 60

mins = 120

Next

hours = (minutes+mins)/60;

hours = (30 + 120) / 60

         = 150/60

hours = 2.5

Now the next two statements compute distance of the cars:

distanceA = speedA * (hours);  

this becomes

distanceA = 70 * (2.5)

distanceA = 175

distanceB = speedB * (hours);

distanceB = 55 * (2.5)

distanceB = 137.5

Next the shortest distance between car A and car B is computed:

shortDistance = sqrt((distanceA * distanceA) + (distanceB * distanceB));

shortDistance = sqrt((175 * 175) + (137.5 * 137.5))

                        = sqrt(30625 + 18906.25)

                        = sqrt(49531.25)

                        =  222.556173

shortDistance =  222.56

 

Hence the output is:

The (shortest) distance between the cars is: 222.56        

You might be interested in
A pangram is a sentence that contains all the letters of the English alphabet at least once. For example, the quick brown fox ju
erma4kov [3.2K]
Do you want this in paragraph form ?
5 0
2 years ago
You are building a gaming computer and you want to install a dedicated graphics card that has a fast GPU and 1GB of memory onboa
Vilka [71]

Answer:

a. PCI express

Explanation:

<em>PCI express</em> (Peripheral Component Interconnect Express) is a high speed serial bus and commonly used motherboard interface for  Graphics card, wifi, SSDs and HDs hardware connections. Simple PCI can also be used but PCI express has more error detection accuracy lesser number of I/O pins and better throughput as compared to simple PCI.

6 0
2 years ago
The arcade machine market crash in the 1980's because:
Blababa [14]

Answer:

C) A quarter was worth less than is used to be.

Explanation:

I got this answer wrong when I chose B.

7 0
3 years ago
The background image does not affect any cell’s format or content. _______
Korvikt [17]
Hmmm...that is true 
Here a quizlet about if you need it!
https://quizlet.com/15207805/csci-241-flash-cards/
3 0
2 years ago
You are designing an internet router that will need to save it's settings between reboots. Which type of memory should be used t
Phoenix [80]

Answer:

d. Flash

Explanation:

A flash memory can be defined as an electronic non-volatile memory chip (storage medium) that is typically used on computer systems and other digital devices such as routers, USB flash drives, switches, digital cameras, mp3 players etc. A flash memory is an electronically erasable programmable read only memory (EEPROM) and as such data saved (written) on it can be erased electronically. Also, a flash memory do not require a source of power (electricity) to save or retain data through the use of a floating gate MOSFET (FGMOS) or floating gate transistor.

In this scenario, you are designing an internet router that will need to save it's settings between reboots. The type of memory that should be used to save these settings is a flash memory because it does not require power to write or save data.

8 0
3 years ago
Other questions:
  • Which software application should be used to create a sales pitch to a group of people? Database Email Presentation Word process
    9·1 answer
  • Given three floating-point numbers x, y, and z, output x to the power of y, x to the power of (y to the power of z), the absolut
    9·1 answer
  • 1.) How do parks and other green spaces benefit a community?
    7·2 answers
  • ) How many switching functions of two variables (x and y) are there?
    11·1 answer
  • What is the Documenter?
    10·1 answer
  • I have a question on an IT crossword the question is as follows
    12·1 answer
  • If a piece of software designed to run on Windows XP can run on the latest version of Windows, we say the latest version of Wind
    14·1 answer
  • Please hurry!
    15·2 answers
  • Kelly wants to change the text in a cell so that it is centered instead of left-aligned, where should she look to make this
    8·1 answer
  • Connect research concepts to their definitions
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!