Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- typedef struct Car{
- char Mark[10];
- int ID, model, mileage, currentREPAIRS, archiveREPAIRS;
- } Car[30];
- typedef struct Service {
- char FULLname[20];
- int ID, repairTIMES, SERVICEhistory;
- } Service[30][10];
- struct Car *p[30];
- struct Service *r[30][10];
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void add(int n, int z, int *T)
- {
- int e=0;
- p[n-1] = malloc(sizeof(Car));
- char CID[10], mark[10], model[10], mileage[10], rep[10], archive[10], RID[10], name[10], reptime[10], history[10], amount[10];
- printf("What is car ID?\n");
- fgets(CID, sizeof(CID), stdin);
- p[n-1] -> ID = atoi(CID);
- fflush(stdin);
- printf("What is car Mark?\n");
- scanf("%s", p[n-1] -> Mark);
- fflush(stdin);
- printf("What is car Model?\n");
- fgets(model, sizeof(model), stdin);
- p[n-1] -> model = atoi(model);
- fflush(stdin);
- printf("What is car Mileage?\n");
- fgets(mileage, sizeof(mileage), stdin);
- p[n-1] -> mileage = atoi(mileage);
- fflush(stdin);
- printf("What is car CurrReapir?\n");
- fgets(rep, sizeof(rep), stdin);
- p[n-1] -> currentREPAIRS = atoi(rep);
- fflush(stdin);
- printf("How many repiars did it have?\n");
- fgets(amount, sizeof(amount),stdin);
- printf("What is car AoRepairs?\n");
- fgets(archive, sizeof(archive), stdin);
- T[n-1]= atoi(amount);
- p[n-1] -> archiveREPAIRS = atoi(archive);
- fflush(stdin);
- for(e=0; e<T[n-1]; e++)
- {
- r[n-1][e] = malloc(sizeof(Service));
- r[n-1][e] = malloc(sizeof(Service));
- printf("What is repair ID?\n");
- fgets(RID, sizeof(RID), stdin);
- r[n-1][e] -> ID = atoi(RID);
- fflush(stdin);
- printf("What is repair name?\n");
- scanf("%s", r[n-1][e] -> FULLname);
- fflush(stdin);
- printf("What is repair RepTime?\n");
- fgets(reptime, sizeof(reptime), stdin);
- r[n-1][e] -> repairTIMES = atoi(reptime);
- fflush(stdin);
- printf("What is repair History?\n");
- fgets(history, sizeof(history), stdin);
- r[n-1][e] -> SERVICEhistory = atoi(history);
- fflush(stdin);
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void deleting(int n, int *T)
- {
- char help[10];
- int i=0, e=0;
- p[n] = malloc(sizeof(Car));
- r[n][0] = malloc(sizeof(Service));
- printf("Which card should I delete from the list?\n");
- fgets(help, sizeof(help), stdin);
- for(i=0; i<(n-1); i++)
- {
- if((p[i] -> ID )== atoi(help) )
- {
- break;
- }
- }
- p[i] -> ID = p[n-1] -> ID;
- strcpy(p[i] -> Mark, p[n-1] -> Mark);
- p[i] -> model = p[n-1] -> model;
- p[i] -> mileage = p[n-1] -> mileage;
- p[i] -> currentREPAIRS= p[n-1] -> currentREPAIRS;
- p[i] -> archiveREPAIRS = p[n-1] -> archiveREPAIRS;
- for(e=0; e<T[n-1]; e++)
- {
- r[i][e] = malloc(sizeof(Service));
- strcpy(r[i][e] -> FULLname, r[n-1][e] -> FULLname);
- r[i][e] -> ID = r[n-1][e] -> ID;
- r[i][e] -> repairTIMES = r[n-1][e] -> repairTIMES;
- r[i][e] -> SERVICEhistory = r[n-1][e] -> SERVICEhistory;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void modify(int n, int *T)
- {
- char help[10], amount[10], CID[10], mark[10], model[10], mileage[10], rep[10], archive[10], RID[10], name[10], reptime[10], history[10];
- int i=0, e=0;
- printf("Which Car Info would you like to modify?\n");
- fgets(help, sizeof(help), stdin);
- for(i=0; i<(n-1); i++)
- {
- if(p[i] -> ID == atoi(help))
- break;
- }
- printf("What is car ID?\n");
- fgets(CID, sizeof(CID), stdin);
- p[i] -> ID = atoi(CID);
- fflush(stdin);
- printf("What is car Mark?\n");
- scanf("%s", p[i] -> Mark);
- fflush(stdin);
- printf("What is car Model?\n");
- fgets(model, sizeof(model), stdin);
- p[i] -> model = atoi(model);
- fflush(stdin);
- printf("What is car Mileage?\n");
- fgets(mileage, sizeof(mileage), stdin);
- p[i] -> mileage = atoi(mileage);
- fflush(stdin);
- printf("What is car CurrReapir?\n");
- fgets(rep, sizeof(rep), stdin);
- p[i] -> currentREPAIRS = atoi(rep);
- fflush(stdin);
- printf("How many repiars did it have?\n");
- fgets(amount, sizeof(amount), stdin);
- T[i]= atoi(amount);
- printf("What is car AoRepairs?\n");
- fgets(archive, sizeof(archive), stdin);
- p[i] -> archiveREPAIRS = atoi(archive);
- fflush(stdin);
- for(e=0; e<T[i]; e++)
- {
- r[i][e] = malloc(sizeof(Service));
- printf("What is repair ID?\n");
- fgets(RID, sizeof(RID), stdin);
- r[i][e] -> ID = atoi(RID);
- fflush(stdin);
- printf("What is repair name?\n");
- scanf("%s", r[i][e] -> FULLname);
- fflush(stdin);
- printf("What is repair RepTime?\n");
- fgets(reptime, sizeof(reptime), stdin);
- r[i][e] -> repairTIMES = atoi(reptime);
- fflush(stdin);
- printf("What is repair History?\n");
- fgets(history, sizeof(history), stdin);
- r[i][e] -> SERVICEhistory = atoi(history);
- fflush(stdin);
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void druk(int n, int *T)
- {
- int i=0, e=0;
- for(i=0; i<(n); i++)
- {
- printf("%i\n", p[i] -> ID);
- for(e=0; e<T[i]; e++)
- {
- printf("\t%i\t", r[i][e] -> ID);
- printf("%s\t", r[i][e] -> FULLname);
- printf("%i\t", r[i][e] -> repairTIMES);
- printf("%i", r[i][e] -> SERVICEhistory);
- printf("\n");
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void print(int n, int *T)
- {
- int i=0, e=0;
- for(i=0; i<(n); i++)
- {
- printf("%i\t", p[i] -> ID);
- printf("%s\t", p[i] -> Mark);
- printf("%i\t", p[i] -> model);
- printf("%i\t", p[i] -> mileage);
- printf("%i\t", p[i] -> currentREPAIRS);
- printf("%i\n", p[i] -> archiveREPAIRS);
- }
- /* for(e=0; e<T[i]; e++)
- {
- printf("\t%i\t", r[i][e] -> ID);
- printf("%s\t", r[i][e] -> FULLname);
- printf("%i\t", r[i][e] -> repairTIMES);
- printf("%i", r[i][e] -> SERVICEhistory);
- printf("\n");
- } */
- druk(n, T);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void sort(int n, int *T)
- {
- int i=0, j=0, e=0, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
- char help[10], help2[20];
- int a,b,c,d;
- p[n] = malloc(sizeof(Car));
- r[n][0] = malloc(sizeof(Service));
- for (i = 0; i<(n); i++)
- {
- for (j=0; j<(n-1); j++)
- {
- if ((p[j] -> ID) > (p[j+1] -> ID))
- {
- temp1 = p[j+1] -> ID;
- p[j+1] -> ID = p[j] -> ID;
- p[j] -> ID = temp1;
- strcpy(help, p[j+1] -> Mark);
- strcpy(p[j+1] -> Mark, p[j] -> Mark);
- strcpy(p[j] -> Mark, help);
- temp2 = p[j+1] -> model;
- p[j+1] -> model= p[j] -> model;
- p[j] -> model = temp2;
- temp3 = p[j+1] -> mileage;
- p[j+1] -> mileage = p[j] -> mileage;
- p[j] -> mileage = temp3;
- temp4 = p[j+1] -> currentREPAIRS;
- p[j+1] -> currentREPAIRS = p[j] -> currentREPAIRS;
- p[j] -> currentREPAIRS = temp4;
- temp5 = p[j+1] -> archiveREPAIRS;
- p[j+1] -> archiveREPAIRS = p[j] -> archiveREPAIRS;
- p[j] -> archiveREPAIRS = temp5;
- if(T[j] > T[j+1])
- {
- for(e=0; e<T[j]; e++)
- {
- r[j][e] = malloc(sizeof(Service));
- temp6 = r[j+1][e] -> ID;
- r[j+1][e] -> ID = r[j][e] -> ID;
- r[j][e] -> ID = temp6;
- strcpy(help2, r[j+1][e] -> FULLname);
- strcpy(r[j+1][e] -> FULLname, r[j][e] -> FULLname);
- strcpy(r[j][e] -> FULLname, help2);
- temp7 = r[j+1][e] -> repairTIMES;
- r[j+1][e] -> repairTIMES = r[j][e] -> repairTIMES;
- r[j][e] -> repairTIMES = temp7;
- temp8 = r[j+1][e] -> SERVICEhistory;
- r[j+1][e] -> SERVICEhistory = r[j][e] -> SERVICEhistory;
- r[j][e] -> SERVICEhistory = temp8;
- }
- }
- else
- {
- for(e=0; e<T[j+1]; e++)
- {
- r[j][e] = malloc(sizeof(Service));
- temp6 = r[j+1][e] -> ID;
- r[j+1][e] -> ID = r[j][e] -> ID;
- r[j][e] -> ID = temp6;
- strcpy(help2, r[j+1][e] -> FULLname);
- strcpy(r[j+1][e] -> FULLname, r[j][e] -> FULLname);
- strcpy(r[j][e] -> FULLname, help2);
- temp7 = r[j+1][e] -> repairTIMES;
- r[j+1][e] -> repairTIMES = r[j][e] -> repairTIMES;
- r[j][e] -> repairTIMES = temp7;
- temp8 = r[j+1][e] -> SERVICEhistory;
- r[j+1][e] -> SERVICEhistory = r[j][e] -> SERVICEhistory;
- r[j][e] -> SERVICEhistory = temp8;
- }
- }
- }
- }
- }
- print( n, T );
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void main()
- {
- int menu, n=0, z=0;
- char tabela[5];
- int repair[30], *T;
- T = &repair[30];
- do
- {
- printf("Menu\n");
- printf("1. Adding record\n");
- printf("2. Removing record\n");
- printf("3. Modify record\n");
- printf("4. Print all records\n");
- printf("5. Sort records\n");
- printf("6. Print current list of repairs by each car\n");
- printf("7. Quit\n");
- fgets(tabela, sizeof(tabela), stdin);
- menu = atoi(tabela);
- switch( menu )
- {
- case 1 : n++;
- add( n, z, T );
- break;
- case 2 : deleting( n, T );
- n--;
- break;
- case 3 : modify( n, T );
- break;
- case 4 : print( n, T );
- break;
- case 5 : sort( n, T );
- break;
- case 6 : druk( n, T );
- break;
- case 7 : printf("Good Bye!\n");
- break;
- deafult: printf("Wrong data!\n");
- break;
- }
- }
- while(menu!=7);
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement