Тема: Не можу зрозуміти чому не показує список який я добавляю в програму))
НЕможу зрозуміти чому непоказує добавленні товари))
// Курсова.cpp: определяет точку входа для консольного приложения.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class file;
typedef file* pFile;
class file
{
string name;
int cina;
pFile next,prev;
public:
string &Name()
{
return name;
}
int &Cina()
{
return cina;
}
pFile &Next()
{
return next;
}
pFile &Prev()
{
return prev;
}
virtual void Input()
{
cout << "Name: ";
cin >> Name();
cout << "Cina:";
cin >> Cina();
}
virtual void Output()
{
cout<<"Name: "<<Name()<<"Cina: "<<Cina()<<" grn";
}
file(string nm="", int s=0, pFile n=NULL, pFile p=NULL)
{
Name () = nm;
Cina() = s;
Prev() = p;
Next() = n;
}
};
class Tovar: public file
{
int k;
public:
int &K()
{
return k;
}
void Input()
{
cout << "Tovar pobut himii" << endl;
file::Input();
cout<< "K-st v najavnosti: ";
cin >> K();
}
void Output()
{
cout << "Tovar pobut himii"<<endl;
file::Output();
cout<<" K-st v najavnosti: " << K()<< endl;
}
Tovar(int r=0, int c=0, string n="", int s=0, pFile prv=NULL, pFile nxt=NULL):file(n,s,prv,nxt)
{
K() = r;
}
};
class Z_p: public file
{
string url;
public:
string &Url()
{
return url;
}
void Input()
{
cout<<"Zybna pasta"<<endl;
file::Input();
cout << "Rik vugotovlennja: ";
cin >> Url();
}
void Output()
{
cout << "Zybna pasta"<<endl;
file::Output();
cout << "Rik vugotovlennja: "<<Url()<< endl;
}
Z_p(string p="", string u="", string n="", int s=0, pFile prv=NULL, pFile nxt=NULL):file(n,s,prv,nxt)
{
Url() = u;
}
};
class List
{
pFile start,temp, end;
int count;
public:
pFile SStart()
{
return start;
}
pFile &Temp()
{
return temp;
}
pFile &End()
{
return end;
}
int &Count()
{
return count;
}
List ()
{
start = temp = end = NULL;
Count() = 0;
}
void AddTovar()
{
temp = new Tovar();
temp->Input();
if(count==0)
{
start = end = temp;
start->Next() = start;
start->Prev() = start;
}
else
{
temp->Next()=end->Next();
temp->Prev()=end;
end->Next()->Prev()=temp;
end->Next()=temp;
end = temp;
}
Count()++;
}
void AddZ_p()
{
temp = new Z_p();
temp->Input();
if(count==0)
{
start = end = temp;
start->Next() = start;
start->Prev() = start;
}
else
{
temp->Next() = end->Next();
temp->Prev() = end;
end->Next()->Prev() = temp;
end->Next() = temp;
end = temp;
}
Count()++;
}
pFile Search(string n)
{
if(!Count())
{
cout << "spusok porognij" << endl;
return NULL;
}
temp = start;
do
{
if(temp->Name()==n) return temp;
temp = temp->Next();
}
while (temp!=start);
cout << "Tovar dont found" << endl;
return NULL;
}
void Del(string n)
{
if(!Count()) return;
pFile tmp = Search(n);
if(tmp==NULL)
{
cout << "Tovar dont found" << endl;
return;
}
if(Count()!=1)
{
if(tmp == start) start = start->Next();
if(tmp == end) end = end->Prev();
tmp->Prev()->Next() = tmp->Next();
tmp->Next()->Prev() = tmp->Prev();
}
delete tmp;
Count()--;
cout<<"1 tovar vudaleno" <<endl;
}
void ShowList()
{
temp=start;
for(int i=0; i<Count(); i++,temp=temp->Next()) temp->Output();
}
};
void main()
{
List ftp;
string cmd="help";
while(cmd!="exit")
{
if(cmd=="help")
{
cout << "Menu" << endl;
cout << "1 - duvutus spusok " << endl;
cout << "2 - add new tovar" << endl;
cout << "3 - add new zybna pasta" << endl;
cout << "5 - delete tovar" << endl;
cout << "6 - exit with program" << endl;
}
if(cmd=="l")
{
ftp.ShowList();
}
if(cmd=="2")
{
ftp.AddTovar();
}
if(cmd=="3")
{
ftp.AddZ_p();
}
if(cmd=="5")
{
cout << "Vvedit name tovary: ";
string tmp;
cin >> tmp;
ftp.Del(tmp);
}
if(cmd=="6")
{
cout << "Good-bye!"<< endl;
exit(0);
}
cout << endl << "> "; cin >> cmd;
}
}