Advertisement
Talar97

[JPO] Lab09

May 9th, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class samochod{
  8. public:
  9.     int moc;
  10.     int predkosc;
  11.     int cena;
  12.    
  13.     void pobierzDane(){
  14.         cout << "Moc: "; cin >> this->moc;
  15.         cout << "Predkosc: "; cin >> this->predkosc;
  16.         cout << "Cena: "; cin >> this->cena;
  17.     }
  18.    
  19.     void wyswietlDane(){
  20.         cout << "Moc: " << this->moc << endl;
  21.         cout << "Predkosc: " << this->predkosc << endl;
  22.         cout << "Cena: " << this->cena << endl;
  23.     }
  24. };
  25.  
  26. class uczen{
  27. public:
  28.     string imie;
  29.     string nazwisko;
  30.     string klasa;
  31.     string ocena;
  32.    
  33.     void pobierzDane(){
  34.         cout << "Imie: "; cin >> this->imie;
  35.         cout << "Nazwisko: "; cin >> this->nazwisko;
  36.         cout << "Klasa: "; cin >> this->klasa;
  37.         cout << "Ocena: "; cin >> this->ocena;
  38.     }
  39.    
  40.     void wyswietlDane(){
  41.         cout << "Imie: " << this->imie << endl;
  42.         cout << "Nazwisko: " << this->nazwisko << endl;
  43.         cout << "Klasa: " << this->klasa << endl;
  44.         cout << "Ocena: " << this->ocena << endl;
  45.     }
  46. };
  47.  
  48. class prostopadloscian{
  49. private:
  50.     double a, b, h;
  51. public:
  52.     prostopadloscian(double a, double b, double h){
  53.         this->a = a;
  54.         this->b = b;
  55.         this->h = h;
  56.     }
  57.    
  58.     int obliczPole(){
  59.         return this->a * this->b * this->h;
  60.     }
  61.    
  62. };
  63.  
  64. class Rachunek{
  65. private:
  66.     string data;
  67.     double wartosc_netto;
  68.     double wartosc_brutto;
  69.     double podatek;
  70. public:
  71.     Rachunek(){
  72.         this->wczytajDane();
  73.     }
  74.    
  75.     void wczytajDane(){
  76.         cout << "Data :"; cin >> this->data;
  77.         cout << "Wartosc_netto: "; cin >> this->wartosc_netto;
  78.     }
  79.    
  80.     void wyliczPodatek(){
  81.         this->wartosc_brutto = this->wartosc_netto * 1.23;
  82.         this->podatek = this->wartosc_brutto - this->wartosc_netto;
  83.     }
  84.    
  85.     void wyswietl(){
  86.         cout << "Data: " << this->data << endl;
  87.         cout << "Wartosc netto: " << this->wartosc_netto << endl;
  88.         cout << "Wartosc brutto: " << this->wartosc_brutto << endl;
  89.         cout << "Podatek: " << this->podatek << endl;
  90.     }
  91. };
  92.  
  93. class MyWater{
  94. private:
  95.     int large, medium, small;
  96.     static double l,m,s;
  97. public:
  98.     void addLarge(int num){
  99.         this->large += num;
  100.     }
  101.     void addMedium(int num){
  102.         this->medium += num;
  103.     }
  104.     void addSmall(int num){
  105.         this->small += num;
  106.     }
  107.    
  108.     void set_l(double x){
  109.         this->l = x;
  110.     }
  111.     void set_m(double x){
  112.         this->m = x;
  113.     }
  114.     void set_s(double x){
  115.         this->s = x;
  116.     }
  117.    
  118.     void wyswietlDane(){
  119.         double suma = (this->large * this->l) + (this->medium * this->m) + (this->small * this->s);
  120.        
  121.         cout << "Mam teraz " << suma << " litrow wody" << endl;
  122.         cout << "Duzych butelek: " << this->large << endl;
  123.         cout << "Srednich butelek: " << this->medium << endl;
  124.         cout << "Malych butelek: " << this->small << endl;
  125.     }
  126. };
  127.  
  128. double MyWater::l = 2;
  129. double MyWater::m = 1;
  130. double MyWater::s = 0.5;
  131.  
  132.  
  133. class osoba{
  134. private:
  135.     string imie;
  136.     string nazwisko;
  137.     string adres;
  138.     string gg;
  139.     string email;
  140.    
  141. public:
  142.     osoba(string imie, string nazwisko, string adres, string gg, string email){
  143.         this->imie = imie;
  144.         this->nazwisko = nazwisko;
  145.         this->adres = adres;
  146.         this->gg = gg;
  147.         this->email = email;
  148.     }
  149.    
  150.     osoba(){
  151.         this->ustawDane();
  152.     }
  153.    
  154.     void wyswietlDane(){
  155.         cout << "-------" << endl;
  156.         cout << "Imie: " << this->imie << endl;
  157.         cout << "Nazwisko: " << this->nazwisko << endl;
  158.         cout << "Adres: " << this->adres << endl;
  159.         cout << "GG (opcjonalne): " << this->gg << endl;
  160.         cout << "Email (opcjonalne): " << this->email << endl;
  161.         cout << "-------" << endl;
  162.     }
  163.    
  164.     void wyswietlDaneSkrotowo(){
  165.         cout << this->imie << ", " << this->nazwisko << ", " << this->adres << endl;
  166.     }
  167.    
  168.     void ustawDane(){
  169.         cout << "Imie: "; cin >> this->imie;
  170.         cout << "Nazwisko: "; cin >> this->nazwisko;
  171.         cout << "Adres: "; cin >> this->adres;
  172.         cout << "GG (opcjonalne): "; cin >> this->gg;
  173.         cout << "Email (opcjonalne): "; cin >> this->email;
  174.     }
  175. };
  176.  
  177. class KsiazkaAdresowa{
  178. private:
  179.     vector < osoba > listaOsob;
  180. public:
  181.     void dodajNowaOsobe(){
  182.         osoba czlowiek;
  183.         listaOsob.push_back(czlowiek);
  184.     }
  185.    
  186.     void wyswietlWszystkich(){
  187.         for(int i = 0; i < listaOsob.size(); i++){
  188.             cout << "UID: " << i+1 << ":" << endl;
  189.             listaOsob[i].wyswietlDane();
  190.         }
  191.     }
  192.    
  193.     void wyswietlWszystkichSkrotowo(){
  194.         for(int i = 0; i < listaOsob.size(); i++){
  195.             cout << "UID: " << i+1 << ": ";
  196.             listaOsob[i].wyswietlDaneSkrotowo();
  197.         }
  198.     }
  199.    
  200.     void menu(){
  201.         int x;
  202.         cout << "> Wybierz opcje: " << endl;
  203.         cout << ">> 1 - Dodaj nowa osobe " << endl;
  204.         cout << ">> 2 - Edytuj/Usun osobe " << endl;
  205.         cout << ">> 3 - Wyszukaj osoby " << endl;
  206.         cout << ">> 4 - Wyswietl wszystkie osoby " << endl;
  207.         cout << ">> 5 - Import z pliku " << endl;
  208.         cout << ">> 6 - Eksport do pliku " << endl;
  209.         cout << ">> 7 - Wyjscie " << endl;
  210.         cout << "->"; cin >> x;
  211.         switch(x){
  212.             case 1:
  213.             {
  214.                 this->dodajNowaOsobe();
  215.                 this->menu();
  216.                 break;
  217.             }
  218.             case 2:
  219.             {
  220.                 int x, uid;
  221.                 this->wyswietlWszystkichSkrotowo();
  222.                 cout << "Wprowadz uid: "; cin >> uid;
  223.                 cout << "1 - usun" << endl << "2 - modyfikuj";
  224.                 cin >> x;
  225.                
  226.                 if(x==1){
  227.                     string y;
  228.                     cout << "Jestes pewny? T/N"; cin >> y;
  229.                     if(y=="T") {
  230.                         listaOsob.erase(listaOsob.begin()+(uid-1));
  231.                         cout << "!!!Pomyslnie usunieto osobe z ksiazki" << endl;
  232.                     }
  233.                 }
  234.                 else if(x==2) listaOsob[uid-1].ustawDane();
  235.                
  236.                 this->menu();
  237.                 break;
  238.             }
  239.             case 3:
  240.             {
  241.                
  242.                 this->menu();
  243.                 break;
  244.             }
  245.             case 4:
  246.             {
  247.                 this->wyswietlWszystkich();
  248.                 this->menu();
  249.                 break;
  250.             }
  251.             case 7:
  252.             {
  253.                 break;
  254.             }
  255.             default:
  256.             {
  257.                 this->menu();
  258.             }
  259.         }
  260.     }
  261.    
  262.     KsiazkaAdresowa(){
  263.         this->menu();
  264.     }
  265. };
  266.  
  267.  
  268. //Prototypy
  269. void WyborZadania();
  270.  
  271. int main() {
  272.     WyborZadania();
  273.     return EXIT_SUCCESS;
  274. }
  275.  
  276. void WyborZadania(){
  277.     int zad;
  278.     cout << "Wybierz zadanie: ";
  279.     cin >> zad;
  280.     switch(zad){
  281.         case 1:
  282.         {
  283.             samochod x;
  284.             x.pobierzDane();
  285.             x.wyswietlDane();
  286.             break;
  287.         }
  288.         case 2:
  289.         {
  290.             uczen y;
  291.             y.pobierzDane();
  292.             y.wyswietlDane();
  293.             break;
  294.         }
  295.         case 3:
  296.         {
  297.             prostopadloscian box(2,3,4);
  298.             cout << "Pole prostopadloscianu: " << box.obliczPole();
  299.             break;
  300.         }
  301.         case 4:
  302.         {
  303.             Rachunek z;
  304.             z.wyliczPodatek();
  305.             z.wyswietl();
  306.             break;
  307.         }
  308.         case 5:
  309.         {
  310.             MyWater q;
  311.             q.addLarge(5);
  312.             q.addMedium(4);
  313.             q.addSmall(2);
  314.             q.wyswietlDane();
  315.            
  316.             q.set_l(5);
  317.             q.wyswietlDane();
  318.             break;
  319.         }
  320.         case 6:
  321.         {
  322.             KsiazkaAdresowa facebook;
  323.         }
  324.         default:
  325.         {
  326.           WyborZadania();
  327.           break;  
  328.         }    
  329.     }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement