Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#praga once
- struct tek{
- double cena;
- char vid[size];
- int kol;
- char name[size];
- int kod;
- int index_magazin;
- };
- struct tek tech[size];
- int techSize=0;
- void chitatTechniku(){
- FILE *file;
- file=fopen("tech", "rb");
- fread(&techSize,sizeof(techSize),1,file);
- fread(tech,sizeof(struct tek),techSize,file);
- fclose(file);
- }
- void pisatTechniku(){
- FILE *file;
- file=fopen("tech", "w+b");
- fwrite(&techSize,sizeof(techSize),1,file);
- fwrite(tech,sizeof(struct tek),techSize,file);
- fclose(file);
- }
- void dobavitTechniku();
- void izmenitTechniku();
- void udalitTechniku();
- void vivestiTechniku();
- void sortirovatTechniku();
- void menuTechniki(){
- while (1){
- cls;
- printf("1 - Добавить\n");
- printf("2 - Изменить\n");
- printf("3 - Удалить\n");
- printf("4 - Вывести\n");
- printf("5 - Отсортировать\n");
- printf("6 - Назад\n");
- switch (_getch()){
- case '1':
- dobavitTechniku();
- break;
- case '2':
- izmenitTechniku();
- break;
- case '3':
- udalitTechniku();
- break;
- case '4':
- vivestiTechniku();
- break;
- case '5':
- sortirovatTechniku();
- break;
- case '6':
- return;
- default:
- break;
- }
- }
- }
- void dobavitTechniku(){
- vivestiMagazin();
- int nomer;
- printf("Номер магазина\n");
- scanf("%d", &nomer);
- nomer--;
- if (nomer>magazinSize || nomer<0){
- printf("Ошибка\n");
- pause;
- return;
- }
- tech[techSize].index_magazin=magazin[nomer].index_magazin;
- printf("Название\n");
- fflush(stdin);
- gets(tech[techSize].name);
- printf("Вид\n");
- fflush(stdin);
- gets(tech[techSize].vid);
- printf("Цена\n");
- fflush(stdin);
- scanf("%lf", &tech[techSize].cena);
- printf("Количество\n");
- fflush(stdin);
- scanf("%d", &tech[techSize].kol);
- printf("Код\n");
- fflush(stdin);
- scanf("%d", &tech[techSize].kod);
- techSize++;
- pisatTechniku();
- }
- void izmenitTechniku(){
- vivestiTechniku();
- int nomer;
- printf("Номер техники\n");
- scanf("%d", &nomer);
- nomer--;
- if (nomer>techSize || nomer<0){
- printf("Ошибка\n");
- pause;
- return;
- }
- while (1){
- cls;
- printf("1 - Название\n");
- printf("2 - Вид\n");
- printf("3 - Цена\n");
- printf("4 - Количество\n");
- printf("5 - Код\n");
- printf("6 - Выход\n");
- switch (_getch()){
- case '1':
- printf("Введите новое название\n");
- fflush(stdin);
- gets(tech[nomer].name);
- break;
- case '2':
- printf("Введите новый вид\n");
- fflush(stdin);
- gets(tech[nomer].vid);
- break;
- case '3':
- printf("Введите новую цену\n");
- fflush(stdin);
- scanf("%lf", &tech[nomer].cena);
- break;
- case '4':
- printf("Введите новое количество\n");
- fflush(stdin);
- scanf("%d", &tech[nomer].kol);
- break;
- case '5':
- printf("Введите новый код\n");
- fflush(stdin);
- scanf("%d", &tech[nomer].kod);
- break;
- case '6':
- pisatTechniku();
- return;
- default:
- break;
- }
- }
- }
- void udalitTechniku(){
- vivestiTechniku();
- int nomer;
- printf("Номер техники\n");
- scanf("%d", &nomer);
- nomer--;
- if (nomer>techSize || nomer<0){
- printf("Ошибка\n");
- pause;
- return;
- }
- int i;
- techSize--;
- for (i=nomer;i<techSize;i++){
- tech[i]=tech[i+1];
- }
- pisatTechniku();
- }
- void vivestiTechniku(){
- cls;
- printf("_____________________________________________________________________________\n");
- printf("|# |Название |Вид |Цена |Количество|Код |\n");
- printf("|_____|____________________|_______________|__________|__________|__________|\n");
- int i;
- char str[size];
- for (i=0;i<techSize;i++){
- sprintf(str,"%d", i+1);
- printf("|%5s|", str);
- printf("%20s|", tech[i].name);
- printf("%20s|", tech[i].vid);
- sprintf(str,"%lf", tech[i].cena);
- printf("%10s|", str);
- sprintf(str,"%d", tech[i].kol);
- printf("%10s|", str);
- sprintf(str,"%d", tech[i].kod);
- printf("%10s|", str);
- printf("|_____|____________________|_______________|__________|__________|__________|\n");
- }
- pause;
- }
- void sortirovatTechniku(){
- cls;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement