Program needs to be made in C . I prefer if you TYPE it please. So much neater a
ID: 3861966 • Letter: P
Question
Program needs to be made in C. I prefer if you TYPE it please. So much neater and I can understand it that way. Thank you.
Introduction
Arrays are important in all programming languages including C. Here you will gain experience in using many arrays.
Problem description
Excelsior Auto Leasing is a company that leases, but it specializes in used cars at a lower price. Your job is to make a C program that maintains up-to-date information about all the cars in the company’s fleet.
Sample run/Sample data
Welcome to Excelsior Auto Leasing
Choices for commands are:
A = Add: enter another car
Y = Year: view the cars in order by year
M = Make: view the cars in alphabetical order of Make
R = Remove a car
Cntl+D = Quit.
Enter your choice (A,Y,M,R,Cntl+D): A
Enter vin#: 87452
Enter make: Cadillac
Enter model: CTS
Enter year: 2014
Enter fee: 120.00
Enter your choice (A,Y,M,R,Cntl+D): A
Enter vin#: 62183
Enter make: Chevrolet
Enter model: Camero
Enter year: 2012
Enter fee: 145.50
Enter your choice (A,Y,M,R,Cntl+D): A
Enter vin#: 04381
Enter make: Toyota
Enter model: Camry
Enter year: 2016
Enter fee: 95.90
Enter your choice (A,Y,M,R,Cntl+D): Y
VIN Make Model Year Fee
62183 Chevrolet Camero 2012 145.50
87452 Cadillac CTS 2014 120.00
04381 Toyota Camry 2016 95.90
Enter your choice (A,Y,M,R,Cntl+D): A
Enter vin#: 43564
Enter make: Ford
Enter model: Explorer
Enter year: 2013
Enter fee: 90.45
Enter your choice (A,Y,M,R,Cntl+D): Y
VIN Make Model Year Fee
62183 Chevrolet Camero 2012 145.50
43564 Ford Explorer 2013 90.45
87452 Cadillac CTS 2014 120.00
04381 Toyota Camry 2016 95.90
Enter your choice (A,Y,M,R,Cntl+D): M
VIN Make Model Year Fee
87452 Cadillac CTS 2014 120.00
62183 Chevrolet Camero 2012 145.50
43564 Ford Explorer 2013 90.45
04381 Toyota Camry 2016 95.90
Enter your choice (A,Y,M,R,Cntl+D): R
Enter VIN #: 43564
Enter your choice (A,Y,M,R,Cntl+D): Y
VIN Make Model Year Fee
62183 Chevrolet Camero 2012 145.50
87452 Cadillac CTS 2014 120.00
04381 Toyota Camry 2016 95.90
Enter your choice (A,Y,M,R,Cntl+D): R
Enter VIN #: 22222
No such vehicle.
Enter your choice (A,Y,M,R,Cntl+D):
Have a nice day. Bye.
Arrays needed
Use a two-dimensional array of char to store Makes (manufacturers), and another two-dimensional array of char to store Models.
Use an integer array for Vin and another integer array for year.
Use an array of doubles for the leasing fee.
Declare the 3 numeric arrays using malloc. This is a very common way of declaring arrays in C, and now it is time to practice it. Here is an interesting exercise: try to declare the 2 char arrays using malloc.
Make these functions.
1. A function that prompts for the five inputs and returns all five to the caller, and the caller places them into their respective arrays.
2. A sorting function to sort according to Year. Notice that the sort function has manage all five arrays while sorting.
3. A sorting function to sort according to Make. Again the function has to manage all five arrays.
4. A function that displays the rows of data in justified columns. For example, if the arrays hold data for four cars then this function will output something like the following.
VIN Make Model Year Fee
87452 Cadillac CTS 2008 120.00
62183 Chevrolet Camero 2001 145.50
43564 Ford Explorer 1999 90.45
04381 Toyota Camry 2010 95.90
5. A function that returns the index number of a specific vin number that is provided to the function as a parameter. This function finds the location where a given vin number is located. If the function searches for a vin that does not exist then make the function return an integer that is out of bounds
Put each function in its own file. This is what you did in Assignment 1.
Test data
Real VINs contain about 20 digits. For purposes of this program we will pretend that the VINs contain only 5 digits.
To test your program I suggest you use the data in the sample run. When you send me your program I will use data very similar to the sample run.
No error checking is required, but you are welcome to add error check after you finish the program. For example, there cannot exist two cars with the same VIN number. You could check to make sure this doesn’t happen
Explanation / Answer
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
static int i=0;
int *sortAboutYear(int *yearArray);
int giveIndexOfAnyVin(int vin);
int removeCar(int *vinArray,char *makesArray);
int main() {
int vin,year;
double fee;
char str[20];
char makes[100][200]; /* here i used two-dimensional array of char to store Makes (manufacturers), and another two-dimensional array of char to store Models*/
char models[100][200];
double *fee_array;
int *vin_array;
int *year_array;
/* here i dynamically create two integer array and one double array */
vin_array = (int*) malloc(100 * sizeof(int));
year_array = (int*) malloc(100 * sizeof(int));
fee_array = (double*) malloc(100 * sizeof(double));
while(1)
{
printf(" enter your choice ");
scanf("%s",&str);
if(strcmp("A",str) == 0)
{
printf("Add : Enter another car ");
printf("Enter VIN#");
scanf("%d ",&vin);
vin_array[i]=vin;
printf("enter make");
scanf("%s ",&makes[i]);
printf("enter model");
scanf("%s ",&models[i]);
printf("enter year");
scanf("%d ",&year);
year_array[i]=year;
printf("enter fee");
scanf("%lf",&fee);
fee_array[i]=fee;
i=i+1;
}
if(strcmp("Y",str)== 0)
{
int *temp_arr;
int len=(int)( sizeof(year_array) / sizeof(year_array[0]));
temp_arr= sortAboutYear(year_array);
for(int i=0;i<len;i++)
{
printf("%d" "" "%s" "%s" "%d" "" "%lf",vin_array[*(temp_arr+i)],makes[*(temp_arr+i)],models[*(temp_arr+i)],year_array[*(temp_arr+i)],fee_array[*(temp_arr+i));
}
}
if(strcmp("Cntl+D",str)== 0)
{
printf("Quit ");
break;
}
i=i+1;
}
return 0;
}
int* sortAboutYear(int *yearArray)
{
int i,j;
int temp_arr[50];
int t;
int len=(int)( sizeof(yearArray) / sizeof(yearArray[0]));
for(i = 0; i < len; i++) {
for(j = 0; j < len-i-1; j++) {
if(yearArray[j] > yearArray[j+1]) {
/* Swap inputArray[j] and inputArray[j+1] */
t = yearArray[j];
yearArray[j] = yearArray[j+1];
yearArray[j+1] = t;
}
temp_arr[i]=j;
}
}
return temp_arr;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.