Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, everyone I have two assignments, I already finished one which requires the input of new entry with spaces. I need someone who can modify

Hi, everyone

I have two assignments, I already finished one which requires the input of new entry with spaces. I need someone who can modify my code the void addEntry(purse list[], int *size) so my program can only prompt the user for an entry without space like EXAMPLE THAT DOES NOT ACCEPT INPUT WITH SPACES (FooFighters or Foo_Fighters)

Here is my code please modify it:

#define _CRT_SECURE_NO_DEPRECATE

#include

#include

#include

#define MAX_ENTRIES 40

typedef struct {

//1-int called id

int id;

//2-char array called name

char make[20];

//3-char array called brand

char model[20];

//4-int called stock

int stock;

//5-double called cost

double cost;

//6-double called price

double price;

} purse;

char menu()

{

char Choice;

printf(" *************************************** ");

printf("Please select from the options below: ");

printf("P - Print entire inventory ");

printf("A - Add a new entry ");

printf("C - Clear all records ");

printf("S - Create a current report(save it to a file) ");

printf("D - Delete an item from the list(inventory) ");

printf("U - Update the price ");

printf("Q - Quit ");

//prompt the user

printf("What would you like to do: ");

scanf(" %c", &Choice);

return Choice;

}

void initializeEntries(purse list[], int *size)

{

list[0].id = 101;

strcpy(list[0].make, "Rolls-Royce");

strcpy(list[0].model, "Ghost");

list[0].stock = 11;

list[0].cost = 120000.00;

list[0].price = 194900.00;

list[1].id = 102;

strcpy(list[1].model, "Mclaren");

strcpy(list[1].make, "P1");

list[1].stock = 5;

list[1].cost = 2000000.00;

list[1].price = 2399900.00;

list[2].id = 103;

strcpy(list[2].make, "Ferrari");

strcpy(list[2].model, "458 Speciale A");

list[2].stock = 7;

list[2].cost = 580000.00;

list[2].price = 649990.00;

list[3].id = 104;

strcpy(list[3].make, "Maserati");

strcpy(list[3].model, "GT Sport");

list[3].stock = 20;

list[3].cost = 100000.00;

list[3].price = 142200.00;

list[4].id = 105;

strcpy(list[4].make, "Lamborghini");

strcpy(list[4].model, "Huracan LP 610");

list[4].stock = 12;

list[4].cost = 220000.00;

list[4].price = 274900.00;

*size = 5;

return;

}

void createReport(purse list[], int *size)

{

//declares pointer

FILE *f;

int i;

//opens text file and add information into the text file

f = fopen("Records.txt", "w");

if (f == NULL)

{

printf("Error opening file! ");

exit(1);

}

if (*size == 0)

fprintf(f, "*****Inventory is empty***** ");

for (i = 0; i<*size; i++)

{

//fprint to check

fprintf(f, "---Inventory Entry %d--- ", i + 1);

fprintf(f, "I.D.#: %d ", list[i].id);

fprintf(f, "MAKE: %s ", list[i].make);

fprintf(f, "MODEL: %s ", list[i].model);

fprintf(f, "QTY: %d ", list[i].stock);

fprintf(f, "COST: $%.2lf ", list[i].cost);

fprintf(f, "PRICE: $%.2lf ", list[i].price);

}

//closes text file

fclose(f);

return;

}

void addEntry(purse list[], int *size)

{

//prompt and get information

printf(" What is this car's I.D. number : ");

scanf("%d", &list[*size].id);

//prompt and get information

printf(" Please enter the Make of the car : ");

scanf("%s", list[*size].make);

//prompt and get information

printf(" Please enter the name of the car : ");

scanf("%s", list[*size].model);

//prompt and get information

printf(" What is this car's quantity : ");

scanf("%d", &list[*size].stock);

//prompt and get information

printf(" How much does this car cost from the manufacturer: ");

scanf("%lf", &list[*size].cost);

//prompt and get information

printf(" How much will you charge for this car: ");

scanf("%lf", &list[*size].price);

//prompt and get information

printf(" Your entry has been added to the catalog");

(*size)++;

return;

}

void display(purse list[], int *size)

{

//Declare variables

int i;

if (*size == 0)printf("*****Dealership's Inventory is empty***** ");

for (i = 0; i<*size; i++)

{

//print to check

printf("---Inventory Entry %d--- ", i + 1);

printf("I.D.#: %d ", list[i].id);

printf("MAKE: %s ", list[i].make);

printf("MODEL: %s ", list[i].model);

printf("QTY: %d ", list[i].stock);

printf("COST: $%.2lf ", list[i].cost);

printf("PRICE: $%.2lf ", list[i].price);

}

return;

}

void deleteEntry(purse list[], int *size)

{

//Declare variables

int i, id;

printf("List of ID #'s: ");

for (i = 0; i<*size; i++)

//print to check

printf("%d ", list[i].id);

printf(" Please enter the I.D.: ");

scanf("%d", &id);

for (i = 0; i<*size; i++)

{

if (list[i].id == id)

{

list[i].id = list[*size - 1].id;

strcpy(list[i].make, list[*size - 1].make);

strcpy(list[i].model, list[*size - 1].model);

list[i].stock = list[*size - 1].stock;

list[i].cost = list[*size - 1].cost;

list[i].price = list[*size - 1].price;

(*size)--;

break;

}

}

return;

}

void clearRecords(purse list[], int *size)

{

*size = 0;

//print the clearing of all entries

printf(" Your Inventory has been cleared of all entries.");

return;

}

location

void update(purse list[], int *size)

{

//Declare variables

int i, id;

double price_up;

printf("List of ID #'s: ");

for (i = 0; i<*size; i++)

printf("%d ", list[i].id);

//prompt and get information

printf(" Please enter the I.D.: ");

scanf("%d", &id);

//for loop

for (i = 0; i<*size; i++)

{

if (list[i].id == id)

{

printf("---Inventory Entry %d--- ", i + 1);

printf("I.D.#: %d ", list[i].id);

printf("MAKE: %s ", list[i].make);

printf("MODEL: %s ", list[i].model);

printf("QTY: %d ", list[i].stock);

printf("COST: $%.2lf ", list[i].cost);

printf("PRICE: $%.2lf ", list[i].price);

printf("Please enter the updated price: ");

scanf("%lf", &price_up);

list[i].price = price_up;

break;

}

}

return;

}

int main()

{

//Declare variables

purse list[MAX_ENTRIES];

int size = 0;

initializeEntries(list, &size);

//Greets the user

printf("Hello and welcome. This program helps you create an inventory for Exotic Car Dealership. ");

printf("To get you started, 5 cars have already been entered. ");

//while loop for selecting menu options

while (1) {

char Choice = menu();

if (Choice == 'A' || Choice == 'a') {

addEntry(list, &size);

}

else if (Choice == 'D' || Choice == 'd') {

deleteEntry(list, &size);

}

else if (Choice == 'P' || Choice == 'p') {

display(list, &size);

}

else if (Choice == 'S' || Choice == 's') {

createReport(list, &size);

}

else if (Choice == 'C' || Choice == 'c') {

clearRecords(list, &size);

}

else if (Choice == 'U' || Choice == 'u') {

update(list, &size);

}

else if (Choice == 'Q' || Choice == 'q') {

printf("Thank you and Goodbye. ");

break;

}

else printf("Enter a valid command ");

}

return 0;

}

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_2

Step: 3

blur-text-image_step3

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

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago