Hi i would like to make a program for my school exams.This will be a Multiple choice questions.
I want the program to read the questions from a file (i.e textfile) and then one by one will be shown on screen. When the user will answer the question using a,b,c or d then the choice will be written somewhere so I can make some statistics at the end of the questions.
How can i make this project ?What am i going to use?
Can anyone please help me to start it and then i will do it by myself.
#include <iostream.h>
#include <stdio.h>
#include <fstream.h>
#include <stream.h>
usingnamespace std;
int showquestion()
{//shows the question on screen
ifstream text1;
text1.open ("question1.txt", ifstream::in);
while (text1.good())
cout << (char) text1.get();
text1.close();
}
int main()
{
int exit;
char a,b,c,d,choice;
char next_exit;
ifstream text1;
ifstream text0;
showquestion(); //call the procedure to show question
cout<<("\n\n Please select (a-d) or s (skip) to next question \n");
cout<<"\n\n";
choose : //Label used in invalid choice
cin>>choice; //waiting for user's choice
if (choice == 'a') //CASE OF SELECTION a
{
ofstream text0; //("default.txt"); //Names File as ofstream (for output to file)
text0.open ("default.txt", ios::app);
text0 << "a"<<"\n";
text0.close();
cout<<("Done. Your choice is : a ");
cout<<endl;
}//end of if case
elseif (choice == 'b') //CASE OF SELECTION b
{
ofstream text0; //("default.txt"); //Names File as ofstream (for output to file)
text0.open ("default.txt", ios::app);
text0 << "b"<<"\n";
text0.close();
cout<<("Done. Your choice is : b ");
cout<<endl;
}//end of else if
elseif (choice == 'c') //CASE OF SELECTION c
{
ofstream text0; //("default.txt"); //Names File as ofstream (for output to file)
text0.open ("default.txt", ios::app);
text0 << "c"<<"\n";
text0.close();
cout<<("Done. Your choice is : c ");
cout<<endl;
}//end of else if
elseif (choice == 'd') //CASE OF SELECTION d
{
ofstream text0; //("default.txt"); //Names File as ofstream (for output to file)
text0.open ("default.txt", ios::app);
text0 << "d"<<"\n";
text0.close();
cout<<("Done. Your choice is : d ");
cout<<endl;
}//end of else if
elseif (choice == 's') //CASE OF skipping question
{
cout<<("Question skipped ! :\n");
text0.open ("default.txt", ios::app);
// text0 << "skipped \n";
text0.close();
cout<<"Press N to go to the next question or E to EXIT. \n"; //SUB MENUS FOR EXIT OR GO TO NEXT
cin>>next_exit;
if ((next_exit) == 'N' or (next_exit) == 'n')
{
cout<<"Proceed with the next question. \n";
//call the function with questions!
}
elseif ((next_exit) == 'E' or (next_exit) == 'e')
{
cout<<"Apllication Stopped. \n";
return 1;
}
}//end of else if
else cout<<("Invalid Choice.\n")<<("Select again. \n");
goto choose;
/*
return 0;
}
*/
This is the code i have written.
I know that it is so good and also the best method i used ,but i dont know how else to write the program
Please help me...
I want the program to read the questions one by one from the file,in the screen will be appeared the 1st question and then there will be a,b,c or from choices.when the user makes a selection by pressing a-d then the choice should be writen somewhere and then goes to the next question.Finally i would like to see the results i.e how many correct questions ,wrong questions.
ummm, your code looks pretty good as it is, but just to make it a much much simpler code, you can easily generate another function that sends the user's choice as an argument.
the function can then take that character, and write it to a file. that way, you don't have to repeat the code so many times.
also, i don't quite understand what you mean by "statistics" but if you mean whether or not you got it right, or how many questions you answered, you can easily keep track of that using a counter and a loop if necessary.
i hope you can understand those, if you don't please ask and i'll post some code but then it takes the fun out of writing the program out yourself right? (:
i think u sud use a function here...
with each correct answer call a function and then do the statistics....or whtever...u can also use loop to ask questions....
happy programmin though...