|
From: Noorez K. <coo...@ho...> - 2004-06-24 03:00:57
|
this program is ignoring the system() functions
//quiz maker!
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
using namespace std;
class Quiz
{
private:
char question[1000];
char answerA[1000];
char answerB[1000];
char answerC[1000];
char answerD[1000];
char answerT;
char answerF;
char actual;
public:
static int questionNumb;
static int type;
Quiz createQuestion();
void writeQuestion(Quiz ques, int type,char* quizName);
};
int Quiz::questionNumb = 1;
int Quiz::type = 0;
Quiz Quiz::createQuestion()
{
Quiz ques;
system("cls");
cout << "What kind of question do you want question " <<
Quiz::questionNumb << " to be\n";
real1:
cout << "A. Multiple choice.. or B. True/False [a\\b] ";
char choice;
cin >> choice;
cin.sync();
if(!(choice == 'a' || choice == 'b'))
{
cout << "Choice must be a or b\n";
goto real1;
}
if(choice == 'a' || choice == 'A')
{
type = 1;
cout << "\nType the question in\n\n";
cin.getline(ques.question,1000);
cout << "Type in answer A. ";
cin.getline(ques.answerA,1000);
cout << "Type in answer B. ";
cin.getline(ques.answerB,1000);
cout << "Type in answer C. ";
cin.getline(ques.answerC,1000);
cout << "Type in answer D. ";
cin.getline(ques.answerD,1000);
real2:
cout << "Give us the real answer: ";
cin >> ques.actual;
cin.sync();
if(!(ques.actual == 'a' || ques.actual == 'b'
|| ques.actual == 'c' || ques.actual == 'd') )
{
cout << "Real answer must be a,b,c or d\n";
goto real2;
}
}
if(choice == 'b' || choice == 'B')
{
type = 2;
cout << "\nType in the statement\n\n";
cin.getline(ques.question,1000);
real3:
cout << "Give us the real answer: ";
cin >> ques.actual;
cin.sync();
if(!(ques.actual == 't' || ques.actual == 'f'))
{
cout << "Real answer must be t or f\n";
goto real3;
}
}
return ques;
}
void Quiz::writeQuestion(Quiz ques, int type, char* quizName)
{
ofstream out_file(quizName,ios::app);
if(type == 1)
{
out_file << "~\n" << questionNumb << ". " << ques.question << '\n'
<< '\n';
out_file << "A. " << ques.answerA << '\n';
out_file << "B. " << ques.answerB << '\n';
out_file << "C. " << ques.answerC << '\n';
out_file << "D. " << ques.answerD << '\n';
out_file << '~' << ques.actual << '\n';
}
if(type == 2)
{
out_file << "~\n" << questionNumb << ". " << ques.question << '\n';
out_file << "True or False\n";
out_file << '~' << ques.actual << '\n';
}
}
int main()
{
cout << "Welcome to the quiz maker.\n";
cout << "With this program you can make a Multiple Choice/True or False
quiz.\n";
getName:
cout << "We need the name of the quiz file: ";
char* quizName = new char;
cin.getline(quizName,123);
strcat(quizName,".qz");
fstream fs(quizName);
if(fs)
{
cout << "File name in use.\n";
goto getName;
}
cout << endl << "\nLets start making questions!\n";
system("pause");
system("cls");
Quiz question;
char contin;
do
{
question = question.createQuestion();
question.writeQuestion(question,Quiz::type,quizName);
Quiz::questionNumb = Quiz::questionNumb+1;
cout << "\nDo you want to add another question [Y\\N] ";
do
{
cin >> contin;
}while(contin == 'y' && contin == 'Y' && contin == 'n' && contin ==
'N');
}while(contin == 'y' || contin == 'Y');
}
_________________________________________________________________
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
|