Public paste
Undefined
By: Guest | Date: Jun 2 2011 18:43 | Format: C++ | Expires: never | Size: 2.36 KB | Hits: 815

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6. struct komp{
  7.         int numer;
  8.         char procesor[30];
  9.         int rok;
  10.         int cena;
  11.         komp *nast;
  12. };
  13.  
  14. int main()
  15. {
  16.        
  17.         komp *glowa=new komp;
  18.         glowa->nast=NULL;
  19.         do
  20.         {cout<<"Podaj numer seryjny:"<<endl;
  21.                 cin>>glowa->numer;
  22.         }while(glowa->numer>1000000);
  23.         cout<<"Podaj typ procesora"<<endl;
  24.         cin>>glowa->procesor;
  25.         do{cout<<"Podaj rok przyjecia komputera."<<endl;       
  26.                 cin>>glowa->rok;
  27.         }while(glowa->rok<1990&&glowa->rok>2010);
  28.         do{cout<<"Podaj cene."<<endl;
  29.                 cin>>glowa->cena;}while(glowa->cena<10);
  30.         char znak;     
  31.         komp *nowy;
  32.         do{
  33.                 cout<<"Czy nastepny?"<<endl;
  34.                 cin>>znak;
  35.                 if(znak=='n')
  36.                 {
  37.                         break;
  38.                 }
  39.                 if(glowa->nast==NULL)
  40.                 {
  41.                         nowy=new komp;
  42.                         glowa->nast=nowy;
  43.                 }
  44.                 else
  45.                 {
  46.                         nowy->nast=new komp;
  47.                         nowy=nowy->nast;
  48.                 }
  49.                         do
  50.         {cout<<"Podaj numer seryjny:"<<endl;
  51.                 cin>>nowy->numer;
  52.         }while(nowy->numer>1000000);
  53.         cout<<"Podaj typ procesora"<<endl;
  54.         cin>>nowy->procesor;
  55.         do{cout<<"Podaj rok przyjecia komputera."<<endl;       
  56.                 cin>>nowy->rok;
  57.         }while(nowy->rok<1990&&nowy->rok>2010);
  58.         do{cout<<"Podaj cene."<<endl;
  59.                 cin>>nowy->cena;}while(nowy->cena<10);
  60.                
  61.  
  62.         }while(znak=='t');
  63.         nowy->nast=NULL;
  64.         nowy=glowa;
  65.         cout<<endl<<endl;
  66.         while(nowy!=NULL)
  67.         {
  68.                 cout<<"Numer seryjny: "<<nowy->numer<<endl;
  69.                 cout<<"Procesor: "<<nowy->procesor<<endl;
  70.                 cout<<"Rok: "<<nowy->rok<<endl;
  71.                 cout<<"Cena: "<<nowy->cena<<endl;
  72.                 nowy=nowy->nast;
  73.         }
  74.         int nr;
  75.         nowy=glowa;
  76.         cout<<"Podaj numer do wyszukania"<<endl;
  77.         cin>>nr;
  78.         while(nowy!=NULL)
  79.         {      
  80.                 if(nowy->numer==nr)
  81.                 {      
  82.                         cout<<"Procesor "<<nowy->procesor<<endl;
  83.                         cout<<"Rok "<<nowy->rok<<endl;
  84.                         cout<<"Cena "<<nowy->cena<<endl;
  85.                 }
  86.                 nowy=nowy->nast;
  87.         }
  88.         cout<<"Podaj rok do usuniecia:"<<endl;
  89.         cin>>nr;
  90.         while(glowa->nast!=NULL&&glowa->rok==nr)
  91.         {
  92.                 nowy=glowa;
  93.                 glowa=glowa->nast;
  94.                 delete nowy;
  95.         }
  96.         nowy=glowa;
  97.         komp *pom;
  98.         while(nowy->nast!=NULL)
  99.         {
  100.                 if(nowy->nast->rok==nr)
  101.                 {
  102.                        
  103.                                 pom=nowy->nast;
  104.                                 nowy->nast=pom->nast;
  105.                                 delete pom;
  106.  
  107.                 }
  108.                 else{
  109.                         nowy=nowy->nast;
  110.                 }
  111.  
  112.         }
  113.         nowy=glowa;
  114.         cout<<endl<<endl;
  115.         while(nowy!=NULL)
  116.         {
  117.                 cout<<"Numer seryjny: "<<nowy->numer<<endl;
  118.                 cout<<"Procesor: "<<nowy->procesor<<endl;
  119.                 cout<<"Rok: "<<nowy->rok<<endl;
  120.                 cout<<"Cena: "<<nowy->cena<<endl;
  121.                 nowy=nowy->nast;
  122.         }
  123.        
  124.         system("PAUSE");
  125.         return EXIT_SUCCESS;
  126. }