#include<time.h>
#include<fstream>
#include<iostream>
#include<stdlib.h>
using namespace std;
int sum;
int q1(char q[60], char a1[20], char a2[20]);
int q2(char q[60], char a1[20], char a2[20]);
int q3(char q[60], char a1[20], char a2[20]);
int q4(char q[60], char a1[20], char a2[20]);
int q5(char q[60], char a1[20], char a2[20]);
int q6(char q[60], char a1[20], char a2[20]);
int q7(char q[60], char a1[20], char a2[20]);
int q8(char q[60], char a1[20], char a2[20]);
int q9(char q[60], char a1[20], char a2[20]);
int q10(char q[60], char a1[20], char a2[20]);
int tem(char q[60], char a1[20], char a2[20]);
int tem(char q[60], char a1[20], char a2[20]);
void wf();
int record();
int main(){
char q[60];
char a1[20];
char a2[20];
cout <<"\nChoose either the options 1, 2 or 3 depending on the answer next to it.\n\n";
sum = q1(q, a1, a2);
cout << "\n";
sum = q2(q, a1, a2);
cout << "\n";
sum = q3(q, a1, a2);
cout << "\n";
sum = q4(q, a1, a2);
cout << "\n";
sum = q5(q, a1, a2);
cout << "\n";
sum = q6(q, a1, a2);
cout << "\n";
sum = q7(q, a1, a2);
cout << "\n";
sum = q8(q, a1, a2);
cout << "\n";
sum = q9(q, a1, a2);
cout << "\n";
sum = q10(q, a1, a2);
record();
}
////////////////////////////////////////////////////////////////////
// These functions are the 2 templates for the questions each //
// question calls either tem() or tem2() //
////////////////////////////////////////////////////////////////////
int tem(char q[60], char a1[20], char a2[20])
{
int res;
cout << q << "\n";
cout <<"1) "<< a1 <<"\n";
cout <<"2) "<< a2 <<"\n";
cout <<"3) Exit program\n";
cin >> res;
if (res==1){
sum=(sum+10);
}
else if (res==2){
}
else if (res==3) {
cout << sum <<" out of 100\n";
record();
exit(1);
}
else
{ cout << "You must enter a number between 1 and 3.\n";
tem(q, a1, a2);
}
return sum;
}
int tem2(char q[60], char a1[20], char a2[20])
{
int res;
cout << q << "\n";
cout <<"1) "<< a1 <<"\n";
cout <<"2) "<< a2 <<"\n";
cout <<"3) Exit program\n";
cin >> res;
if (res==1){
}
else if (res==2){
sum=(sum+10);
}
else if (res==3) {
cout << sum <<" out of 100\n";
record();
exit(1);
}
else
{ cout << "You must enter a number between 1 and 3.\n";
tem2(q, a1, a2);
}
return sum;
}
////////////////////////////////////////////////////////////////////
// These functions are the questions and answers that are used in //
// the question template functions. //
////////////////////////////////////////////////////////////////////
int q1(char q[60], char a1[20], char a2[20])
{
q="What does the command ls stand for?";
a1="long";
a2="list";
sum = tem2(q, a1, a2);
return sum;
}
int q2(char q[60], char a1[20], char a2[20])
{
q="What does the cd command stand for";
a1="Change Directory";
a2="Choose Definition";
sum = tem(q, a1, a2);
return sum;
}
int q3(char q[60], char a1[20], char a2[20])
{
q="What does the -l argument stand for with the command ls?";
a1="level";
a2="long";
sum = tem2(q, a1, a2);
return sum;
}
int q4(char q[60], char a1[20], char a2[20])
{
q="What does the cal command display on the screen?";
a1="Calendar";
a2="Calculator";
sum = tem(q, a1, a2);
return sum;
}
int q5(char q[60], char a1[20], char a2[20])
{
q="What does the cp command stand for?";
a1="Chop";
a2="Copy";
sum = tem2(q, a1, a2);
return sum;
}
int q6(char q[60], char a1[20], char a2[20])
{
q="What does the rm command stand for?";
a1="Remove";
a2="Rename";
sum = tem(q, a1, a2);
return sum;
}
int q7(char q[60], char a1[20], char a2[20])
{
q="What does the pwd command stand for?";
a1="Password";
a2="Print Working Directory";
sum = tem2(q, a1, a2);
return sum;
}
int q8(char q[60], char a1[20], char a2[20])
{
q="What does the mkdir command stand for?";
a1="Make Direct";
a2="Make Directory";
sum = tem2(q, a1, a2);
return sum;
}
int q9(char q[60], char a1[20], char a2[20])
{
q="What does the history command print on the screen?";
a1="Command History";
a2="Web History";
sum = tem(q, a1, a2);
return sum;
}
int q10(char q[60], char a1[20], char a2[20])
{
q="What is the fdisk program";
a1="Disk Partitioner";
a2="File Browser";
sum = tem(q, a1, a2);
return sum;
}
////////////////////////////////////////////////////////////////////
// This function calculates the date and inputs it and the users //
// score into a file called bashquizresults.txt in the same //
// direcory as the program //
////////////////////////////////////////////////////////////////////
void wf()
{
time_t t = time(0);
tm time = *localtime(&t);
ofstream results;
results.open ("bashquizresults.txt", ios::app);
results << "The date of the quiz was " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
time.tm_year + 1900 << " Your score was " << sum <<" out of 100." "\n";;
results.close();
}
////////////////////////////////////////////////////////////////////
// This function asks the user if they would like to record their //
// results in a file and calls the function wf() //
////////////////////////////////////////////////////////////////////
int record()
{
int c;
cout<<"\n"<<"Your score is "<< sum << " out of 100" << "\n";
cout<< "Would you like to record your results?\n";
cout <<"1) Yes \n";
cout <<"2) No \n";
cin >> c;
if (c==1){
wf();
cout << "Your results have been recorded in bashquizresults.txt in the same directory as this program.\n";
}
else if (c==2){
return 0;
}
else {
cout << "You must enter either 1 or 2!\n";
record();
}
}