Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------KLASA TFORM1-----------------------------------
- #ifndef Unit1H
- #define Unit1H
- #include <Classes.hpp>
- #include <Controls.hpp>
- #include <StdCtrls.hpp>
- #include <Forms.hpp>
- #include <Dialogs.hpp>
- #include <ExtCtrls.hpp>
- #include <fstream>
- #include <vector>
- using namespace std;
- class TForm1 : public TForm
- {
- __published: // IDE-managed Components
- TRadioButton *RadioButton1;
- TRadioButton *RadioButton2;
- TRadioButton *RadioButton3;
- TButton *Przycisk_Start;
- TButton *Przycisk_Koniec;
- TLabel *Odp1;
- TLabel *Tekst_PodajNazwisko;
- TEdit *Wprowadz_Nazwisko;
- TGroupBox *GroupBox;
- TLabel *Tekst_NumerPytania;
- TEdit *Wyswietl_TrescPytania;
- TLabel *Tekst_Nazwisko;
- TLabel *Tekst_NazwiskoUzytkownika;
- TLabel *Tekst_BladNazwisko;
- TTimer *Timer1;
- TLabel *Label1;
- TLabel *Czas;
- TOpenDialog *OpenDialog1;
- TButton *Przycisk_Wczytaj;
- TButton *Przycisk_Nastepne;
- TButton *Przycisk_SprOdp;
- TButton *Przycisk_Wyjdz;
- void __fastcall Przycisk_StartClick(TObject *Sender); // glowna
- void __fastcall Przycisk_KoniecClick(TObject *Sender);
- void __fastcall Timer1Timer(TObject *Sender);
- void __fastcall Przycisk_WczytajClick(TObject *Sender);
- void __fastcall Przycisk_NastepneClick(TObject *Sender);
- void __fastcall Przycisk_WyjdzClick(TObject *Sender);
- private:
- public:
- __fastcall TForm1(TComponent* Owner);
- };
- extern PACKAGE TForm1 *Form1;
- #endif
- //---------------------------PLIK WYKONAWCZY KLASY TFORM1-------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- #include "Unit2.h"
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- using namespace std;
- __fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner)
- {
- ClientHeight = 100;
- ClientWidth = 320;
- Left = 800;
- Top = 500;
- Przycisk_Start -> Left = 180;
- Przycisk_Start -> Top = 64;
- Przycisk_Start -> Height = 25;
- Przycisk_Start -> Width = 130;
- }
- void __fastcall TForm1::Przycisk_WczytajClick(TObject *Sender)
- {
- Form2 -> Wczytaj();
- }
- void __fastcall TForm1::Przycisk_StartClick(TObject *Sender)
- {
- Form2 -> SprawdzNazwisko();
- }
- void __fastcall TForm1::Przycisk_NastepneClick(TObject *Sender)
- {
- Form2 -> NastepnePyt();
- }
- void __fastcall TForm1::Przycisk_KoniecClick(TObject *Sender)
- {
- Form2 -> KoniecQ();
- }
- void __fastcall TForm1::Timer1Timer(TObject *Sender)
- {
- Form2 -> LiczCzas();
- }
- void __fastcall TForm1::Przycisk_WyjdzClick(TObject *Sender)
- {
- Form2 -> WyjdzQ();
- }
- //------------ KLASA TFORM2 ---------------------------------
- #ifndef Unit2H
- #define Unit2H
- #include <Classes.hpp>
- #include <Controls.hpp>
- #include <StdCtrls.hpp>
- #include <Forms.hpp>
- #include <Dialogs.hpp>
- #include <ExtCtrls.hpp>
- #include <fstream>
- #include <vector>
- using namespace std;
- class TForm2 : public TForm
- {
- __published:
- public:
- void __fastcall Wczytaj();
- void __fastcall Wypisz(int nr);
- void __fastcall Sprawdz();
- void __fastcall Zapisz();
- void __fastcall LiczCzas();
- void __fastcall SprawdzNazwisko();
- void __fastcall NastepnePyt();
- void __fastcall KoniecQ();
- void __fastcall WyjdzQ();
- string Linia, Tresc, A, B, C, Poprawna, Odpowiedz;
- int nr_pytania, punkt, czas;
- vector < string > tab;
- __fastcall TForm2(TComponent* Owner);
- private:
- };
- extern PACKAGE TForm2 *Form2;
- #endif
- //-------------PLIK WYKONAWCZY KLASY TFORM2--------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- #include "Unit2.h"
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm2 *Form2;
- using namespace std;
- __fastcall TForm2::TForm2(TComponent* Owner):TForm(Owner)
- {
- }
- void __fastcall TForm2::Wczytaj()
- {
- if (Form1 -> OpenDialog1 -> Execute())
- {
- ifstream plik (Form1 -> OpenDialog1 -> FileName.c_str());
- if (plik.good() == false)
- {
- ShowMessage("Błąd. Wskaż prawidłowy plik!");
- }
- else {
- while (getline(plik, Linia)) tab.push_back(Linia);
- plik.close();
- Form1 -> Tekst_BladNazwisko -> Caption = "Plik wczytano poprawnie!";
- Form1 -> Przycisk_Start -> Enabled = true;
- }
- }
- }
- void __fastcall TForm2::SprawdzNazwisko()
- {
- Form1 -> Wprowadz_Nazwisko -> Text;
- int dlugosc = Form1 -> Wprowadz_Nazwisko -> Text.Length();
- if((Form1 -> Wprowadz_Nazwisko -> Text == "") || (dlugosc < 3))
- {
- Form1 -> Tekst_BladNazwisko -> Caption = "Nazwisko musi miec min. 3 litery!";
- }
- else
- {
- ClientHeight = 327;
- ClientWidth = 534;
- Form1 -> Left = 650;
- Form1 -> Top = 300;
- Form1 -> Tekst_PodajNazwisko -> Visible = false;
- Form1 -> Wprowadz_Nazwisko -> Visible = false;
- Form1 -> Przycisk_Wczytaj -> Visible = false;
- Form1 -> Przycisk_Start -> Visible = false;
- Form1 -> Tekst_NumerPytania -> Visible = true;
- Form1 -> Przycisk_Koniec -> Visible = true;
- Form1 -> Tekst_NazwiskoUzytkownika -> Caption = Form1 -> Wprowadz_Nazwisko -> Text.c_str();
- Form1 -> Timer1 -> Enabled = true;
- Form1 -> Tekst_NumerPytania -> Caption = "Pytanie nr 1";
- Form1 -> Wyswietl_TrescPytania -> Visible = true;
- Form1 -> GroupBox -> Visible = true;
- Form1 -> RadioButton1 -> Visible = true;
- Form1 -> RadioButton2 -> Visible = true;
- Form1 -> RadioButton3 -> Visible = true;
- Wypisz(Form2 -> nr_pytania);
- nr_pytania++;
- }
- }
- void __fastcall TForm2::NastepnePyt()
- {
- Sprawdz();
- Wypisz(nr_pytania);
- if(nr_pytania == 10) Form1 -> Przycisk_Nastepne -> Enabled = false;
- nr_pytania++;
- }
- void __fastcall TForm2::KoniecQ()
- {
- Sprawdz();
- Form1 -> Timer1 -> Enabled = false;
- Form1 -> Przycisk_Nastepne -> Enabled = false;
- Form1 -> Przycisk_SprOdp -> Enabled = true;
- Form1 -> Przycisk_Koniec -> Visible = false;
- Form1 -> Przycisk_Wyjdz -> Visible = true;
- AnsiString Wynik = "Ukończyłes quiz w ";
- AnsiString Wynik2 = " sekund. Twoj wynik to: ";
- AnsiString Wynik3 = "/10";
- ShowMessage(Wynik + czas + Wynik2 + punkt + Wynik3);
- Zapisz();
- }
- void __fastcall TForm2::WyjdzQ()
- {
- Application -> Terminate();
- }
- void __fastcall TForm2::Wypisz(int nr)
- {
- int i = (nr - 1) * 5;
- AnsiString Pytanie = "Pytanie nr ";
- Form1 -> Tekst_NumerPytania -> Caption = Pytanie + nr;
- for(i; i < tab.size(); i++)
- {
- Form1 -> Wyswietl_TrescPytania -> Text = tab[i].c_str();
- Form1 -> RadioButton1 -> Caption = tab[i+1].c_str();
- Form1 -> RadioButton2 -> Caption = tab[i+2].c_str();
- Form1 -> RadioButton3 -> Caption = tab[i+3].c_str();
- Form1 -> Odp1 -> Caption = tab[i+4].c_str();
- break;
- }
- Form1 -> RadioButton1 -> Checked = false;
- Form1 -> RadioButton2 -> Checked = false;
- Form1 -> RadioButton3 -> Checked = false;
- }
- void __fastcall TForm2::Sprawdz()
- {
- if (Form1 -> RadioButton1 -> Checked) Odpowiedz = "A";
- if (Form1 -> RadioButton2 -> Checked) Odpowiedz = "B";
- if (Form1 -> RadioButton3 -> Checked) Odpowiedz = "C";
- if((Form1 -> Odp1 -> Caption == Odpowiedz.c_str()))
- {
- punkt++;
- }
- }
- void __fastcall TForm2::LiczCzas()
- {
- czas++;
- Form1 -> Label1 -> Caption = IntToStr(this -> czas);
- }
- void __fastcall TForm2::Zapisz()
- {
- fstream zapisz;
- zapisz.open("Wyniki.txt", ios::out | ios::app);
- zapisz << "** " << Form1 -> Wprowadz_Nazwisko -> Text.c_str() << ", ukończył quiz w czasie " << czas << " sekund i uzyskał " << punkt << " pkt." << endl;
- zapisz.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement