помогите доделать плиз программа на С++ | Код |
#include <iostream> using namespace std;
#include <windows.h> #include <conio.h>
#define nlen 256
ostream & operator<<(ostream & out,char* s) { char buf[512],*p=buf; CharToOem(s,buf); while(*p) out<<*p++; return out; }
//Товар class Tovar { unsigned int number; char name[nlen];
public:
double price; Tovar() { number = 0; strcpy(name,"Не инициализировано!"); price = 0; }
Tovar(unsigned int num, char* Name, double pr) { number = num; if(Name != 0) strcpy(name,Name); price = pr; }
void GetData() { cout<<"Введите номер товара->"; cin>>number; cout<<"Введите название товара->"; cin>>name; cout<<"Введите цену товара->"; cin>>price; }
void ShowInfo() { cout<<name<<endl; cout<<"Номер: "<<number<<endl; cout<<"Цена: "<<price<<endl; } };
class Date { unsigned int day; unsigned int month; unsigned int year;
public:
void SetDate(int Day, int Month, int Year) { day = Day; month = Month; year = Year; }
void GetDate() { do { cout<<"День->"; cin>>day; { if (day>31)
cout<<"НЕКОРЕКТНЫЙ ВВОД!!!"<<endl; } } while (day>31);
do { cout<<"Месяц->"; cin>>month; { if (month>12) cout<<"НЕКОРЕКТНЫЙ ВВОД!!!"<<endl; } } while (month>12);
do { cout<<"Год->"; cin>>year; { if (year>2020) cout<<"НЕКОРЕКТНЫЙ ВВОД!!!"<<endl; } } while (year>2020); }
void ShowDate() { cout<<day<<"."<<month<<"."<<year<<endl; } };
//Партия товаров class Tovaro { protected: //даты приема на склад Date date;
// Количество товара unsigned int n;
//Товар Tovar tov;
int state; //0 - на складе 1 - продано
public:
// Номер партии unsigned int number;
Tovaro(Date d, Tovar t, unsigned int k ,int st,int num) { date = d; tov = t; n = k; state = st; number = num; }
Tovaro() { n = 0; state = 0; number = 0; }
void GetData() { cout<<"...Введите даные партии..."<<endl; /* cout<<"Введите номер партии->"; cin>>number; cout<<endl;*/ cout<<"Дата с приема партии->\t"; date.GetDate(); cout<<endl; cout<<"Кол-во товаров в партии->\t"; cin>>n; cout<<endl; cout<<"Введите даные о товаре->"; tov.GetData(); cout<<endl; cout<<"Введите статус партии ( 0 - на складе; 1 - продано)->"; cin>>state; cout<<endl; }
void Show() { cout<<"........Даные партии........"<<endl; cout<<"Номер партии->"; cout<<number<<endl; cout<<"Дата с прибытия на склад - "; date.ShowDate(); cout<<endl;
cout<<"Кол-во товаров в партии - "<<n<<endl;
cout<<"Даные о товаре - "; tov.ShowInfo(); cout<<endl; cout<<"Статус партии - "; if(state) { cout<<"продано"; } else cout<<"на складе";
cout<<endl<<"........................................."<<endl<<endl; }
void SetState(int st) { state = st; }
};
class PTQueueElement;
class QueueElement { public: friend PTQueueElement;
PTQueueElement* next; PTQueueElement* prev;
QueueElement() { next = NULL; prev = NULL; }
virtual QueueElement* GetNext() = 0; };
class PTQueueElement: public Tovaro, public QueueElement {
int priority;
public: PTQueueElement():QueueElement() { priority = 0; }
QueueElement* GetNext() { return next; } };
class PTQueue { PTQueueElement* head; PTQueueElement* tail; PTQueueElement* current;
int numberOfActs;
public:
PTQueue() { head = NULL; tail = NULL; current = NULL;
numberOfActs = 0; }
void Add() { PTQueueElement* temp = new PTQueueElement(); temp->GetData();
if(numberOfActs==0) { head = tail = temp; temp->next = NULL; temp->prev = NULL; } else { tail->next = temp; temp->prev = tail; temp->next = NULL; tail = temp; }
numberOfActs++; }
bool Delete() { int actNumber = 0; cout<<"Введите номер партии для удаления->"; cin>>actNumber;
if(head == NULL) { cerr<<"Нечего удалять!!!"; return false; } current = head; do { if(current->number == actNumber) { if(current->prev != NULL) current->prev->next = current->next; if(current->next != NULL) current->next->prev = current->prev;
current->next = NULL; current->prev = NULL; delete current; current = NULL;
numberOfActs--;
return true; } current = current->next; } while(current != NULL);
return false; }
/* void Del() { int qwe=0; cout<<"Введите номер товара который продали"; cin>>number; }*/
void ShowList() { if(head!=NULL) current = head; else { cerr<<"Нет товаров на складе!!!"<<endl; return; }
do { current->Show(); current = current->next; } while(current != NULL); }
int ActsNumber() { return numberOfActs; } };
void main()
{ MessageBox(NULL, "ну учет товаров ведётся примерно так!!)", "КУРСОВАя_вар№11", MB_OK);
SetConsoleOutputCP(1251); SetConsoleCP(1251);
PTQueue pt; int tovCompleated = 0;
//Интерактивное меню int pr_tov; char ch = '0';
do { cout<<"-------------Учет товаров на складе------------"<<endl; cout<<"Учет партий товатор:"<<endl; cout<<"Кол-во проданных партий: "<<tovCompleated<<endl; cout<<"Кол-во партий на складе: "<<pt.ActsNumber()<<endl<<endl; cout<<"МенЮ программы"<<endl; cout<<"-----Выберите пункт меню, нажав соответствующую цифру----\n"; cout<<"1 - Добавить товар на склад\n"; cout<<"2 - Удалить товар со склада\n"; cout<<"3 - Посмотреть список\n"; cout<<"0 - Выход\n\n\n";
ch=getch(); switch(ch) { case '1': pt.Add(); break; case '2': if( pt.Delete() ) tovCompleated++; cout<<"Введите количество проданных товаров"; cin>>pr_tov; break;
case '3': pt.ShowList(); break; case '0': exit(0); break;
default: cerr<<"\t"<<"Неверный ввод!!!ПОВТОРИ ВВОД"<<endl; }
cout<<endl; } while(ch != '0');
}
|
нужно чтобы она я мог вводить товары,удалять их...и писалось количество оставшихся товаров...вроде легко,но не пойму как это осуществить...
|