Hi. I made a code but I have to change it. These are the requirements for the program code • Safe entry • No magic numbers • No global variables • File management must be in a separate c-file - I HAVEN'T DONE THIS AND I NEED HELP • All standard header files, type declarations, function prototypes etc. must be included a custom header file - I HAVEN'T DONE THIS EITHER • Functions must not be “too long and when the user chooses to quit "exit", the register must be written to a file - i haven't done this So basically I need to change the code so that it fits the requirements #include #include #include #include #define STR_LANGD 30 #define VEHICLE 10 #define NUMBEROF_PEOPLE 10 typedef struct { char name[STR_LANGD]; int age; } Person; typedef struct { Person person; char model[STR_LANGD]; char carbrand[STR_LANGD]; char registrationnumber[STR_LANGD]; } Vehicle; void initVehicle(Vehicle myVehicle[]) { int i; for (i = 0; i < VEHICLE; i++) { myVehicle[i].person.age = 0; } } int menu() { int choice = 0; printf ("1. Add a vehicle. \n"); printf ("2. Remove a vehicle \n"); printf ("3. Sort by car brand. \n"); printf ("4. Print vehicle information.\n"); printf ("5. Print the entire vehicle register. \n"); printf ("0. Exit. \n"); scanf("%d", &choice); return choice; } void AddVehicle(Vehicle myVehicle[]) { Vehicle temp; int i; fflush(stdin); printf("Enter name: \n"); scanf("%s", temp.person.name); printf("Enter personens ålder: \n"); scanf("%d", &temp.person.age); printf("Enter Vehiclestyp: \n"); scanf("%s", temp.model); printf("Enter car brand: \n"); scanf("%s", temp.carbrand); printf("Enter registration number: "); scanf("%s", temp.registrationnumber); for (i = 0; i < VEHICLE; i++) { if (myVehicle[i].person.age == 0) { myVehicle[i] = temp; break; } } } void showVehicle(Vehicle myVehicle[]) { int i; printf("\nAll vehicle in database\n"); printf("-------------------\n"); for (i = 0; i < VEHICLE; i++) { if (myVehicle[i].person.age != 0) { printf("Place: %d\n", i); printf("Name: "); puts(myVehicle[i].person.name); printf("Ålder på ägaren: %d\n", myVehicle[i].person.age); printf("Car model: %s\n", myVehicle[i].model); printf("Car brand: %s\n", myVehicle[i].carbrand); printf("Registration number: %s\n\n", myVehicle[i].registrationnumber); } } } void DeleteVehicle(Vehicle myVehicle[VEHICLE]) { int temp; printf("På vilken plats (0-10) vill du ta bort Vehicleinfo?\nPlats: "); scanf("%d", &temp); if (myVehicle[temp].person.age != 0) { myVehicle[temp].person.age = 0; } } void printinfo(Vehicle myVehicle[VEHICLE]) { int temp; printf("På vilken plats (0-10) vill du se Vehicleinfo?\nPlats: "); scanf("%d", &temp); if (myVehicle[temp].person.age != 0) { printf("\n------------Vehicleinfo-----------\n"); printf("Plats: %d", temp); printf("name: %s\n", myVehicle[temp].person.name); printf("Ålder på ägaren: %d\n", myVehicle[temp].person.age); printf("Car model: %s\n", myVehicle[temp].model); printf("Car brand: %s\n", myVehicle[temp].carbrand); printf("Registration number: %s\n", myVehicle[temp].registrationnumber); } } void carSort(Vehicle myVehicle[VEHICLE]) { int i; int j; Vehicle temp; for (i = 1; i < VEHICLE; i++) { for (j = 0; j < VEHICLE - i; j++) { if (myVehicle[j].carbrand[0] > myVehicle[j+1].carbrand[0]) { temp = myVehicle[j]; myVehicle[j] = myVehicle[j+1]; myVehicle[j+1] = temp; } } } } int main() //main: här startar alla C-program { Vehicle myVehicle[VEHICLE]; int menuchoice = 0; initVehicle(myVehicle); do { menuchoice = menu(); switch (menuchoice) { case 1: AddVehicle(myVehicle); break; case 2: DeleteVehicle(myVehicle); break; case 3: carSort(myVehicle); break; case 4: printinfo(myVehicle); break; case 5: showVehicle(myVehicle); break; default: break; } } while (menuchoice !=0); return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi. I made a code but I have to change it. These are the requirements for the program code
• Safe entry
• No magic numbers
• No global variables
• File management must be in a separate c-file - I HAVEN'T DONE THIS AND I NEED HELP
• All standard header files, type declarations, function prototypes etc. must be included
a custom header file - I HAVEN'T DONE THIS EITHER
• Functions must not be “too long

and when the user chooses to quit "exit", the register must be written to a file - i haven't done this

So basically I need to change the code so that it fits the requirements

#include

#include

#include

#include

#define STR_LANGD 30

#define VEHICLE 10

#define NUMBEROF_PEOPLE 10

typedef struct

{

char name[STR_LANGD];

int age;

}

Person;

typedef struct

{

Person person;

char model[STR_LANGD];

char carbrand[STR_LANGD];

char registrationnumber[STR_LANGD];

}

Vehicle;

void initVehicle(Vehicle myVehicle[])

{

int i;

for (i = 0; i < VEHICLE; i++)

{

myVehicle[i].person.age = 0;

}

}

int menu() {

int choice = 0;

printf ("1. Add a vehicle. \n");

printf ("2. Remove a vehicle \n");

printf ("3. Sort by car brand. \n");

printf ("4. Print vehicle information.\n");

printf ("5. Print the entire vehicle register. \n");

printf ("0. Exit. \n");

scanf("%d", &choice);

return choice;

}

void AddVehicle(Vehicle myVehicle[])

{

Vehicle temp;

int i;

fflush(stdin);

printf("Enter name: \n");

scanf("%s", temp.person.name);

printf("Enter personens ålder: \n");

scanf("%d", &temp.person.age);

printf("Enter Vehiclestyp: \n");

scanf("%s", temp.model);

printf("Enter car brand: \n");

scanf("%s", temp.carbrand);

printf("Enter registration number: ");

scanf("%s", temp.registrationnumber);

for (i = 0; i < VEHICLE; i++)

{

if (myVehicle[i].person.age == 0)

{

myVehicle[i] = temp;

break;

}

}

}

void showVehicle(Vehicle myVehicle[])

{

int i;

printf("\nAll vehicle in database\n");

printf("-------------------\n");

for (i = 0; i < VEHICLE; i++)

{

if (myVehicle[i].person.age != 0)

{

printf("Place: %d\n", i);

printf("Name: ");

puts(myVehicle[i].person.name);

printf("Ålder på ägaren: %d\n", myVehicle[i].person.age);

printf("Car model: %s\n", myVehicle[i].model);

printf("Car brand: %s\n", myVehicle[i].carbrand);

printf("Registration number: %s\n\n", myVehicle[i].registrationnumber);

}

}

}

void DeleteVehicle(Vehicle myVehicle[VEHICLE])

{

int temp;

printf("På vilken plats (0-10) vill du ta bort Vehicleinfo?\nPlats: ");

scanf("%d", &temp);

if (myVehicle[temp].person.age != 0)

{

myVehicle[temp].person.age = 0;

}

}

void printinfo(Vehicle myVehicle[VEHICLE])

{

int temp;

printf("På vilken plats (0-10) vill du se Vehicleinfo?\nPlats: ");

scanf("%d", &temp);

if (myVehicle[temp].person.age != 0)

{

printf("\n------------Vehicleinfo-----------\n");

printf("Plats: %d", temp);

printf("name: %s\n", myVehicle[temp].person.name);

printf("Ålder på ägaren: %d\n", myVehicle[temp].person.age);

printf("Car model: %s\n", myVehicle[temp].model);

printf("Car brand: %s\n", myVehicle[temp].carbrand);

printf("Registration number: %s\n", myVehicle[temp].registrationnumber);

}

}

void carSort(Vehicle myVehicle[VEHICLE])

{

int i;

int j;

Vehicle temp;

for (i = 1; i < VEHICLE; i++)

{

for (j = 0; j < VEHICLE - i; j++)

{

if (myVehicle[j].carbrand[0] > myVehicle[j+1].carbrand[0])

{

temp = myVehicle[j];

myVehicle[j] = myVehicle[j+1];

myVehicle[j+1] = temp;

}

}

}

}

int main() //main: här startar alla C-program

{

Vehicle myVehicle[VEHICLE];

int menuchoice = 0;

initVehicle(myVehicle);

do

{

menuchoice = menu();

switch (menuchoice)

{

case 1: AddVehicle(myVehicle); break;

case 2: DeleteVehicle(myVehicle); break;

case 3: carSort(myVehicle); break;

case 4: printinfo(myVehicle); break;

case 5: showVehicle(myVehicle); break;

default: break;

}

}

while (menuchoice !=0);

return 0;

}

 
Expert Solution
steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education