190k views
5 votes
A program is used to convert from minutes to seconds. Write the directive for defining the conversion factor called MINUTE_TO_SECOND_FACTOR as a constant that cannot be changed and define it as a string 60.

1 Answer

2 votes

Answer:

I am writing a simple program in C++ However, let me know if you need this program to be implemented in some other programming language .

Program

#include <iostream>

using namespace std;

#define MINUTE_TO_SECOND_FACTOR 60

int main()

{ int minutes;

cout<<"enter the time in minutes: ";

cin>>minutes;

int output;

output = minutes * MINUTE_TO_SECOND_FACTOR;

cout<<minutes<<" minutes = "<<output<<" seconds.";

Output:

enter the time in minutes: 45

45 minutes = 2700 seconds

Step-by-step explanation:

I will explain every line of the code .

  • The first statement contains a pre-processor directive which is a library that contains input and output functions for a program.
  • The next line namespace is used so that the computer can identify cout, cin and endl used in the program.
  • This is a define directive #define MINUTE_TO_SECOND_FACTOR 60
  • Here define directive is used for declaring a macro which is MINUTE_TO_SECOND_FACTOR.
  • Here this macro is given a value 60.
  • Now wherever in the program this macro is used, it will be replaced by 60. This macro MINUTE_TO_SECOND_FACTOR can be used as a constant and cannot be changed.
  • Next line enters the body of the main function.
  • variable minutes is declared which is used to store the value in minutes.
  • variable is declared which will store the result of the conversion from minutes to seconds.
  • output = minutes * MINUTE_TO_SECOND_FACTOR; statement works as follows:

In this statement written above the value of minutes is multiplied by 60 ( value of the macro MINUTE_TO_SECOND_FACTOR) and the result of this multiplication is stored in the output variable.

  • As we know that 1 minute =60 seconds
  • Let suppose the input number is 45 minutes

Then output= 45 * 60

output= 2700 seconds.

  • Last statement displays the converted value of minutes into seconds which is stored in output variable.
User Sbrrk
by
3.4k points