Please answer the questions correctly and show clear workings . Show the appropr
ID: 3878742 • Letter: P
Question
Please answer the questions correctly and show clear workings . Show the appropriate code and then the result that it works on your screen. THE COLNSOLE OUTPUT IS GIVEN IN THE PICTURE. The program must be in C LANGUAGE. And PLEASE DO NOT USE #include<Conio.h> i.e no using get function. Customer Information Storage for an Automotive Mechanic Business Instructions In this assignment you will create a small program which could be used by an automotive mechanic business to keep track of their customers and their vehicles. You will begin with the skeleton code posted in cuLean. Your program must use the provided skeleton code without making any changes to the existing code, data structures or function prototypes. You will, however, add your own code to it. Below are the requirements for your program. Note: all strings described in this assignment will be declared to have a length of MAX STR. 1. Defined structures This program makes use of two structures that need to be completed. The first is the VehicleType structure. This structure will contain all of the data for each car owned by the customers. This structure will have fields for the following pieces of data make (string) e model (string) colour (string) year (int) mileage (int) . The second structure (CustomerType) will contain all of the data regarding the individual customers. It will have the following fields first name (string) last name (string) number of vehicles registered with the shop (int) a VehicleType array storing the individual vehicles owned by the customer (declared to have a length of MAX VEHICLESExplanation / Answer
#include <stdio.h>
#include <string.h>
#define MAX_STR 32
#define MAX_VEHICLES 4
#define MAX_CUSTOMERS 6
typedef struct
{
char make[MAX_STR];
char model[MAX_STR];
char colour[MAX_STR];
int year;
int mileage;
} VehicleType;
typedef struct
{
char fname[MAX_STR];
char lname[MAX_STR];
int numVehicle;
VehicleType *vehicle[MAX_VEHICLES];
} CustomerType;
void print_vehicle (VehicleType *v)
{
printf ("%d %s %s, %s, %dKM ", v->year, v->make, v->model, v->colour, v->mileage);
}
void print_customer (CustomerType *c)
{
int i = 0;
printf ("%s %s, %d vehicle(s) ", c->fname, c->lname, c->numVehicle);
for (i=0; i<c->numVehicle; i++)
{
print_vehicle (c->vehicle[i]);
}
}
/*In problem description it is mentioned that the return type is either 0 or -1*/
int add_vehicle (CustomerType *customer, VehicleType *vehicle)
{
int i ;
if (customer->numVehicle >= MAX_VEHICLES)
{
return -1;
}
else
{
i = customer->numVehicle;
customer->vehicle[i] = vehicle;
customer->numVehicle++;
return 0;
}
}
CustomerType create_customer (char *fname, char *lname)
{
CustomerType c = {0};
strcpy (c.fname, fname);
strcpy (c.lname, lname);
c.numVehicle = 0;
return c;
}
VehicleType create_vehicle (char *make, char *model, char * colour, int year, int mileage)
{
VehicleType v = {0};
strcpy (v.make, make);
strcpy (v.model, model);
strcpy (v.colour, colour);
v.year = year;
v.mileage = mileage;
return v;
}
int main ()
{
CustomerType customer[MAX_CUSTOMERS];
VehicleType vehicle[MAX_VEHICLES] = {0};
/*Customer 1*/
customer[0] = create_customer ("Maurice", "Mooney");
vehicle[0] = create_vehicle ("Ford","Fiesta", "Red", 2007, 100000);
add_vehicle (&customer[0], &vehicle[0]);
print_customer (&customer[0]);
memset (&vehicle[0], '', sizeof (vehicle[0]));
printf (" ");
/*Customer 2*/
customer[1] = create_customer ("Abigail", "Atwood");
vehicle[0] = create_vehicle ("Subaru","Forester", "Green", 2016, 40000);
add_vehicle (&customer[1], &vehicle[0]);
print_customer (&customer[1]);
memset (&vehicle[0], '', sizeof (vehicle[0]));
printf (" ");
/*Customer 3*/
customer[2] = create_customer ("Brook", "Banding");
vehicle[0] = create_vehicle ("Honda","Accord", "White", 2018, 5000);
add_vehicle (&customer[2], &vehicle[0]);
vehicle[1] = create_vehicle ("Volkswagen","Beetle", "White", 1972, 5000);
add_vehicle (&customer[2], &vehicle[1]);
print_customer (&customer[2]);
memset (&vehicle[0], '', sizeof (vehicle[0]));
memset (&vehicle[1], '', sizeof (vehicle[1]));
printf (" ");
/*Customer 4*/
customer[3] = create_customer ("Eva", "Engram");
vehicle[0] = create_vehicle ("Toyota","Corolla", "Green", 2013, 80000);
add_vehicle (&customer[3], &vehicle[0]);
vehicle[1] = create_vehicle ("Toyota","Rav4", "Gold", 2015, 20000);
add_vehicle (&customer[3], &vehicle[1]);
vehicle[2] = create_vehicle ("Toyota","Prius", "Blue", 2017, 10000);
add_vehicle (&customer[3], &vehicle[2]);
print_customer (&customer[3]);
memset (&vehicle[0], '', sizeof (vehicle[0]));
memset (&vehicle[1], '', sizeof (vehicle[1]));
memset (&vehicle[2], '', sizeof (vehicle[2]));
printf (" ");
/*Similarly you can add the other customers also*/
return 0;
}
OUTPUT:
Maurice Mooney, 1 vehicle(s)
2007 Ford Fiesta, Red, 100000KM
Abigail Atwood, 1 vehicle(s)
2016 Subaru Forester, Green, 40000KM
Brook Banding, 2 vehicle(s)
2018 Honda Accord, White, 5000KM
1972 Volkswagen Beetle, White, 5000KM
Eva Engram, 3 vehicle(s)
2013 Toyota Corolla, Green, 80000KM
2015 Toyota Rav4, Gold, 20000KM
2017 Toyota Prius, Blue, 10000KM