Помогите плз, прога дает сбои

  • Автор темы NightManiak
  • Дата начала
N

NightManiak

#1
C++:
#include <iostream>
#include <string.h>
using namespace std;
struct elements
{
elements()
{}
elements(int n, char c1, char c2)
{
num=n;
c=c1;
str=c2;
}
int num;
char c;
char str;
elements *next;	 // óêàçàòåëü íà ñëåäóþùèé ýëåìåíò ñïèñêà
};
class list
{
elements *First;	 // óêàçàòåëü íà ïåðâûé ýëåìåíò ñïèñêà
elements *End;	  // óêàçàòåëü íà ïîñëåäíèé ýëåìåíò ñïèñêà
public:
list();			 //êîíñòðóêòîð, óñòàíàâëèâàåì âñå çíà÷åíèÿ óêàçàòåëåé íà íà÷àëî ñïèñêà(èëè êîíåö)
~list();			 //äåñòðóêòîð, óäàëÿåò âåñü ñïèñîê
//Îáúÿâëåíèå ôóíêöèÿ äëÿ ðàáîòû ñî ñïèñêîì
void addToList(int, char, char); //äîáàâëåíèå ýëåìåíòà â ñïèñîê
void delFirst();	  //ôóíêöèÿ äëÿ óäàëåíèÿ ïåðâîé ÿöåéêè ñïèñêà 
void change(int);		 //èçìåíèòü ýëåìåíò â ñïèñêå 
void show(char);		  //Âûâîä ñïèñêà
void addFirstToList(int, char, char);
};
/////////////////////////////////////////////////////////////////////////////
list::list()
{
First = 0;
End = 0;
}
/////////////////////////////////////////////////////////////////////////////
list::~list()
{
while(First != 0)
{
elements *pTemp = First;
First = First->next;

}
}
//Îïðåäåëåíèå âñåõ ôóíêöèé äëÿ êëàññà list
/////////////////////////////////////////////////////////////////////////////
void list::addToList(int n, char c1, char c2)
{
elements *temp = new elements;
if(End == 0)
End = temp;
else
First->next = temp;
temp->num = n;
temp->c = c1;
temp->str = c2;
temp->next = NULL; 
First = temp;
}
//Äîáàâëåíèå ïåðâîé ýëåìåíòîé list
/////////////////////////////////////////////////////////////////////////////
void list::addFirstToList(int n, char c1, char c2)
{
elements *temp = new elements(n, c1, c2);
if(End == NULL)
End = temp;
else
temp->next = First;
}
/////////////////////////////////////////////////////////////////////////////
void list::delFirst()
{
elements *pTemp = First;
pTemp->num=0;
pTemp->c=0;
pTemp->str=0;
}
/////////////////////////////////////////////////////////////////////////////
void list::change(int p)
{
int i;
char c;
char s;
cout<<"Enter the int:"<<endl;
cin>>i;
cout<<"Enter the char:"<<endl;
cin>>c;
cout<<"Enter the string:"<<endl;
cin>>s;
elements *Temp = First;
for(int j=0; j<p-1; j++){
Temp = Temp->next;}
Temp->num = i;
Temp->c = c;
Temp->str = s;
}
/////////////////////////////////////////////////////////////////////////////
void list::show(char kol)
{
elements *pTemp = First;
for(int i=0; i<=kol; i++)
{
cout<<kol; 
cout << pTemp->num <<"\t";
cout << pTemp->c <<"\t";
cout << pTemp->str << "\t\n";

pTemp = pTemp->next;
}
cout<<"\n";
}
/////////////////////////////////////////////////////////////////////////////
int main()
{
const int k=3;
list l;
int num[k];
char c[k];
char str[k];

for(int i=0; i<k; i++)
{
cout<<"Enter the int "<<i+1<<":"<<endl;
cin>>num[i];
cout<<"Enter the char "<<i+1<<":"<<endl;
cin>>c[i];
cout<<"Enter the string "<<i+1<<":"<<endl;
cin>>str[i];
//çàïîëíÿåì ñïèñîê äàííûìè
l.addToList(num[i], c[i], str[i]);
}
cout<<"\n\nWhat do you want?"<<endl;
cout<<"1: Show the list"<<endl;
cout<<"2: Delete first cell of the list"<<endl;
cout<<"3: Change the element"<<endl;
int tmp;
cin>>tmp;
if(tmp==1)
l.show(k);
else if(tmp==2){
l.delFirst();
l.show(k);}
else if(tmp==3)
{
int p;
cout<<"\nEnter the number cell for change data: "<<endl;
cin>>p;
l.change(p);
l.show(k);
}
cin.get();
cin.get();
return 0;
}