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
Goshia [24]
3 years ago
5

Write a program that allows the user to enter a start time and a future time. Include a function named compute Difference that t

akes the six variables as parameters that represent the start time and future time. Your function should return, as an int, the time difference in minutes. for example, given a start time of 11:59 AM and a future time of 12:01 PM, your program should compute 2 minutes as the time difference. Given a start time of 11:59 AM and a future time of 11:58 AM, your program should compute 1439 minutes as the time difference (23 hours and 59 minutes). You may need "AM" or "PM" from the user’s input by reading in two character values. (Display 2.3 illustrates character input.) Characters can be compared just like numbers. for example, if the variable a char is of type char, then (a_char == 'A')is a Boolean expression that evaluates to true if a_char contains the letter A.
Computers and Technology
1 answer:
Aleonysh [2.5K]3 years ago
7 0

Step 1

Following is the c++ program:

Variables used:

startHours, startMins are used to store the starting time of time machine.

futureHours, futureMins are used to store the future time of time machine.

xAM variable is used to store meridiem of start and future time.

isSAM is boolean variable that is true if starting time is AM.

isFAM is boolean variable that is true if future time is AM.

 

Functions:

main() is used to call computeDifference() function that will calculate the difference between the start and future time.

computeDifference() takes as input six variables from the user and then apply the following logic to compute the difference between the start and future time:

If Meridien of both start and future time are the same, then simply subtract the start time from the future time.

Difference = future minutes – start minutes

If Meridien of both start and future time are different, then apply the following formula to calculate difference:

Difference = (12 * 60 – start minutes) + future minutes

Step 2

Program :

#include <iostream> //header file for input and output

 

using namespace std;

//calculate the time difference(in minutes) between start time and future time.

int computeDifference(int startHours, int startMins, bool isSAM, int futureHours, int futureMins, bool isFAM) {

 int difference = 0; //to store difference

 startMins = startHours * 60 + startMins; //converting in minutes.

 futureMins = futureHours * 60 + futureMins; //converting in minutes.

 //applying formula for difference.

 if (isSAM == isFAM) {

   difference = futureMins - startMins;

 } else if (isSAM == true && isFAM == false) {

   difference = (12 * 60 - startMins) + futureMins;

 }

}

int main() {

 int startHours, startMins; //it will store start time

 int futureHours, futureMins; //it will store future time.

 string xAM; //it will store meridiem.

 bool isSAM; //it will be true if start time is AM.

 bool isFAM; //it will be true if future time is in AM.

 int difference = 0; //it will store difference.

 cout << "Enter start time of time machine as 'HH MM AM/PM': "; //take input from

You might be interested in
If you find yourself boxed in by a vehicle on your left or right _____________
Zepler [3.9K]

Answer: A. speed up or slow down briefly

Explanation:

put that and then i saw someone said b and it was wrong and i got mad because it was the only answer i got wrong. but it’s a

4 0
3 years ago
Read 2 more answers
Should organizations that promote free trade have environmental or social checks and balances?
Step2247 [10]
it depends on the organization some organizations are more monopolizing than others so it really just depends on the organization that it talks about
6 0
2 years ago
व्याख्या c) Differentiate between Raster Image and Vector Image.​
crimeas [40]

Vector images are described by lines, shapes, and other graphic image components stored in a format that incorporates geometric formulas for rendering the image elements

These are the types of images that are produced when scanning or photographing an object. Raster images are compiled using pixels, or tiny dots, containing unique color and tonal information that come together to create the image.

7 0
2 years ago
Allowing every communication is a bad idea from a security standpoint as well as a productivity one.TrueFalse
s344n2d4d5 [400]

Answer:

The answer to this question is True.

Explanation:

If we allow every communication this will not be a great idea if we want better security and better productivity.

There will be a lot of spam communications so the productivity and the security will also degrade because of that.

So if we want better productivity and security we have to allow a certain number of connections.

Hence the answer to this question is True.

4 0
3 years ago
Write a Python 3 program to read from a .csv file containing rates from power companies. Your program should determine the avera
aliya0001 [1]

Answer:

In python:

file = open("rates.csv", "r")

ratecount = 0

ratesum = 0

mylist = []

rates = file.readlines()

for nums in rates:

     num = nums.rstrip('\n')

     mylist.append(int(num))

     for i in num:

           ratesum= ratesum + int(i)

           ratecount = ratecount + 1

print("Maximum Rate: "+str(max(mylist)))

print("Minimum Rate: "+str(min(mylist)))

print("Average Rate: "+str(ratesum/ratecount))

Explanation:

This opens the csv file

file = open("rates.csv", "r")

This initializes the number of rates in the file

ratecount = 0

This initializes the sum of the rates

ratesum = 0

This initializes an empty list

mylist = []

This reads the rates into lines

rates = file.readlines()

This iterates through the rates (as a string)

for nums in rates:

This removes the newline character \n in the rates

     num = nums.rstrip('\n')

This appends the rates (as an integer) to the empty list

     mylist.append(int(num))

The following counts the rates in the file and also sum them up

<em>      for i in num: </em>

<em>            ratesum= ratesum + int(i) </em>

<em>            ratecount = ratecount + 1 </em>

This prints the maximum of the rates

print("Maximum Rate: "+str(max(mylist)))

This prints the minimum of the rates

print("Minimum Rate: "+str(min(mylist)))

This calculates and prints the average rate

print("Average Rate: "+str(ratesum/ratecount))

6 0
3 years ago
Other questions:
  • What considerations have to be kept in mind with JPEG
    10·1 answer
  • Free points! your welcome
    9·2 answers
  • What is the role of the osi application layer? provides control of all the data flowing between the source and destination devic
    5·1 answer
  • David uses Office Excel 2013 to calculate his average marks. He enters a formula in cell B5 to calculate the average based on th
    11·1 answer
  • Linux would be a good example of?
    6·1 answer
  • Select the correct answer. Vlad wants to include his goals and target in his résumé. He also wants to add how he can be benefici
    12·1 answer
  • Give one example of where augmented reality is used​
    11·2 answers
  • Help me plzzzz ASAP T-T and it's Cyber Security but my last day of school is tomorrow and I'll graduate in June 24 so plzzzzz I
    12·1 answer
  • Make this be a 7th grade argument over a boy
    5·2 answers
  • What is the extension of a Microsoft access database 2013​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!