Advertisement
Talar97

[JPO] Lab10

May 29th, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.77 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Uczen{
  8. public:
  9.     string imie;
  10.     char nazwisko[20];
  11.     long pesel;
  12.    
  13.     void ustawImie(){
  14.         cout << "Imie: "; cin >> this->imie;
  15.     }
  16.    
  17.     void ustawNazwisko(){
  18.         cout << "Nazwisko: "; cin >> this->nazwisko;
  19.     }
  20.    
  21.     void ustawPesel(){
  22.         cout << "Pesel: "; cin >> this->pesel;
  23.     }
  24.    
  25. };
  26.  
  27. class UczenSzkoly : public Uczen{
  28. public:
  29.     string nazwaSzkoly;
  30.    
  31.     void ustawSzkole(){
  32.         cout << "Nazwa szkoly: "; cin >> this->nazwaSzkoly;
  33.     }
  34. };
  35.  
  36.  
  37. //Niedokonczone//
  38. class Figure{
  39.     //Metoda do definiowania najwiekszego obwodu
  40. };
  41.  
  42. class Triangle : Figure{
  43.    
  44. };
  45.  
  46. class Circle : Figure{
  47.    
  48. };
  49.  
  50. class Figures{
  51.     //Klasa ma przechowywac wiele obiektow klasy Figure
  52.     //Szukac figury z najwiekszym obwodem
  53. };
  54. //-------//
  55.  
  56.  
  57. class Przedmiot{
  58. private:
  59.     double * oceny;
  60.     int nr_indeksu;
  61.     int liczba_ocen;
  62.     int limit;
  63. public:
  64.     Przedmiot(int nr_ind, int lim){
  65.         this->nr_indeksu = nr_ind;
  66.         this->limit = lim;
  67.         this->oceny = new double[this->limit];
  68.         this->liczba_ocen = 0;
  69.        
  70.         for(int i = 0; i < this->limit; i++){
  71.             this->oceny[i] = 0;
  72.         }
  73.     }
  74.    
  75.     ~Przedmiot(){
  76.             delete [] oceny;
  77.      }
  78.    
  79.     double obliczSrednia(){
  80.         double suma = 0;
  81.         this->liczba_ocen = 0;
  82.         for(int i = 0; i < this->limit; i++){
  83.             if(this->oceny[i] != 0){
  84.                 suma += this->oceny[i];
  85.                 this->liczba_ocen++;
  86.             }
  87.         }
  88.        
  89.         return (suma/this->liczba_ocen);
  90.     }
  91.    
  92.     bool zaliczenie(){
  93.         if(this->obliczSrednia() > 3) return true;
  94.         else return false;
  95.     }
  96.    
  97.     void dodajOcene(double ocena){
  98.         this->oceny[this->liczba_ocen] = ocena;
  99.         this->liczba_ocen++;
  100.     }
  101.    
  102.     void zmienOcene(int indeks, double nowaOcena){
  103.         this->oceny[indeks] = nowaOcena;
  104.     }
  105.    
  106.     void wypisz(){
  107.         cout << "Nr indeksu: " << this->nr_indeksu << endl;
  108.         cout << "Srednia: " << this->obliczSrednia() << ", zaliczenie: " << this->zaliczenie() << endl;
  109.         cout << "Oceny: ";
  110.        
  111.        
  112.         for(int i = 0; i < this->limit; i++){
  113.             if(this->oceny[i] != 0){
  114.                 cout << this->oceny[i] << ", ";
  115.             }
  116.         }
  117.     }
  118.    
  119. };
  120.  
  121. int Zad4(string cluster){
  122.     char x[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R'};
  123.    
  124.     string modul = cluster.substr(cluster.length()-1, cluster.length());
  125.     int dl = sizeof(x)/sizeof(x[0]);
  126.     int wynik = -1;
  127.    
  128.     for(int i = 0; i < dl; i++){
  129.         if(modul[0] == x[i]) wynik = i;
  130.     }
  131.    
  132.     return wynik;
  133. }
  134.  
  135. //Prototypy
  136. void WyborZadania();
  137.  
  138. int main() {
  139.     WyborZadania();
  140.     return EXIT_SUCCESS;
  141. }
  142.  
  143. void WyborZadania(){
  144.     int zad;
  145.     cout << "Wybierz zadanie: ";
  146.     cin >> zad;
  147.     switch(zad){
  148.         case 1:
  149.         {  
  150.             UczenSzkoly osoba;
  151.             osoba.ustawImie();
  152.             osoba.ustawNazwisko();
  153.             osoba.ustawPesel();
  154.             osoba.ustawSzkole();
  155.             break;
  156.         }
  157.         case 2:
  158.         {
  159.             cout << "Nie chce mi sie";
  160.             break;
  161.         }
  162.         case 3:
  163.         {
  164.             Przedmiot inf(1122, 20);
  165.             inf.dodajOcene(5);
  166.             inf.dodajOcene(3);
  167.             inf.dodajOcene(2);
  168.             inf.zmienOcene(0,2);
  169.             inf.wypisz();
  170.             break;
  171.         }
  172.         case 4:
  173.         {
  174.             cout << Zad4("Cluster_M");
  175.             break;
  176.         }
  177.         default:
  178.         {
  179.           WyborZadania();
  180.           break;  
  181.         }    
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement