Question

Complete the incomplete code provided

//Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //CalculaIntro to Programming in C - small program (prog7) Project objective: To compile, build, and execute an interactive program usCOP 2220 prog7.c steps **Please do only one step at a time and do not move onto the next step until you have compiled and tes

//Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and return (by reference) the total time it will take as a double //And also calculate the number of hours and number of minutes void TripTime (double miles, double *totalTimePtr, int *hoursPtr, int minutesPtr) int main() //Greet the user //declare 3 double variables (miles, gas, time) //declare 2 integer variables (hours, minutes) //see the assignment instructions for more details return 0 //function definitions
Intro to Programming in C - small program (prog7) Project objective: To compile, build, and execute an interactive program using loops and user defined functions with pass by reference and pass by copy arguments **Submit source code (lastname firstname_prog7.c) through Canvas One source code file (unformatted text) will be submitted The file name must match the assignment : lastname_firstname_prog7.c The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas .The code must be submitted on time in order to receive credit (11:59 PM on the due date) Late submissions will not be accepted or graded All programming assignments are individual work, sharing code is considered cheating Calculate the cost of gas and the time it will take for a road trip. Assume the user will drive an average of 70 MPH. The user will enter the number of miles, the cost of gas per gallon, and the miles per gallon(mpg) of the car //Calculate the cost of the gas on a trip //declare, ask, and get the price per gallon and the mpg //calculate and return(by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr); //using a 75 MPH speed limit and the miles passed to the function //calculate and return (by reference) the total time it will take as a double //And also calculate the number of hours and number of minutes void TripTime(double miles, double *totalTimePtr, İnt *hoursPtr, İnt *minutesPtr); //Main function logic: /declare 3 double variables (miles, gas, time) /declare 2 integer variables (hours, minutes) ask and get the number of miles // pass the miles (by copy) and the "address of" gas to the GasCost function //Tell the user how much the gas will cost //pass the miles, "address of" time, "address of" hours, and "address of" minutes //Tell the user how much total time it will take as a double (time) /also tell the user how many hours and how many minutes that is
COP 2220 prog7.c steps **Please do only one step at a time and do not move onto the next step until you have compiled and tested the current step 1. Read the assignmen 2. Create an empty project 3. Add the source code Tile and name it lastname firstname progI.C 4. Copy and paste the prog7.c template 5. Change the header comment so that it has your name, date, and a description of the program t instructions build run and test Be sure to add a Greeting (a Greeting function may be added) 7. 6. Ask and get a value for the number of miles (You may add a function for this) build run and test 8. Now it is time to implement the GasCost function definition. Create the function definition (block of code) below the main function Inside the function you will need to get the price per gallon from the user Inside the function you will also need to get the miles per gallon (MPG) of the user's car Make the total gas calculation for the number of miles (argument 1) and store the result in the "value at" gasTotalPtr . . ***build run and test 9. Now it is time to test the GasCost function with a function call 10. Write the statement to call the GasCost function from inside the main function and pass the miles and the "address of" gas to the function 11. Print gas onto the screen from the main function to see the total build run and test 12. Now it is time to implement the TripTime function definition. * Create the function definition (block of code) below the main function the "value at" totalTimePtr at" hours and "value at" minutes . Inside the function you will need to calculate total time using miles and speed 70MPH store the result in Inside the function vou will also need calculate how many hours and how many minutes stored in "value One way to do the calculation: int HOURS = (int)TOTALTIME //cast the totaltime to an integer to get the number of hours int MINUTES (TOTALTIME HOURS) * 60; //subtract the hours from the total time and multiply by 60 to get the number of minutes *build run and test 13. Now it is time to test the TripTime function with a function call 14. Write the statement to call the TripTime function from inside the main function and pass the miles and the "address of" time, "address of" hours, and "address of" minutes to the function 15. Print the results onto the screen from the main function build run and test BEFORE SUBMITTING THE CODE
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C program

#include<stdio.h>
void GasCost(double miles , double *gasTotalPtr);
void TripTime(double miles , double *totalTimePtr , int*hoursPtr ,int *minutePtr);

int main(){
   printf("********Welcome to converter***********\n\n");
   double miles , gas , time;
   int hours,minutes;
  
   printf("Enter mile to drive : ");
   scanf("%lf",&miles);
   GasCost (miles , &gas);
   TripTime(miles , &time,&hours,&minutes);
  
   printf("\nGas Cost : %lf\n",gas);
   printf("Total time : %lf\n",time);
   printf("Time : %d hour %d minutes\n",hours,minutes);
   return 0;
}

void GasCost(double miles , double *gasTotalPtr){
   double cpg,mpg;
   printf("Enter cost per gallon : ");
   scanf("%lf",&cpg);
   printf("Enter mile per gallon : ");
   scanf("%lf",&mpg);
  
   *gasTotalPtr = (miles/mpg)*cpg;
  
}
void TripTime(double miles , double *totalTimePtr , int*hoursPtr ,int *minutePtr){
   *totalTimePtr = miles/70;
   *hoursPtr = (int)*totalTimePtr;
   *minutePtr = (*totalTimePtr-*hoursPtr)*60;
}

//sample output

C:\Users\IshuManish\Documents gascost.exe 4/elcome to converter Enter mile to drive 105 Enter cost per grallon 30 Enter mile

Add a comment
Know the answer?
Add Answer to:
//Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS ...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE...

    Must Follow Example code //Add name, date, and description here //preprocessor directives #de fine CRT SECURE NO WARNINGS #includestdio.h> - //Calculate the cost of the gas on a trip /Ideclare, ask, and get the price per gallon and the mpg /Icalculate and return (by reference) the cost of gas for the number of miles passed to the function void GasCost (double miles, double *gasTotalPtr) //using a 70 MPH speed limit and the miles passed to the function //calculate and return...

  • // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter...

    // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter your class section, and time /* The program TripCost.cpp uses pointers to calculate    the cost of a trip depending on the cost of a gallon    of gas, the number of miles, and the number of miles    per gallon a car gets. */ /* The cost of gas, the number of miles, and number of    miles per gallon is entered. */...

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

  • In C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • please help me add on this java code to run public class CarHwMain public static void...

    please help me add on this java code to run public class CarHwMain public static void main(String args 1/ Construct two new cars and one used car for the simulation Cari carl = new Car W"My New Mazda", 24.5, 16.0); Car car2 = new Cart My New Ford" 20.5, 15.0) Cari car) - new Cari ("My Used Caddie", 15.5, 16.5, 5.5, 1/ ADD CODE to completely fill the tanks in the new cars and off the used cars ton //...

  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT