Advertisement
szubert

moj spr v1.1

Mar 29th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. class obliczenia {
  9. private:
  10.         int Liczby[10];
  11. public:
  12.         int suma(){
  13.                 short i;
  14.                 int suma=0;
  15.                 for(i=0; i<10; i++){
  16.                         suma+=Liczby[i];
  17.                 }
  18.                 return suma;
  19.         }
  20.         int iloczyn(){
  21.                 short i;
  22.                 int ilo=1;
  23.                 for(i=0; i<10; i++){
  24.                         if(Liczby[i]%2==0)
  25.                         ilo*=Liczby[i];
  26.                         return ilo;
  27.                 }      
  28.         }
  29.         obliczenia() {
  30.                 short i;
  31.                 for(i=0; i<10; i++){
  32.                         Liczby[i]=((rand()%199)-99);
  33.                 }
  34.         }
  35.         void wyswietl(){
  36.                 short i;
  37.                 int *wsk;
  38.                 cout<<endl<<"Liczby: ";
  39.                 for(i=0; i<10; i++){
  40.                         wsk=&Liczby[i];
  41.                         cout<<*wsk <<"; ";
  42.                 }
  43.                 cout<<endl;
  44.         }
  45.         void adresy(){
  46.                 short i;
  47.                 int *wsk;
  48.                 cout<<endl<<"Adresy: ";
  49.                 for(i=0; i<10; i++){
  50.                         wsk=&Liczby[i];
  51.                         cout<<wsk<<"; ";
  52.                 }
  53.                 cout<<endl;
  54.         }
  55.         ~obliczenia(){
  56.                 cout<<"Obiekt usunieto";
  57.         }
  58.         void zamien(short lowIndex, short highIndex){
  59.                 short i=lowIndex;
  60.                 if (lowIndex>highIndex){
  61.                 lowIndex=highIndex;
  62.                 highIndex=i;}
  63.         }
  64.         void wysw_oddo(short lowIndex, short highIndex){
  65.                 zamien(lowIndex,highIndex);
  66.                 short i;
  67.                 cout<<endl;
  68.                 for(i=lowIndex; i<=highIndex; i++){
  69.                         cout<<Liczby[i]<<"; ";
  70.                 }
  71.                 cout<<endl;
  72.         }
  73.        
  74. };
  75.  
  76.  
  77.  
  78. int main(){
  79. short *a,*b,c,d;
  80. a=&c;
  81. b=&d;
  82. srand(time(NULL));
  83.  
  84. cout<<"Metody na pierwszym obiekcie"<<endl;
  85. obliczenia obiekt;
  86. obiekt.wyswietl();
  87. cout<<"Suma= " <<obiekt.suma()<<endl;
  88. cout<<endl <<"Iloczyn= " <<obiekt.iloczyn()<<endl;
  89. obiekt.adresy();
  90.  
  91. cout<< "Od ilu do ilu chcesz wyswietlic elementy?"<<endl;
  92. cin>>c;
  93. cout<<endl;
  94. cin>>d;
  95.  
  96. obiekt.wysw_oddo(*a,*b);
  97.  
  98. getch();
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement