Условие такое: Программа должна выполнять: стандартеую операцию добавления в стек; стандартную операцию извлечения из стека; работа с переменными стека; ошибка переполнения. Реализацию осуществить в отдельных функциях, сохранять информацию в файл.
Вот то что я пока сделал (не работает):
| Код | #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #include <iostream> using namespace std;
struct man{ char F[15],I[15],O[15],DR[10]; }; struct STACK{ struct man M; struct STACK *next; };
//___________________________ void add(struct STACK **head); void iden(struct STACK head, struct man w); void input(struct man *w); void display(struct STACK *wk); struct STACK *print(struct STACK *h); void del(struct STACK **head);
//___________________________ void main(void) {struct STACK *head=NULL; while(1) { cout <<"Vuberite deistvie:"<<endl; cout <<"a-Dobavit element"<<endl; cout <<"p-Vuvod soderchimogo stacka"<<endl; cout <<"d-Ydalenie elementa"<<endl; cout <<"q-Exit"<<endl; fflush(stdin); switch(getch()) { case 'a': case 'A':add(&head); break; case 'p': case 'P':display(head); break; case 'd': case 'D':del(&head); break; case 'q': case 'Q':return; default : cout << "ERROR.." << endl; cout << "Povtorite vvod" <<endl; } cout << "press any key" <<endl; getch(); } } //___________________________ void add(struct STACK **head) { struct STACK *tmp; struct man W; input(&W); if(iden(*head,&W)==0) { tmp=new STACK; if(tmp==NULL) {cout << "Svobodnoi pamati net";return;} else { tmp->M=W; tmp->next=(*head); (*head)=tmp; } } else cout << "Takoi element est"<<endl; return; }
//____________________________
int iden(struct STACK *head,struct man * w) {while(head) {if (strcmp(head->M.F,w->F)==0 && strcmp(head->M.I,w->I)==0 && strcmp(head->M.O,w->O)==0 && strcmp(head->M.DR,w->DR)==0) return 1; head=head->next; } return 0; } //____________________________ void input(struct man *w) { cout << "Vvedite Fmili Ime Otchestvo Daty" << endl; fflush(stdin); cin >> w->F >> w->I >> w->O >> w->DR; } //____________________________ void display(struct man *h) { cout << "Information" <<endl; if(!h) {cout << "Stack pust"<<endl;return;} do {print(h);h=h->next; }while(h); cout <<""<<endl; return; } //___________________________ struct STACK *print(struct STACK *wk) { cout << wk->M.F << wk->M.I << wk->M.O << wk->M.DR << endl; return wk; } //__________________________ void del(struct STACK **head) {struct STACK *cur,*pr; struct man w; cur=*head; if(!cur){cout << "Stack pust" << endl;return;} cout << "Kakoi element nado ydalit" << endl; input(&w); while(cur) { if(strcmp(cur->M.F,w.F)==0 && strcmp(cur->M.I,w.I)==0 && strcmp(cur->M.O,w.O)==0 && strcmp(cur->M.DR,w.DR)==0) {if(cur==*head) { (*head)=(*head)->next; delete cur; cout << "Element ydalen" << endl;return; } pr->next=cur->next; delete cur; cout << "Element ydalen" << endl;return; } pr=cur; cur=cur->next; } cout << "Net takogo elementa" <<endl; } //___________________________________
| |