7.6 LAB*: Program: Fancy car
I AM POSTING THIS AGAIN!!! C CODE ONLY!!!! NO PYTHON OR C++ JUST C.
Program Specifications Write a program that uses a struct to support basic operations such as drive, add gas, honk horn and start engine. FancyCar.h declares the FancyCar_Struct and the functions necessary to complete the exercise. FancyCar.c provides the function stubs. Follow each step to gradually complete all functions in FancyCar.c.
Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() function includes an example to be used for development. Add statements in main() as functions are completed to support development mode testing.
Step 0. Declare data members for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (char[]). Note the provided constant variable in FancyCar.c indicates the gas tank capacity of 14.0 gallons.
Step 1 (2 pts). 1) Define InitializeFancyCar() to set the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". InitializeFancyCar() returns the initialized FancyCar struct. 2) Complete functions to check the odometer, check the gas gauge, get the model, and get the miles per gallon. Submit for grading to confirm 1 test passes.
Step 2 (1 pt). Complete the HonkHorn() function to output the car model. If the car model is:
the HonkHorn() function outputs:
Submit for grading to confirm 2 tests pass.
Step 3 (1 pt). Complete the Drive() function. Miles driven should increase by parameter distance, and the amount of gas should decrease by distance / MPG. Data members are only updated if parameter distance is positive. Drive() returns the updated FancyCar struct. Submit for grading to confirm 3 tests pass.
Step 4 (2 pts). Complete the AddGas() function. Increase gas tank by parameter amount only if parameter is positive. Set gas tank to full if too much gas was added. AddGas() returns the updated FancyCar struct. Submit for grading to confirm 4 tests pass.
Step 5 (2 pts). Update the Drive() function to identify if the car runs out of gas. If so, the parameter distance will not be achieved, and the gas tank will have 0.0 gallons. For example, Drive(car, 100) will not be possible with only three gallons of gas and MPG of 20.0. The maximum driving distance is 60 miles with three gallons of gas and MPG of 20.0. Therefore, the odometer will only increase by 60 instead of the requested 100, and the gas tank will have 0.0 gallons (not a negative amount). Submit for grading to confirm 5 tests pass.
Step 6 (2 pts). 1) Add an engine status (int) data member in the FancyCar struct to indicate if the car engine is on or off. 2) Complete the StartEngine() function to set the engine status to 1 and return the updated FancyCar struct. 3) Complete the StopEngine() function to set the engine status to 0 and return the updated FancyCar struct. 4) Update the InitializeFancyCar() function to start with the engine off. 5) Update the Drive() function to only update data members if the engine is on, and the engine turns off if the car runs out of gas. 6) Update the AddGas() function to only add gas if the engine is off. Submit for grading to confirm all tests pass.
LAB ACTIVITY 7.6.1: LAB*: Program: Fancy car 1 #include 2 #include 3 4 #include "FancyCar.h" 5 6 int main(void) { 7 FancyCar car; 8 9 10 11 12 13 14 15 16} char name [100]; strcpy(car.model, "Example"); Current file: main.c GetCarModel (car, name); // Should print: The model of the car is Example // printf("The model of the car is %s.\n", name); return 0; 0/10 Load default template...
7.6 LAB*: Program: Fancy car I AM POSTING THIS AGAIN!!! C CODE ONLY!!!! NO PYTHON OR C++ JUST C. Program Specifications
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am