Facebook
From Wet Hummingbird, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 227
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <exception>
  4. #include <fstream>
  5. #include <time.h>
  6. using namespace std;
  7.  
  8. class brak_danych : public exception {
  9.         const char* what() const throw() {
  10.                 return "brak danych";
  11.         }
  12. };
  13.  
  14. class blad_pliku : public exception {
  15.         const char* what() const throw() {
  16.                 return "blad pliku";
  17.         }
  18. };
  19.  
  20. class za_malo_obecnosci : public exception {
  21.         const char* what() const throw() {
  22.                 return "ponizej polowy obecnosci";
  23.         }
  24. };
  25.  
  26. class brak_danych_osobowych : public exception {
  27.         const char* what() const throw() {
  28.                 return "brak danych osobowych";
  29.         }
  30. };
  31.  
  32. class Student {
  33. public:
  34.         string Dane_osobowe;
  35.         int* punkty;
  36.         bool* obecnosci;
  37.         double OcenaKoncowa;
  38.         int ObliczOcene() {
  39.                 int ile_nieob = 0;
  40.                 for (int i = 0; i < 10; i++) {
  41.                         if (obecnosci[i] == 0)ile_nieob++;
  42.                 }
  43.                 if (ile_nieob >= 5) {
  44.                         throw za_malo_obecnosci();
  45.                 }
  46.                 else {
  47.                         cout << "Powyzej polowy obecnosci" << endl;
  48.                         OcenaKoncowa = punkty[0];
  49.                 }
  50.         }
  51.         void Wypisz() {
  52.                 if (OcenaKoncowa == 0) {
  53.                         throw brak_danych();
  54.                 }
  55.                 else {
  56.                         cout << "Ocena: " << OcenaKoncowa<<endl;
  57.                 }
  58.                 if (Dane_osobowe == "") {
  59.                         throw brak_danych_osobowych();
  60.                 }
  61.         }
  62.         void EksportDoPlikuCSV() {
  63.                 fstream plik;
  64.                 plik.open("nazwa_pliku.xlsx", ios::out | ios::in);
  65.                 if (plik.good() == false) {
  66.                         throw blad_pliku();
  67.                 }
  68.                 else cout << "Uzyskano dostep" << endl;
  69.         }
  70.         Student::Student() {
  71.  
  72.         }
  73.         Student::Student(int i){
  74.                 OcenaKoncowa = 0;
  75.                 obecnosci = new bool[10];
  76.                 for (int i = 0; i < 10; i++) {
  77.                 obecnosci[i] = rand() % 2;
  78.                 }
  79.                 punkty = new int[1];
  80.                 punkty[0] = rand() % 3 + 3;
  81.                 Dane_osobowe = "";
  82.         }
  83. };
  84.  
  85. class Grupa {
  86.         Student*tablicaStudentow;
  87.         Grupa::Grupa(){
  88.                
  89.                 tablicaStudentow = new Student[10];
  90.         }
  91. };
  92.  
  93.  
  94. int main()
  95. {
  96.         srand(time(NULL));
  97.         Student ja(0);
  98.        
  99.        
  100.         try { ja.Wypisz(); }
  101.         catch (exception& e) {
  102.                 cerr << "exception caught: " << e.what() << endl;
  103.         }
  104.         try { ja.EksportDoPlikuCSV(); }
  105.         catch (exception& e) {
  106.                 cerr << "exception caught: " << e.what() << endl;
  107.         }
  108.         try { ja.ObliczOcene(); }
  109.         catch (exception& e) {
  110.                 cerr << "exception caught: " << e.what() << endl;
  111.         }
  112.         try { ja.Wypisz(); }
  113.         catch (exception& e) {
  114.                 cerr << "exception caught: " << e.what() << endl;
  115.         }
  116.         system("pause");
  117.     return 0;
  118. }
  119.  
  120.