Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with Structures in C!! Do the TODO Parts in the files please! There is 3 different files Car.c, Car.h, and main.c Please Copy and

Help with Structures in C!!

image text in transcribed

image text in transcribed

Do the TODO Parts in the files please! There is 3 different files Car.c, Car.h, and main.c

Please Copy and paste your output so I know its correct!

Thanks!

HERE IS THE CODE:

/** * Including C libraries */ #include #include

/** * Including function prototypes */ #include Car.h

/** * Definition of constants */ #define INDEX_OF_DOM 6 #define CURRENT_YEAR 2017 #define SUPER_NEW_YEAR 2 #define NEW_YEAR 6

/** * Prints brand, model and the date * of manufacture of Car to stdout. * * Argument: * argCar -- Car to read information from. * * Return: * none. */ void print( Car argCar ) { //TODO }

/** * Prints The logo of Car struct to stdout * and adds a space at end too. * * Argument: * argCar -- Car to read information from. * * Return: * none. */ void printLogo( Car argCar ) { //Getting the first letter of the brand and the model //Hint: think string as array of characters. //TODO }

/** * Calculates the age of Car by subtracting * the current year ( 2017 ) from the Cars * year of manufacture. * * Argument: * argCar -- Car to read information from. * * Return: * The age of Car passed in as argument. */ int calculateAge( Car argCar ) { //Getting the year of manufacture only //Hint: think string as array of characters. //TODO }

/** * Checks if Car is super new, new or old * depending on whether it was manufactured * within 2 years, 6 years or earlier * Argument: * argCar -- Car to read information from. * * Return: * 2 if Car is super new. 1 if new. * 0 if old. */ int isNew( Car argCar ); //TODO }

/** * Addind C Standard library */ #include #include

/** * Adding local header files */ #include Car.h

/** * Definition of constants */ #define NUM_ARGS 4

/** * Main method to make a Car struct, populate it and * call helper methods to print Car information. * * Arguments: * argc -- Holds the number of command line * arguments passed. * argv -- Holds each command line argument as * char string. * * Error: * If we don't pass in 3 command line arguments, write an error to stderr * and terminate the program * * Return: * EXIT_FAILURE upon hitting an error. EXIT_SUCCESS on successful program run. */ int main( int argc, char* argv[] ) { //Checks if we pass in 3 arguments if( /* TODO */ ) { fprintf( stderr, "Program only accepts 3 command line arguments. " ); return EXIT_FAILURE; }

//Make and populate Car struct from command line arguments Car myCar = //TODO

//Print Cars logo followed by Cars information

//TODO: logo first

printf( "Information: " );

//then print Cars information: //Print brand and model followed by whether the Car is a super new, new or old. //TODO

return EXIT_SUCCESS; }

#ifndef CAR_H #define CAR_H

//defining string of char as string typedef char* string;

/** * Making struct Car with 3 members. * brand, model and date of manufacture. * * Assume valid brand, make and date of manufacture * when making a struct Car */ struct Car { //TODO }; //defining struct Car as Car typedef struct Car Car;

/** * Prints brand, model and the date * of manufacture of Car to stdout. * * Argument: * argCar -- Car to read information from. * * Return: * none. */ void print( Car argCar );

/** * Prints The logo of Car struct to stdout * and adds a space at end too. * * Argument: * argCar -- Car to read information from. * * Return: * none. */ void printLogo( Car argCar );

/** * Calculates the age of Car by subtracting * the current year ( 2017 ) from the Cars * year of manufacture. * * Argument: * argCar -- Car to read information from. * * Return: * The age of Car passed in as argument. */ int calculateAge( Car argCar );

/** * Checks if Car is super new, new or old * depending on whether it was manufactured * within 2 years, 6 years or earlier * Argument: * argCar -- Car to read information from. * * Return: * 2 if Car is super new. 1 if new. * 0 otherwise. */ int isNew( Car argCar );

#endif //CAR_H

Car struct is simple. You will have 3 members that will hold 3 different facts about a car: Brand, Model and Date of manufacture (format: mm/dd/yyyy). Then you will manipulate the Car struct inside your main method to fill the struct members off of command line arguments passed in then print information about the said Car Here are the steps that your main should take: 1. Check if3 arguments have been passed in. If less or more than 3 arguments have been passed in, then print an error into stderr (already provided) and exit the program. Otherwise, go to step 2. 2. Make a Car struct called myCar and populate its members with the arguments passed in through command line. 3. Print the car's logo (it is formed from the first letter of the brand and first letter from the model, separated and terminated by using a function from Car.c 4. Print the car's information (brand, model and date of manufacture) using a function from Car.c 5. Print the car's full name (brand followed by model) followed by a statement declaring whether this car is old, new or super new. (A car is super new if it was manufactured anytime in the past 2 years, it is new if it was manufactured anytime in the past 6 years and is old if it was manufactured anytime before that). See the sample outputs below for better understanding of the requirements

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

sk management cybersecurity risks

Answered: 1 week ago