Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Frysk Leare Lieder source code (version 1.0)

 

Frysk Leare Lieder version 1.0 source code. Due to many Frysian characters, this page is not XHTML 1.0 conform.

 

Operating system: Windows XP

IDE: C++ Builder 6.0 Enterprise Edition

Project type: GUI application

Compiler: supplied with C++ Builder 6.0 Enterprise Edition

Libraries used:

 

 

 

 

 

ProjectFryskLeareLieder.cpp

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("UnitFormMain.cpp", FormMain);
USEFORM("UnitFormCorrect.cpp", FormCorrect);
USEFORM("UnitFormIncorrect.cpp", FormIncorrect);
USEFORM("UnitFormAbout.cpp", FormAbout);
USEFORM("UnitFormOptions.cpp", FormOptions);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Title = "Frysk Leare Lieder";
                 Application->CreateForm(__classid(TFormMain), &FormMain);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormAbout.cpp

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormAbout *FormAbout;
//---------------------------------------------------------------------------
__fastcall TFormAbout::TFormAbout(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormAbout::Image1Click(TObject *Sender)
{
  Close();        
}
//---------------------------------------------------------------------------

void __fastcall TFormAbout::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  Close();        
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormAbout.h

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#ifndef UnitFormAboutH
#define UnitFormAboutH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormAbout : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label6;
        TPanel *Panel1;
        TPanel *Panel2;
        TLabel *Label5;
        void __fastcall Image1Click(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
        __fastcall TFormAbout(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormAbout *FormAbout;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormCorrect.cpp

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormCorrect.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormCorrect *FormCorrect;
//---------------------------------------------------------------------------
__fastcall TFormCorrect::TFormCorrect(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormCorrect::Image2MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormCorrect::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  Close();        
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormCorrect.h

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#ifndef UnitFormCorrectH
#define UnitFormCorrectH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TFormCorrect : public TForm
{
__published: // IDE-managed Components
        TImage *Image2;
        TImage *Image1;
        void __fastcall Image2MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
        __fastcall TFormCorrect(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormCorrect *FormCorrect;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormIncorrect.cpp

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormIncorrect.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormIncorrect *FormIncorrect;
//---------------------------------------------------------------------------
__fastcall TFormIncorrect::TFormIncorrect(TComponent* Owner,
          const std::vector<std::string>& answers)
        : TForm(Owner)
{
  const int nAnswers = answers.size();
  for (int i=0; i<nAnswers; ++i)
  {
    RichEdit1->Lines->Add(answers[i].c_str());

  }
}
//---------------------------------------------------------------------------
void __fastcall TFormIncorrect::RichEdit1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  Close();        
}
//---------------------------------------------------------------------------
void __fastcall TFormIncorrect::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  Close();        
}
//---------------------------------------------------------------------------

 

 

 

 

 

UnitFormIncorrect.h

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#ifndef UnitFormIncorrectH
#define UnitFormIncorrectH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
#include <vector>
#include <string>
//---------------------------------------------------------------------------
class TFormIncorrect : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TImage *Image2;
        TRichEdit *RichEdit1;
        void __fastcall RichEdit1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
private: // User declarations
public: // User declarations
        __fastcall TFormIncorrect(TComponent* Owner,
          const std::vector<std::string>& answers);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormIncorrect *FormIncorrect;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormMain.cpp

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormMain.h"
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include <memory>
#include <cassert>
#include "UnitFormCorrect.h"
#include "UnitFormIncorrect.h"
#include "UnitFormAbout.h"
#include "UnitFormOptions.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner)
        : TForm(Owner), mQuestionGenerator(new QuestionGenerator(std::set<QuestionType>()))
{
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::LabeledEdit1Enter(TObject *Sender)
{
  //User presses enter

}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
  TFormOptions::SetDefaultOptions();
  mQuestionGenerator.reset(new QuestionGenerator(TFormOptions::mOptions));
  DrawScreen();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ControlAnswerKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  if (Key == VK_RETURN)
  {
    const bool isCorrect = mQuestionGenerator->GiveAnswer(ControlAnswer->Text.c_str());
    if (isCorrect)
    {
      std::auto_ptr<TFormCorrect> formCorrect(new TFormCorrect(0));
      formCorrect->ShowModal();
    }
    else
    {
      const std::vector<std::string> answers = mQuestionGenerator->GetAnswers();
      std::auto_ptr<TFormIncorrect> formIncorrect(new TFormIncorrect(0,answers));
      formIncorrect->ShowModal();
    }
    DrawScreen();
  }
}
//---------------------------------------------------------------------------
void TFormMain::DrawScreen()
{
  const std::string question = mQuestionGenerator->GetQuestion();
  ControlQuestion->Caption = question.c_str();
  ControlAnswer->Text = "";
  LabelCorrect->Caption = mQuestionGenerator->GetNcorrect();
  LabelIncorrect->Caption = mQuestionGenerator->GetNincorrect();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::LabelQuitClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormMain::LabelAboutClick(TObject *Sender)
{
  std::auto_ptr<TFormAbout> formAbout(new TFormAbout(0));
  formAbout->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::LabelOptionsClick(TObject *Sender)
{
  std::auto_ptr<TFormOptions> formOptions(new TFormOptions(0));
  formOptions->ShowModal();
  //Reset the Question Generator options
  mQuestionGenerator.reset(new QuestionGenerator(TFormOptions::mOptions));
  DrawScreen();

}
//---------------------------------------------------------------------------

void __fastcall TFormMain::ImageLetterSirconflexMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  const int letterIndex = (Y * 5) / ImageLetterSirconflex->Height;
  String s = "";
  switch (letterIndex)
  {
    case 0: s = " "; break;
    case 1: s = " "; break;
    case 2: s = " "; break;
    case 3: s = " "; break;
    case 4: s = " "; break;
    default: assert(!"Should not get here"); break;
  }
  ControlAnswer->Text = ControlAnswer->Text + s;
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormMain.h

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#ifndef UnitFormMainH
#define UnitFormMainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
#include <memory>
#include "UnitQuestionGenerator.h"
//---------------------------------------------------------------------------
class TFormMain : public TForm
{
__published: // IDE-managed Components
        TImage *Image1;
        TImage *Image2;
        TEdit *ControlAnswer;
        TImage *ImageLetterSirconflex;
        TStaticText *ControlQuestion;
        TPanel *PanelBottom;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *LabelCorrect;
        TLabel *LabelIncorrect;
        TLabel *LabelAbout;
        TLabel *LabelQuit;
        TLabel *Label3;
        TImage *Image4;
        TImage *Image5;
        TImage *Image6;
        void __fastcall LabeledEdit1Enter(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall ControlAnswerKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall LabelQuitClick(TObject *Sender);
        void __fastcall LabelAboutClick(TObject *Sender);
        void __fastcall LabelOptionsClick(TObject *Sender);
        void __fastcall ImageLetterSirconflexMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
private: // User declarations
        std::auto_ptr<QuestionGenerator> mQuestionGenerator;
        void DrawScreen();
public: // User declarations
        __fastcall TFormMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormMain *FormMain;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitFormOptions.cpp

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "UnitFormOptions.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormOptions *FormOptions;
//---------------------------------------------------------------------------
#include <cassert>
std::set<QuestionType> TFormOptions::mOptions;
//---------------------------------------------------------------------------
__fastcall TFormOptions::TFormOptions(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormOptions::ImageDoneClick(TObject *Sender)
{
  Close();        
}
//---------------------------------------------------------------------------
void __fastcall TFormOptions::ImageVerbEasyClick(TObject *Sender)
{
  ImageVerbEasy->Tag = (ImageVerbEasy->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageVerbEasy->Canvas,0,0,ImageVerbEasy->Tag,true);
  ImageVerbEasy->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TFormOptions::ImageVerbMediumClick(TObject *Sender)
{
  ImageVerbMedium->Tag = (ImageVerbMedium->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageVerbMedium->Canvas,0,0,ImageVerbMedium->Tag,true);
  ImageVerbMedium->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageVerbHardClick(TObject *Sender)
{
  ImageVerbHard->Tag = (ImageVerbHard->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageVerbHard->Canvas,0,0,ImageVerbHard->Tag,true);
  ImageVerbHard->Refresh();
}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageNounEasyClick(TObject *Sender)
{
  ImageNounEasy->Tag = (ImageNounEasy->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageNounEasy->Canvas,0,0,ImageNounEasy->Tag,true);
  ImageNounEasy->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageNounMediumClick(TObject *Sender)
{
  ImageNounMedium->Tag = (ImageNounMedium->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageNounMedium->Canvas,0,0,ImageNounMedium->Tag,true);
  ImageNounMedium->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageNounHardClick(TObject *Sender)
{
  ImageNounHard->Tag = (ImageNounHard->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageNounHard->Canvas,0,0,ImageNounHard->Tag,true);
  ImageNounHard->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageSentenceEasyClick(TObject *Sender)
{
  ImageSentenceEasy->Tag = (ImageSentenceEasy->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageSentenceEasy->Canvas,0,0,ImageSentenceEasy->Tag,true);
  ImageSentenceEasy->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageSentenceMediumClick(TObject *Sender)
{
  ImageSentenceMedium->Tag = (ImageSentenceMedium->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageSentenceMedium->Canvas,0,0,ImageSentenceMedium->Tag,true);
  ImageSentenceMedium->Refresh();
}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::ImageSentenceHardClick(TObject *Sender)
{
  ImageSentenceHard->Tag = (ImageSentenceHard->Tag == 0 ? 1 : 0);
  ImageList->Draw(ImageSentenceHard->Canvas,0,0,ImageSentenceHard->Tag,true);
  ImageSentenceHard->Refresh();
}
//---------------------------------------------------------------------------
void TFormOptions::SetDefaultOptions()
{
  mOptions.clear();
  assert(mOptions.size()==0);
  mOptions.insert(easyVerb);
  mOptions.insert(easyNoun);
  mOptions.insert(easySentence);
}
//---------------------------------------------------------------------------
void __fastcall TFormOptions::FormCreate(TObject *Sender)
{
  ImageVerbEasy->Tag   = ( mOptions.find(easyVerb)   != mOptions.end() ? 1 : 0);
  ImageVerbMedium->Tag = ( mOptions.find(mediumVerb) != mOptions.end() ? 1 : 0);
  ImageVerbHard->Tag   = ( mOptions.find(hardVerb)   != mOptions.end() ? 1 : 0);

  ImageNounEasy->Tag   = ( mOptions.find(easyNoun)   != mOptions.end() ? 1 : 0);
  ImageNounMedium->Tag = ( mOptions.find(mediumNoun) != mOptions.end() ? 1 : 0);
  ImageNounHard->Tag   = ( mOptions.find(hardNoun)   != mOptions.end() ? 1 : 0);

  ImageSentenceEasy->Tag   = ( mOptions.find(easySentence)   != mOptions.end() ? 1 : 0);
  ImageSentenceMedium->Tag = ( mOptions.find(mediumSentence) != mOptions.end() ? 1 : 0);
  ImageSentenceHard->Tag   = ( mOptions.find(hardSentence)   != mOptions.end() ? 1 : 0);

  ImageList->Draw(ImageVerbEasy->Canvas  ,0,0,ImageVerbEasy->Tag  ,true);
  ImageList->Draw(ImageVerbMedium->Canvas,0,0,ImageVerbMedium->Tag,true);
  ImageList->Draw(ImageVerbHard->Canvas  ,0,0,ImageVerbHard->Tag  ,true);
  ImageList->Draw(ImageNounEasy->Canvas  ,0,0,ImageNounEasy->Tag  ,true);
  ImageList->Draw(ImageNounMedium->Canvas,0,0,ImageNounMedium->Tag,true);
  ImageList->Draw(ImageNounHard->Canvas  ,0,0,ImageNounHard->Tag  ,true);
  ImageList->Draw(ImageSentenceEasy->Canvas  ,0,0,ImageSentenceEasy->Tag  ,true);
  ImageList->Draw(ImageSentenceMedium->Canvas,0,0,ImageSentenceMedium->Tag,true);
  ImageList->Draw(ImageSentenceHard->Canvas  ,0,0,ImageSentenceHard->Tag  ,true);

  ImageVerbEasy->Refresh();
  ImageVerbMedium->Refresh();
  ImageVerbHard->Refresh();
  ImageNounEasy->Refresh();
  ImageNounMedium->Refresh();
  ImageNounHard->Refresh();
  ImageSentenceEasy->Refresh();
  ImageSentenceMedium->Refresh();
  ImageSentenceHard->Refresh();

}
//---------------------------------------------------------------------------

void __fastcall TFormOptions::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  //Save to the std::set
  mOptions.clear();
  if (ImageVerbEasy->Tag==1) mOptions.insert(easyVerb);
  if (ImageVerbMedium->Tag==1) mOptions.insert(mediumVerb);
  if (ImageVerbHard->Tag==1) mOptions.insert(hardVerb);
  if (ImageNounEasy->Tag==1) mOptions.insert(easyNoun);
  if (ImageNounMedium->Tag==1) mOptions.insert(mediumNoun);
  if (ImageNounHard->Tag==1) mOptions.insert(hardNoun);
  if (ImageSentenceEasy->Tag==1) mOptions.insert(easySentence);
  if (ImageSentenceMedium->Tag==1) mOptions.insert(mediumSentence);
  if (ImageSentenceHard->Tag==1) mOptions.insert(hardSentence);
  //If none are selected, the easy verbs are selected
  if (mOptions.empty()) mOptions.insert(easyVerb);
}
//---------------------------------------------------------------------------


 

 

 

 

 

UnitFormOptions.h

 

//---------------------------------------------------------------------------
/*
 *  Frysk Leare Lieder. A program to train the Frysian language.
 *  Copyright (C) 2007  Richel Bilderbeek
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//---------------------------------------------------------------------------
#ifndef UnitFormOptionsH
#define UnitFormOptionsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <ImgList.hpp>
//---------------------------------------------------------------------------
#include <set>
#include "UnitQuestionType.h"
//---------------------------------------------------------------------------
class TFormOptions : public TForm
{
__published: // IDE-managed Components
        TImage *ImageVerbEasy;
        TImageList *ImageList;
        TImage *ImageNounMedium;
        TImage *ImageSentenceMedium;
        TImage *ImageVerbMedium;
        TLabel *Label1;
        TLabel *Label2;
        TLabel *Label3;
        TLabel *Label4;
        TLabel *Label5;
        TLabel *Label6;
        TImage *ImageNounEasy;
        TImage *ImageSentenceEasy;
        TImage *ImageNounHard;
        TImage *ImageSentenceHard;
        TImage *ImageVerbHard;
        TImage *Image10;
        TImage *ImageDone;
        TLabel *LabelDone;
        void __fastcall ImageDoneClick(TObject *Sender);
        void __fastcall ImageVerbEasyClick(TObject *Sender);
        void __fastcall ImageVerbMediumClick(TObject *Sender);
        void __fastcall ImageVerbHardClick(TObject *Sender);
        void __fastcall ImageNounEasyClick(TObject *Sender);
        void __fastcall ImageNounMediumClick(TObject *Sender);
        void __fastcall ImageNounHardClick(TObject *Sender);
        void __fastcall ImageSentenceEasyClick(TObject *Sender);
        void __fastcall ImageSentenceMediumClick(TObject *Sender);
        void __fastcall ImageSentenceHardClick(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
        __fastcall TFormOptions(TComponent* Owner);
        static std::set<QuestionType> mOptions;
        static void SetDefaultOptions();
};
//---------------------------------------------------------------------------
extern PACKAGE TFormOptions *FormOptions;
//---------------------------------------------------------------------------
#endif

 

 

 

 

 

UnitQuestionGenerator.cpp

 

//---------------------------------------------------------------------------


#pragma hdrstop

#include "UnitQuestionGenerator.h"
//---------------------------------------------------------------------------
#include <ctime>
#include <cassert>
#include <algorithm>
//---------------------------------------------------------------------------
QuestionGenerator::QuestionGenerator(const std::set<QuestionType>& types)
: mNcorrect(0),
  mNincorrect(0),
  mQuestionTypes(types),
  mEasyVerbs(GetEasyVerbs()),
  mMediumVerbs(GetMediumVerbs()),
  mHardVerbs(GetHardVerbs()),
  mEasyNouns(GetEasyNouns()),
  mMediumNouns(GetMediumNouns()),
  mHardNouns(GetHardNouns()),
  mEasySentences(GetEasySentences()),
  mMediumSentences(GetMediumSentences()),
  mHardSentences(GetHardSentences())
{
  std::srand(std::time(0));
}
//---------------------------------------------------------------------------

std::string QuestionGenerator::GetQuestion() const
{
  //Set the iterator to a random questiontype
  const int type = std::rand() % mQuestionTypes.size();
  std::set<QuestionType>::const_iterator iter = mQuestionTypes.begin();
  for (int i=0; i<type; ++i) { ++iter; }

  switch ( *iter )
  {
    case easyVerb       : return GetQuestion(mEasyVerbs);
    case mediumVerb     : return GetQuestion(mMediumVerbs);
    case hardVerb       : return GetQuestion(mHardVerbs);
    case easyNoun       : return GetQuestion(mEasyNouns);
    case mediumNoun     : return GetQuestion(mMediumNouns);
    case hardNoun       : return GetQuestion(mHardNouns);
    case easySentence   : return GetQuestion(mEasySentences);
    case mediumSentence : return GetQuestion(mMediumSentences);
    case hardSentence   : return GetQuestion(mHardSentences);
  }
  assert(!"Should not get here");
  return "";
}
//---------------------------------------------------------------------------
std::string QuestionGenerator::GetQuestion(const QuestionMap& verbs) const
{
  const int size = verbs.size();

  //Draw a random index
  const int index = std::rand() % size;

  //Set the iterator to the correct answer
  Iterator iterator = verbs.begin();
  for (int i=0; i<index; ++i) { ++iterator; }

  //Get the question
  mLastQuestion = (*iterator).first;

  //Get the answer
  mAnswers = verbs.equal_range(mLastQuestion);

  //Return the question the iterator points to
  return mLastQuestion;
}
//---------------------------------------------------------------------------
bool QuestionGenerator::GiveAnswer(const std::string& answer)
{
  for (Iterator i = mAnswers.first; i!= mAnswers.second; ++i)
  {
    if ( ToUpperCase(i->second) == ToUpperCase(answer) )
    {
      ++mNcorrect;
      return true;
    }
  }
  ++mNincorrect;
  return false;
}
//---------------------------------------------------------------------------
std::vector<std::string> QuestionGenerator::GetAnswers() const
{
  std::vector<std::string> v;

  for (Iterator i = mAnswers.first; i!= mAnswers.second; ++i)
  {
    v.push_back(i->second);
  }
  return v;

}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetEasyVerbs() const
{
  QuestionMap verbs;
  //29. Dwaan
  verbs.insert(std::make_pair("Tiidwurd: dwaan,ik,notiid", "doch"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,do,notiid", "dochst"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,hy,notiid", "docht"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,wy,notiid", "dogge"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,ik,doetiid", "die"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,do,doetiid", "diest"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,hy,doetiid", "die"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,wy,doetiid", "diene"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,wy,doetiid", "dienen"));
  verbs.insert(std::make_pair("Tiidwurd: dwaan,mulwurd", "haw dien"));
  //46. Gean
  verbs.insert(std::make_pair("Tiidwurd: gean,ik,notiid", "gean"));
  verbs.insert(std::make_pair("Tiidwurd: gean,do,notiid", "giest"));
  verbs.insert(std::make_pair("Tiidwurd: gean,hy,notiid", "giet"));
  verbs.insert(std::make_pair("Tiidwurd: gean,wy,notiid", "geane"));
  verbs.insert(std::make_pair("Tiidwurd: gean,ik,doetiid", "gong"));
  verbs.insert(std::make_pair("Tiidwurd: gean,do,doetiid", "gongst"));
  verbs.insert(std::make_pair("Tiidwurd: gean,hy,doetiid", "gong"));
  verbs.insert(std::make_pair("Tiidwurd: gean,wy,doetiid", "gongen"));
  verbs.insert(std::make_pair("Tiidwurd: gean,mulwurd", "bin gongen"));
  //55. Hawwe
  verbs.insert(std::make_pair("Tiidwurd: hawwe,ik,notiid", "haw"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,do,notiid", "hast"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,hy,notiid", "hat"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,wy,notiid", "hawwe"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,ik,doetiid", "hie"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,do,doetiid", "hiest"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,hy,doetiid", "hie"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,wy,doetiid", "hiene"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,wy,doetiid", "hienen"));
  verbs.insert(std::make_pair("Tiidwurd: hawwe,mulwurd", "haw h n"));
  //120. Sykje
  verbs.insert(std::make_pair("Tiidwurd: sykje,ik,notiid", "sykje"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,do,notiid", "sikest"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,hy,notiid", "siket"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,wy,notiid", "sykje"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,ik,doetiid", "socht"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,do,doetiid", "sochtest"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,hy,doetiid", "socht"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,wy,doetiid", "sochten"));
  verbs.insert(std::make_pair("Tiidwurd: sykje,mulwurd", "haw socht"));
  //121. Sille
  verbs.insert(std::make_pair("Tiidwurd: sille,ik,notiid", "sil"));
  verbs.insert(std::make_pair("Tiidwurd: sille,do,notiid", "silst"));
  verbs.insert(std::make_pair("Tiidwurd: sille,hy,notiid", "sil"));
  verbs.insert(std::make_pair("Tiidwurd: sille,wy,notiid", "sille"));
  verbs.insert(std::make_pair("Tiidwurd: sille,ik,doetiid", "soe"));
  verbs.insert(std::make_pair("Tiidwurd: sille,do,doetiid", "soest"));
  verbs.insert(std::make_pair("Tiidwurd: sille,hy,doetiid", "soe"));
  verbs.insert(std::make_pair("Tiidwurd: sille,wy,doetiid", "soene"));
  verbs.insert(std::make_pair("Tiidwurd: sille,mulwurd", "haw sillen"));
  //124. Sizze
  verbs.insert(std::make_pair("Tiidwurd: sizze,ik,notiid", "sjis"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,do,notiid", "seist"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,hy,notiid", "seit"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,wy,notiid", "sizze"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,ik,doetiid", "sei"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,do,doetiid", "seist"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,hy,doetiid", "sei"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,wy,doetiid", "seine"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,wy,doetiid", "seinen"));
  verbs.insert(std::make_pair("Tiidwurd: sizze,mulwurd", "haw sein"));
  //125. Sjen
  verbs.insert(std::make_pair("Tiidwurd: sjen,ik,notiid", "sjoch"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,do,notiid", "sjochst"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,hy,notiid", "sjocht"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,wy,notiid", "sjogge"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,ik,doetiid", "seach"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,do,doetiid", "seachst"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,hy,doetiid", "seach"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,wy,doetiid", "seagen"));
  verbs.insert(std::make_pair("Tiidwurd: sjen,mulwurd", "haw sjoen"));
  //187. W ze
  verbs.insert(std::make_pair("Tiidwurd: w ze,ik,notiid", "bin"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,do,notiid", "bist"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,hy,notiid", "is"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,wy,notiid", "binne"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,jo,notiid", "binne"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,ik,doetiid","wie"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,do,doetiid","wiest"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,hy,doetiid","wie"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,wy,doetiid","wiene"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,wy,doetiid","wienen"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,jo,doetiid","wiene"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,jo,doetiid","wienen"));
  verbs.insert(std::make_pair("Tiidwurd: w ze,mulwurd",   "haw west"));
  return verbs;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetMediumVerbs() const
{
  QuestionMap verbs;
  verbs.insert(std::make_pair("Medium verb", "anything"));
  return verbs;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetHardVerbs() const
{
  QuestionMap verbs;
  verbs.insert(std::make_pair("Hard verb", "anything"));
  return verbs;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetEasyNouns() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Niemand", "Net ien"));
  nouns.insert(std::make_pair("Niets", "Neat"));
  nouns.insert(std::make_pair("Akkoord", "Akkoart"));
  nouns.insert(std::make_pair("Misschien", "Mooglik"));
  nouns.insert(std::make_pair("Hier", "Hjir"));
  nouns.insert(std::make_pair("Daar", "D r"));
  nouns.insert(std::make_pair("Ergens", "Earne"));
  nouns.insert(std::make_pair("Nergens", "Nearne"));
  nouns.insert(std::make_pair("Overal", "Oeral"));
  nouns.insert(std::make_pair("Overal", "R nom"));
  nouns.insert(std::make_pair("Dichtbij", "Tichteby"));
  nouns.insert(std::make_pair("Rechtdoor", "Rjochttroch"));
  nouns.insert(std::make_pair("Via", "Fia"));
  nouns.insert(std::make_pair("In", "Yn"));
  nouns.insert(std::make_pair("Op", "Op"));
  nouns.insert(std::make_pair("Onder", " nder"));
  nouns.insert(std::make_pair("Tegen", "Tsjin"));
  nouns.insert(std::make_pair("Tegenover", "Foar oer"));
  nouns.insert(std::make_pair("Naast", "Neist"));
  nouns.insert(std::make_pair("Bij", "By"));
  nouns.insert(std::make_pair("Voor", "Foar"));
  nouns.insert(std::make_pair("Beneden", " nder"));
  nouns.insert(std::make_pair("Boven", "boppe"));
  nouns.insert(std::make_pair("Binnen", "binnen"));
  nouns.insert(std::make_pair("Buiten", "b ten"));
  nouns.insert(std::make_pair("Achter", "Efter"));
  nouns.insert(std::make_pair("Vooraan", "Foaroan"));
  nouns.insert(std::make_pair("Achteraan", "Efteroan"));
  //Translation verbs
  nouns.insert(std::make_pair("Blijken", "Blike"));
  nouns.insert(std::make_pair("Blijven", "Bliuwe"));
  nouns.insert(std::make_pair("Durven", "Doare"));
  nouns.insert(std::make_pair("Doen", "Dwaan"));
  nouns.insert(std::make_pair("Vinden", "Fine"));
  nouns.insert(std::make_pair("Gaan", "Gean"));
  nouns.insert(std::make_pair("Hebben", "Hawwe"));
  nouns.insert(std::make_pair("Geven", "Jaan"));
  nouns.insert(std::make_pair("Kunnen", "Kinne"));
  nouns.insert(std::make_pair("Klinken", "Klinke"));
  nouns.insert(std::make_pair("Komen", "Komme"));
  nouns.insert(std::make_pair("Krijgen","Krije"));
  nouns.insert(std::make_pair("Lijken","Lykje"));
  nouns.insert(std::make_pair("Laten","Litte"));
  nouns.insert(std::make_pair("Kijken","Loaitsje"));
  nouns.insert(std::make_pair("Kijken","Sjen"));
  nouns.insert(std::make_pair("Mogen","Meie"));
  nouns.insert(std::make_pair("Maken","Meitsje"));
  nouns.insert(std::make_pair("Moeten","Moatte"));
  nouns.insert(std::make_pair("Lopen","Rinne"));
  nouns.insert(std::make_pair("Zoeken","Sykje"));
  nouns.insert(std::make_pair("Zullen","Sille"));
  nouns.insert(std::make_pair("Zeggen","Sizze"));
  nouns.insert(std::make_pair("Zien","Loaitsje"));
  nouns.insert(std::make_pair("Zien","Sjen"));
  nouns.insert(std::make_pair("Staan","Stean"));
  nouns.insert(std::make_pair("Denken","Tinke"));
  nouns.insert(std::make_pair("Zijn", "W ze"));
  nouns.insert(std::make_pair("Willen", "Wolle"));
  nouns.insert(std::make_pair("Worden", "Wurde"));
  return nouns;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetMediumNouns() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Medium noun", "anything"));
  return nouns;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetHardNouns() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Hard noun", "anything"));
  return nouns;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetEasySentences() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Wie?", "Wa?"));
  nouns.insert(std::make_pair("Wie is dat?", "Wa is dat?"));
  nouns.insert(std::make_pair("Wat?", "Wat?"));
  nouns.insert(std::make_pair("Wat is hier te zien?", "Wat is hjir te sjen?"));
  nouns.insert(std::make_pair("Waar?", "W r?"));
  nouns.insert(std::make_pair("Hoe?", "Hoe?"));
  nouns.insert(std::make_pair("Hoe ver is dat?", "Hoe fier is dat?"));
  nouns.insert(std::make_pair("Hoelang duurt dat?", "Hoe lang duorret dat?"));
  nouns.insert(std::make_pair("Hoeveel?", "Hoefolle?"));
  nouns.insert(std::make_pair("Hoeveel kost dat?", "Hoefolle kostet dat?"));
  nouns.insert(std::make_pair("Hoe laat is het?", "Hoe let is it?"));
  nouns.insert(std::make_pair("Welk(e)?", "Hokker?"));
  nouns.insert(std::make_pair("Welk glas is voor mij?", "Hokker gl s is foar my?"));
  nouns.insert(std::make_pair("Hoeveel?", "Hoefolle?"));
  nouns.insert(std::make_pair("Wanneer?", "Wannear?"));
  nouns.insert(std::make_pair("Waarom?", "W rom?"));
  nouns.insert(std::make_pair("Het spijt me", "It spyt my"));
  nouns.insert(std::make_pair("Een ogenblikje a.u.b.", "Momint graach"));
  nouns.insert(std::make_pair("Ik heb nu geen tijd", "Ik ha it no net oan tiid"));
  nouns.insert(std::make_pair("Dat is onmogelijk", "Dat kin net"));
  nouns.insert(std::make_pair("Ik geloof het wel", "Ik leau fan wol"));
  nouns.insert(std::make_pair("Ik denk het ook", "Ik tink it ek"));
  nouns.insert(std::make_pair("Ik hoop het ook", "Ik hoopje it ek"));
  nouns.insert(std::make_pair("Helemaal niet", "Hielendal net"));
  nouns.insert(std::make_pair("Dat klopt", "Dat kloppet"));
  nouns.insert(std::make_pair("Ik weet het niet", "Ik wit it net"));
  nouns.insert(std::make_pair("Ver weg", "Fier fuort"));
  nouns.insert(std::make_pair("Naar recht", "Nei rjochts"));
  nouns.insert(std::make_pair("Naar links", "Nei links"));
  nouns.insert(std::make_pair("In het midden", "Yn 'e midden"));
  nouns.insert(std::make_pair("Naar voren", "Nei foarren"));
  nouns.insert(std::make_pair("Naar beneden", "Nei nderen"));
  nouns.insert(std::make_pair("Naar boven", "Nei boppen"));
  nouns.insert(std::make_pair("In het noorden", "Yn it noarden"));
  nouns.insert(std::make_pair("Naar het zuiden", "Nei it noarden"));
  nouns.insert(std::make_pair("Uit het westen", " t it westen"));
  nouns.insert(std::make_pair("Van het oosten", "Fan it easten"));
  nouns.insert(std::make_pair("Welke dag is het vandaag?", "Watfoar dei is it hjoed?"));
  nouns.insert(std::make_pair("De hoeveelste is het vandaag?", "De hoefolste is it hjoed?"));
  nouns.insert(std::make_pair("Deze week", "Fan 'e wike"));
  nouns.insert(std::make_pair("Volgende week", "Nije wike"));
  nouns.insert(std::make_pair("Volgende maand", "Oare moanne"));
  nouns.insert(std::make_pair("De volgende dag", "De oare deis"));
  nouns.insert(std::make_pair("De vorige dag", "De foarige deis"));
  nouns.insert(std::make_pair("Dit jaar", "Fan 't jier"));
  nouns.insert(std::make_pair("Vorig jaar", "Ferline jier"));
  nouns.insert(std::make_pair("Volgend jaar", "Takom jier"));
  nouns.insert(std::make_pair("Volgend jaar", "Takomme jier"));
  nouns.insert(std::make_pair("Vrije dag", "Frije dei"));
  nouns.insert(std::make_pair("Een half uur", "In healoere"));
  nouns.insert(std::make_pair("Om hoe laat?", "Om hoe let?"));
  nouns.insert(std::make_pair("Hoe laat kan ik langskomen?", "Hoe let kin ik delkomme?"));
  nouns.insert(std::make_pair("Te vroeg", "Te betiid"));
  nouns.insert(std::make_pair("Te laat", "Te let"));
  nouns.insert(std::make_pair("Op tijd", "Op 'e tiid"));
  //Chapter 2
  nouns.insert(std::make_pair("Goedemorgen", "Goeie moarn"));
  nouns.insert(std::make_pair("Goedemiddag", "Goeie middei"));
  nouns.insert(std::make_pair("Goedenavond", "Goej n"));
  nouns.insert(std::make_pair("Hoe gaat het ermee?", "Hoe is't dermei?"));
  nouns.insert(std::make_pair("Niet zo goed", "Net sa goed"));
  nouns.insert(std::make_pair("Gaat wel", "Giet wol"));
  nouns.insert(std::make_pair("Ik ga maar eens", "Ik stap mar wer ris op"));
  nouns.insert(std::make_pair("Ik moet er vandoor", "Ik moat fuort"));
  nouns.insert(std::make_pair("Tot ziens", "Oant sjen"));
  nouns.insert(std::make_pair("Tot straks", "Oant aanst"));
  nouns.insert(std::make_pair("Tot zo", "Oant daliks"));
  nouns.insert(std::make_pair("Dank u wel", "Tankjewol"));
  nouns.insert(std::make_pair("Geen dank", "Neat te tankjen"));
  nouns.insert(std::make_pair("Graag gedaan", "Graach dien"));
  nouns.insert(std::make_pair("Laat maar zitten", "Lit mar sitte"));
  nouns.insert(std::make_pair("Dat kan iedereen overkomen", "Dat kin elk oerkomme"));
  return nouns;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetMediumSentences() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Medium noun", "anything"));
  return nouns;
}
//---------------------------------------------------------------------------
QuestionGenerator::QuestionMap QuestionGenerator::GetHardSentences() const
{
  QuestionMap nouns;
  nouns.insert(std::make_pair("Hard noun", "anything"));
  return nouns;
}
//---------------------------------------------------------------------------
std::string ToUpperCase(std::string s)
{
  std::transform(s.begin(), s.end(), s.begin(),
   (int(*)(int)) std::toupper);
  return s;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------



#pragma package(smart_init)

 

 

 

 

 

UnitQuestionGenerator.h

 

//---------------------------------------------------------------------------

#ifndef UnitQuestionGeneratorH
#define UnitQuestionGeneratorH
//---------------------------------------------------------------------------
#include <string>
#include <map>
#include <vector>
#include <set>
#include "UnitQuestionType.h"
//---------------------------------------------------------------------------
struct QuestionGenerator
{
  typedef std::multimap<std::string,std::string> QuestionMap;
  typedef QuestionMap::const_iterator Iterator;
  typedef std::pair<Iterator,Iterator> Range;

  QuestionGenerator(const std::set<QuestionType>& types);
  //Main communication
  std::string GetQuestion() const;
  bool GiveAnswer(const std::string& answer);
  std::vector<std::string> GetAnswers() const;
  //Correct/incorrect
  int GetNcorrect() const { return mNcorrect; }
  int GetNincorrect() const { return mNincorrect; }
  //Question types
  std::set<QuestionType> mQuestionTypes;

  const QuestionMap mEasyVerbs;
  const QuestionMap mMediumVerbs;
  const QuestionMap mHardVerbs;
  const QuestionMap mEasyNouns;
  const QuestionMap mMediumNouns;
  const QuestionMap mHardNouns;
  const QuestionMap mEasySentences;
  const QuestionMap mMediumSentences;
  const QuestionMap mHardSentences;

  private:
  int mNcorrect;
  int mNincorrect;

  mutable std::string mLastQuestion;
  mutable Range mAnswers;


  //Create the question maps
  //Verbs
  QuestionMap GetEasyVerbs() const;
  QuestionMap GetMediumVerbs() const;
  QuestionMap GetHardVerbs() const;
  //Nouns
  QuestionMap GetEasyNouns() const;
  QuestionMap GetMediumNouns() const;
  QuestionMap GetHardNouns() const;
  //Sentences
  QuestionMap GetEasySentences() const;
  QuestionMap GetMediumSentences() const;
  QuestionMap GetHardSentences() const;

  //Read from the existing question maps
  //Verbs
  std::string GetQuestion(const QuestionMap& questions) const;
};
//---------------------------------------------------------------------------
std::string ToUpperCase(std::string s);

#endif

 

 

 

 

 

UnitQuestionType.cpp

 

//---------------------------------------------------------------------------


#pragma hdrstop

#include "UnitQuestionType.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

 

 

 

 

 

UnitQuestionType.h

 

//---------------------------------------------------------------------------

#ifndef UnitQuestionTypeH
#define UnitQuestionTypeH
//---------------------------------------------------------------------------
enum QuestionType
{
  easyVerb,
  mediumVerb,
  hardVerb,
  easyNoun,
  mediumNoun,
  hardNoun,
  easySentence,
  mediumSentence,
  hardSentence
};
//---------------------------------------------------------------------------

#endif
 

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.