Advertisement
Guest User

Untitled

a guest
Dec 6th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.54 KB | None | 0 0
  1. //----------------KLASA TFORM1-----------------------------------
  2.  
  3. #ifndef Unit1H
  4. #define Unit1H
  5.  
  6. #include <Classes.hpp>
  7. #include <Controls.hpp>
  8. #include <StdCtrls.hpp>
  9. #include <Forms.hpp>
  10. #include <Dialogs.hpp>
  11. #include <ExtCtrls.hpp>
  12. #include <fstream>
  13. #include <vector>
  14.  
  15. using namespace std;
  16.  
  17. class TForm1 : public TForm
  18. {
  19. __published:    // IDE-managed Components
  20.         TRadioButton *RadioButton1;
  21.         TRadioButton *RadioButton2;
  22.         TRadioButton *RadioButton3;
  23.         TButton *Przycisk_Start;
  24.         TButton *Przycisk_Koniec;
  25.         TLabel *Odp1;
  26.         TLabel *Tekst_PodajNazwisko;
  27.         TEdit *Wprowadz_Nazwisko;
  28.         TGroupBox *GroupBox;
  29.         TLabel *Tekst_NumerPytania;
  30.         TEdit *Wyswietl_TrescPytania;
  31.         TLabel *Tekst_Nazwisko;
  32.         TLabel *Tekst_NazwiskoUzytkownika;
  33.         TLabel *Tekst_BladNazwisko;
  34.         TTimer *Timer1;
  35.         TLabel *Label1;
  36.         TLabel *Czas;
  37.         TOpenDialog *OpenDialog1;
  38.         TButton *Przycisk_Wczytaj;
  39.         TButton *Przycisk_Nastepne;
  40.         TButton *Przycisk_SprOdp;
  41.         TButton *Przycisk_Wyjdz;
  42.  
  43.         void __fastcall Przycisk_StartClick(TObject *Sender); // glowna
  44.         void __fastcall Przycisk_KoniecClick(TObject *Sender);
  45.         void __fastcall Timer1Timer(TObject *Sender);
  46.         void __fastcall Przycisk_WczytajClick(TObject *Sender);
  47.         void __fastcall Przycisk_NastepneClick(TObject *Sender);
  48.         void __fastcall Przycisk_WyjdzClick(TObject *Sender);
  49.  
  50.         private:
  51.  
  52.         public:
  53.  
  54.  
  55.         __fastcall TForm1(TComponent* Owner);
  56. };
  57. extern PACKAGE TForm1 *Form1;
  58.  
  59. #endif
  60.  
  61. //---------------------------PLIK WYKONAWCZY KLASY TFORM1-------------------------------
  62.  
  63. #include <vcl.h>
  64. #pragma hdrstop
  65.  
  66. #include "Unit1.h"
  67. #include "Unit2.h"
  68.  
  69. #pragma package(smart_init)
  70. #pragma resource "*.dfm"
  71. TForm1 *Form1;
  72.  
  73. using namespace std;
  74.  
  75. __fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner)
  76. {
  77.         ClientHeight = 100;
  78.         ClientWidth = 320;
  79.         Left = 800;
  80.         Top = 500;
  81.  
  82.         Przycisk_Start -> Left = 180;
  83.         Przycisk_Start -> Top = 64;
  84.         Przycisk_Start -> Height = 25;
  85.         Przycisk_Start -> Width = 130;
  86. }
  87.  
  88. void __fastcall TForm1::Przycisk_WczytajClick(TObject *Sender)
  89. {
  90.         Form2 -> Wczytaj();
  91. }
  92.  
  93. void __fastcall TForm1::Przycisk_StartClick(TObject *Sender)
  94. {
  95.         Form2 -> SprawdzNazwisko();
  96. }
  97.  
  98. void __fastcall TForm1::Przycisk_NastepneClick(TObject *Sender)
  99. {
  100.         Form2 -> NastepnePyt();
  101. }
  102.  
  103. void __fastcall TForm1::Przycisk_KoniecClick(TObject *Sender)
  104. {
  105.         Form2 -> KoniecQ();
  106. }
  107.  
  108. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  109. {
  110.         Form2 -> LiczCzas();
  111. }
  112.  
  113. void __fastcall TForm1::Przycisk_WyjdzClick(TObject *Sender)
  114. {
  115.         Form2 -> WyjdzQ();
  116. }
  117.  
  118.  
  119. //------------ KLASA TFORM2 ---------------------------------
  120. #ifndef Unit2H
  121. #define Unit2H
  122.  
  123. #include <Classes.hpp>
  124. #include <Controls.hpp>
  125. #include <StdCtrls.hpp>
  126. #include <Forms.hpp>
  127. #include <Dialogs.hpp>
  128. #include <ExtCtrls.hpp>
  129. #include <fstream>
  130. #include <vector>
  131.  
  132. using namespace std;
  133.  
  134. class TForm2 : public TForm
  135. {
  136. __published:
  137.  
  138. public:
  139.  
  140.        void __fastcall Wczytaj();
  141.        void __fastcall Wypisz(int nr);
  142.        void __fastcall Sprawdz();
  143.        void __fastcall Zapisz();
  144.        void __fastcall LiczCzas();
  145.        void __fastcall SprawdzNazwisko();
  146.        void __fastcall NastepnePyt();
  147.        void __fastcall KoniecQ();
  148.        void __fastcall WyjdzQ();
  149.  
  150.        string Linia, Tresc, A, B, C, Poprawna, Odpowiedz;
  151.        int nr_pytania, punkt, czas;
  152.        vector < string > tab;
  153.  
  154.         __fastcall TForm2(TComponent* Owner);
  155.  
  156. private:
  157.  
  158.  
  159. };
  160. extern PACKAGE TForm2 *Form2;
  161.  
  162. #endif
  163.  
  164. //-------------PLIK WYKONAWCZY KLASY TFORM2--------------
  165. #include <vcl.h>
  166. #pragma hdrstop
  167.  
  168. #include "Unit1.h"
  169. #include "Unit2.h"
  170.  
  171. #pragma package(smart_init)
  172. #pragma resource "*.dfm"
  173.  
  174. TForm2 *Form2;
  175.  
  176. using namespace std;
  177.  
  178. __fastcall TForm2::TForm2(TComponent* Owner):TForm(Owner)
  179. {
  180.  
  181. }
  182.  
  183.  
  184. void __fastcall TForm2::Wczytaj()
  185. {
  186.         if (Form1 -> OpenDialog1 -> Execute())
  187.         {
  188.                 ifstream plik (Form1 -> OpenDialog1 -> FileName.c_str());
  189.                 if (plik.good() == false)
  190.                 {
  191.                         ShowMessage("Błąd. Wskaż prawidłowy plik!");
  192.                 }
  193.                 else {
  194.                         while (getline(plik, Linia)) tab.push_back(Linia);
  195.                         plik.close();
  196.                         Form1 -> Tekst_BladNazwisko -> Caption = "Plik wczytano poprawnie!";
  197.                         Form1 -> Przycisk_Start -> Enabled = true;
  198.                 }
  199.         }
  200. }
  201.  
  202. void __fastcall TForm2::SprawdzNazwisko()
  203. {
  204.        Form1 -> Wprowadz_Nazwisko -> Text;
  205.        int dlugosc = Form1 -> Wprowadz_Nazwisko -> Text.Length();
  206.  
  207.        if((Form1 -> Wprowadz_Nazwisko -> Text == "") || (dlugosc < 3))
  208.        {
  209.                 Form1 -> Tekst_BladNazwisko -> Caption = "Nazwisko musi miec min. 3 litery!";
  210.        }
  211.        else
  212.        {
  213.                 ClientHeight = 327;
  214.                 ClientWidth = 534;
  215.                 Form1 -> Left = 650;
  216.                 Form1 -> Top = 300;
  217.  
  218.                 Form1 -> Tekst_PodajNazwisko -> Visible = false;
  219.                 Form1 -> Wprowadz_Nazwisko -> Visible = false;
  220.                 Form1 -> Przycisk_Wczytaj -> Visible = false;
  221.                 Form1 -> Przycisk_Start -> Visible = false;
  222.  
  223.                 Form1 -> Tekst_NumerPytania -> Visible = true;
  224.                 Form1 -> Przycisk_Koniec -> Visible = true;
  225.  
  226.                 Form1 -> Tekst_NazwiskoUzytkownika -> Caption = Form1 -> Wprowadz_Nazwisko -> Text.c_str();
  227.                 Form1 -> Timer1 -> Enabled = true;
  228.  
  229.                 Form1 -> Tekst_NumerPytania -> Caption = "Pytanie nr 1";
  230.                 Form1 -> Wyswietl_TrescPytania -> Visible = true;
  231.                 Form1 -> GroupBox     -> Visible = true;
  232.                 Form1 -> RadioButton1 -> Visible = true;
  233.                 Form1 -> RadioButton2 -> Visible = true;
  234.                 Form1 -> RadioButton3 -> Visible = true;
  235.                 Wypisz(Form2 -> nr_pytania);
  236.                 nr_pytania++;
  237.  
  238.        }
  239. }
  240.  
  241. void __fastcall TForm2::NastepnePyt()
  242. {
  243.                 Sprawdz();
  244.                 Wypisz(nr_pytania);
  245.                 if(nr_pytania == 10) Form1 -> Przycisk_Nastepne -> Enabled = false;
  246.                 nr_pytania++;
  247. }
  248.  
  249. void __fastcall TForm2::KoniecQ()
  250. {
  251.         Sprawdz();
  252.         Form1 -> Timer1 -> Enabled = false;
  253.         Form1 -> Przycisk_Nastepne -> Enabled = false;
  254.         Form1 -> Przycisk_SprOdp -> Enabled = true;
  255.         Form1 -> Przycisk_Koniec -> Visible = false;
  256.         Form1 -> Przycisk_Wyjdz -> Visible = true;
  257.         AnsiString Wynik = "Ukończyłes quiz w ";
  258.         AnsiString Wynik2 = " sekund. Twoj wynik to: ";
  259.         AnsiString Wynik3 = "/10";
  260.         ShowMessage(Wynik + czas + Wynik2 + punkt + Wynik3);
  261.         Zapisz();
  262. }
  263.  
  264. void __fastcall TForm2::WyjdzQ()
  265. {
  266.         Application -> Terminate();
  267. }
  268.  
  269. void __fastcall TForm2::Wypisz(int nr)
  270. {
  271.         int i = (nr - 1) * 5;
  272.         AnsiString Pytanie = "Pytanie nr ";
  273.         Form1 -> Tekst_NumerPytania -> Caption = Pytanie + nr;
  274.  
  275.                 for(i; i < tab.size(); i++)
  276.                 {
  277.                         Form1 -> Wyswietl_TrescPytania -> Text = tab[i].c_str();
  278.                         Form1 -> RadioButton1 -> Caption = tab[i+1].c_str();
  279.                         Form1 -> RadioButton2 -> Caption = tab[i+2].c_str();
  280.                         Form1 -> RadioButton3 -> Caption = tab[i+3].c_str();
  281.                         Form1 -> Odp1 -> Caption = tab[i+4].c_str();
  282.                         break;
  283.                 }
  284.         Form1 -> RadioButton1 -> Checked = false;
  285.         Form1 -> RadioButton2 -> Checked = false;
  286.         Form1 -> RadioButton3 -> Checked = false;
  287. }
  288.  
  289. void __fastcall TForm2::Sprawdz()
  290. {
  291.       if (Form1 -> RadioButton1 -> Checked) Odpowiedz = "A";
  292.       if (Form1 -> RadioButton2 -> Checked) Odpowiedz = "B";
  293.       if (Form1 -> RadioButton3 -> Checked) Odpowiedz = "C";
  294.       if((Form1 -> Odp1 -> Caption == Odpowiedz.c_str()))
  295.       {
  296.                 punkt++;
  297.       }
  298.  
  299. }
  300.  
  301. void __fastcall TForm2::LiczCzas()
  302. {
  303.         czas++;
  304.         Form1 -> Label1 -> Caption = IntToStr(this -> czas);
  305. }
  306.  
  307. void __fastcall TForm2::Zapisz()
  308. {
  309.     fstream zapisz;
  310.     zapisz.open("Wyniki.txt", ios::out | ios::app);
  311.  
  312.     zapisz << "** " << Form1 -> Wprowadz_Nazwisko -> Text.c_str() << ", ukończył quiz w czasie " << czas << " sekund i uzyskał " << punkt << " pkt." << endl;
  313.     zapisz.close();
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement