Advertisement
Guest User

Untitled

a guest
Mar 12th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. // Próba dom.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #define pi 3.14
  6.  
  7.  
  8. class okrag
  9. {
  10.     public:
  11.         int x;
  12.         int y;
  13.         double r;
  14.  
  15.        
  16.  
  17.     okrag();
  18.     okrag(int x0 , int y0, double r0);
  19.    
  20.     void pole()
  21.         {
  22.             double p = pi * r * r;
  23.             cout << "Pole kola wynosi: ";
  24.             cout << fixed << setprecision(3) << p << endl;
  25.         }
  26.  
  27.     void obwod()
  28.         {
  29.             double o = 2 * pi * r;
  30.             cout << "Obwod kola wynosi: ";
  31.             cout << fixed << setprecision(3) << o << endl;
  32.         }
  33.    
  34.  
  35. };
  36.  
  37.    
  38. //konstruktor ktory przypisuje domyslne wartości x=0, y=0, r=1
  39.     okrag::okrag()
  40.         {
  41.             x = 0;
  42.             y = 0;
  43.             r = 1.0;
  44.         }
  45.  
  46. //konstruktor ktory przypisuje wartości podane pozniej przez uzytkownika
  47.     okrag::okrag(int x0 , int y0, double r0)
  48.         {
  49.             x = x0;
  50.             y = y0;
  51.             r = r0;
  52.         }
  53.  
  54. //konstruktor z niepełną liczbą parametrów
  55. //  okrag::okrag(int x, int y);
  56.  
  57.  
  58.  
  59.     void tablica()
  60.         {
  61.             cout << "Podaj rozmiar tablicy: "<< endl;
  62.             int rozmiar;
  63.             cin >> rozmiar;
  64.             int *tab = new int[rozmiar];
  65.             //decyzja ktorego z konstruktorow uzyc
  66.  
  67.             cout << "Podaj numer konstruktora" << endl;
  68.             cout << "[1] Konstruktor domyslny" << endl;
  69.             cout << "[2] Kontruktor umozliwiający wpisanie uzytkownikowi wlasnych wartosci" << endl;
  70.  
  71.             int i;
  72.             cin >> i;
  73.            
  74.             switch(wyb)
  75.                 {
  76.                     //domyslne
  77.                     case 1:
  78.                     okrag kolo();      
  79.                     tab[0]=kolo();
  80.                     break;
  81.  
  82.                    
  83.                     //przez uzytkownika
  84.                     case 2:
  85.                     okrag kolo(x0, y0, r0)
  86.                     break;
  87.  
  88.  
  89.                     case 3:
  90.                     //z pliku (poprzez konstruktor możliwiający wpisane dowolnych wartości
  91.  
  92.                     break;
  93.                 }
  94.         }
  95.  
  96.  
  97.  
  98.  
  99. int _tmain(int argc, _TCHAR* argv[])
  100. {
  101.     int x0;
  102.     int y0;
  103.     double r0;
  104.  
  105.     cout << "Prosze podac X, Y oraz R kola: " << endl;
  106.     cin >> x0 >> y0 >> r0;
  107.  
  108.     okrag kolo = okrag(x0, y0, r0);
  109.  
  110.     kolo.pole();
  111.     kolo.obwod();
  112.  
  113.     delete tab;
  114.  
  115.     system("pause");
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement