Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is a code I made but I want someone to do some modifications on it where I get the same solution but different code.

this is a code I made but I want someone to do some modifications on it where I get the same solution but different code. thank you so much

 #include #include #define SIZE 30 #define PHONE_SIZE 12 void serachCustomer(char search[],int type); int main() { int choice; char customer_name[SIZE], phone[PHONE_SIZE], id[SIZE],make[SIZE],search[SIZE],model_name[SIZE],model_year[SIZE],plate_number[SIZE],new_id[SIZE]; int repeat = 1; FILE* fPtr,*rPtr, *wPtr; do { printf("**** Car Rental Application **** "); printf("1- Customer "); printf("2- Vehicles "); printf("3- Exit "); printf(">>Enter your choice:"); scanf_s("%d", &choice); switch (choice) { case 1: printf("1- Register / add new customers "); printf("2- Search customer "); printf("3- Back "); printf(">>Enter your choice:"); scanf_s("%d", &choice); switch (choice) { case 1: fopen_s(&fPtr, "Customer.txt", "a"); printf("Enter customer ID: "); scanf_s("%s", id, SIZE-1); printf("Enter customer name : "); scanf_s("%s", customer_name, SIZE-1); printf("Enter phone number: "); scanf_s("%s", phone, PHONE_SIZE-1); fprintf(fPtr, "%s%25s%20s ", id,customer_name,phone); fclose(fPtr); break; case 2: printf("1- Search by ID "); printf("2- Search by Name "); printf("3- Search by phone "); printf("4- Back "); printf(">>Enter your choice:"); scanf_s("%d", &choice); switch (choice) { case 1: printf("Please enter ID to serach:"); scanf_s("%s", &search, SIZE); serachCustomer(search,1); break; case 2: printf("Please enter customer name to serach:"); scanf_s("%s", &search, SIZE); serachCustomer(search,2); break; case 3: printf("Please enter phone to serach:"); scanf_s("%s", search, SIZE); serachCustomer(search,3); break; case 4: break; default: break; } break; default: break; } break; case 2: printf("1- Add a new vehicle "); printf("2- Delete vehicle "); printf("3- Rent a vehicle to a customer "); printf("4- Receive rented vehicle back from customer "); printf("5- Search vehicle : "); printf("6- Back : "); printf(">>Enter your choice:"); scanf_s("%d", &choice); switch (choice) { case 1: fopen_s(&fPtr, "vehicle.txt", "a"); printf("Enter mdole year: "); scanf_s("%s", model_year,SIZE); printf("Enter make : "); scanf_s("%s", make, SIZE); printf("Enter model name: "); scanf_s("%s", model_name, SIZE); printf("Enter plate number: "); scanf_s("%s", plate_number,SIZE); printf("Enter customer ID number: "); scanf_s("%s", id,SIZE); fprintf(fPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number,id); fclose(fPtr); break; case 2: fopen_s(&rPtr, "vehicle.txt", "r"); fopen_s(&wPtr, "temp.txt", "w"); printf("Please enter car plat number to delete:"); // 157 scanf_s("%s", search,SIZE); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year,SIZE, make,SIZE, model_name,SIZE, plate_number,SIZE, id,SIZE); if (memcmp(plate_number, search, strlen(search))) { fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(rPtr); fclose(wPtr); fopen_s(&wPtr, "vehicle.txt", "w"); fopen_s(&rPtr, "temp.txt", "r"); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } fclose(rPtr); fclose(wPtr); break; case 3: fopen_s(&rPtr, "vehicle.txt", "r"); fopen_s(&wPtr, "temp.txt", "w"); printf("Please enter car plat number :"); scanf_s("%s", search, SIZE); printf("Please enter customer ID number :"); scanf_s("%s", new_id, SIZE); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); if (!memcmp(plate_number, search, strlen(search))) { fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, new_id); } else { fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(rPtr); fclose(wPtr); fopen_s(&wPtr, "vehicle.txt", "w"); fopen_s(&rPtr, "temp.txt", "r"); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } fclose(rPtr); fclose(wPtr); break; case 4: fopen_s(&rPtr, "vehicle.txt", "r"); fopen_s(&wPtr, "temp.txt", "w"); printf("Please enter car plat number :"); scanf_s("%s", search, SIZE); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); if (!memcmp(plate_number, search, strlen(search))) { fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, "0"); } else { fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(rPtr); fclose(wPtr); fopen_s(&wPtr, "vehicle.txt", "w"); fopen_s(&rPtr, "temp.txt", "r"); while (!feof(rPtr)) { fscanf_s(rPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); fprintf(wPtr, "%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } fclose(rPtr); fclose(wPtr); break; case 5: printf("1- Search by Model year + Make + Model name "); printf("2- Search by License plate number "); printf("3- Search for renting vehicle "); printf("4- Back "); printf(">>Enter your choice:"); scanf_s("%d", &choice); switch (choice) { case 1: char model_search[SIZE], make_search[SIZE], model_name_search[SIZE]; printf("Please enter Model year , Make and Model name to serach:"); scanf_s("%s", &model_search, SIZE); scanf_s("%s", &make_search, SIZE); scanf_s("%s", &model_name_search, SIZE); fopen_s(&fPtr, "vehicle.txt", "r"); while (!feof(fPtr)) { fscanf_s(fPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); if ((!memcmp(model_year, model_search, strlen(model_search)))&&(!memcmp(make, make_search, strlen(make_search)))&&(!memcmp(model_name, model_name_search, strlen(model_name_search))) ) { printf("%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(fPtr); break; case 2: printf("Please enter License plate number to serach:"); scanf_s("%s", &search, SIZE); fopen_s(&fPtr, "vehicle.txt", "r"); while (!feof(fPtr)) { fscanf_s(fPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); if ( (!memcmp(plate_number, search, strlen(search)))) { printf("%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(fPtr); break; case 3: fopen_s(&fPtr, "vehicle.txt", "r"); while (!feof(fPtr)) { fscanf_s(fPtr, "%s%s%s%s%s ", model_year, SIZE, make, SIZE, model_name, SIZE, plate_number, SIZE, id, SIZE); if ((memcmp(id, "0", strlen("0")))) { printf("%s%10s%10s%10s%10s ", model_year, make, model_name, plate_number, id); } } fclose(fPtr); break; case 4: break; default: break; } break; case 6: break; default: break; } break; case 3: repeat = 0; break; } } while (repeat); } void serachCustomer(char search[],int type) { char id[SIZE], customer_name[SIZE], phone[PHONE_SIZE]; FILE* fPtr; fopen_s(&fPtr, "Customer.txt", "r"); while (!feof(fPtr)) { fscanf_s(fPtr, "%s%s%s", id, SIZE, customer_name, SIZE, phone, PHONE_SIZE); if (type==1&&!memcmp(id, search, strlen(search))) { printf("%s%13s%13s ", id, customer_name, phone); } else if (type == 2 && !memcmp(customer_name, search, strlen(search))) { printf("%s%13s%13s ", id, customer_name, phone); } else if (type == 3 && !memcmp(phone, search, strlen(search))) { printf("%s%13s%13s ", id, customer_name, phone); } } fclose(fPtr); }

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

Students also viewed these Programming questions

Question

Communication; Use of IT; Reflective thinking)

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago