Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #include <ctime>
- using namespace std;
- class obliczenia {
- private:
- int Liczby[10];
- public:
- int suma(){
- short i;
- int suma=0;
- for(i=0; i<10; i++){
- suma+=Liczby[i];
- }
- return suma;
- }
- int iloczyn(){
- short i;
- int ilo=1;
- for(i=0; i<10; i++){
- if(Liczby[i]%2==0)
- ilo*=Liczby[i];
- return ilo;
- }
- }
- obliczenia() {
- short i;
- for(i=0; i<10; i++){
- Liczby[i]=((rand()%199)-99);
- }
- }
- void wyswietl(){
- short i;
- int *wsk;
- cout<<endl<<"Liczby: ";
- for(i=0; i<10; i++){
- wsk=&Liczby[i];
- cout<<*wsk <<"; ";
- }
- cout<<endl;
- }
- void adresy(){
- short i;
- int *wsk;
- cout<<endl<<"Adresy: ";
- for(i=0; i<10; i++){
- wsk=&Liczby[i];
- cout<<wsk<<"; ";
- }
- cout<<endl;
- }
- ~obliczenia(){
- cout<<"Obiekt usunieto";
- }
- void zamien(short lowIndex, short highIndex){
- short i=lowIndex;
- if (lowIndex>highIndex){
- lowIndex=highIndex;
- highIndex=i;}
- }
- void wysw_oddo(short lowIndex, short highIndex){
- zamien(lowIndex,highIndex);
- short i;
- cout<<endl;
- for(i=lowIndex; i<=highIndex; i++){
- cout<<Liczby[i]<<"; ";
- }
- cout<<endl;
- }
- };
- int main(){
- short *a,*b,c,d;
- a=&c;
- b=&d;
- srand(time(NULL));
- cout<<"Metody na pierwszym obiekcie"<<endl;
- obliczenia obiekt;
- obiekt.wyswietl();
- cout<<"Suma= " <<obiekt.suma()<<endl;
- cout<<endl <<"Iloczyn= " <<obiekt.iloczyn()<<endl;
- obiekt.adresy();
- cout<< "Od ilu do ilu chcesz wyswietlic elementy?"<<endl;
- cin>>c;
- cout<<endl;
- cin>>d;
- obiekt.wysw_oddo(*a,*b);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement