1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
// This is a program that for the two users (student, teacher)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
ifstream inputFile;
ofstream outputFile;
char choice;
string person,
username,
password,
STUDENT_USERNAME,
STUDENT_PASSWORD,
TEACHER_USERNAME,
TEACHER_PASSWORD,
question,
solution,
name;
int option,
numberOfQuestions,
counter = 1,
questionNumber = 1,
number,
answer;
cout << "Are you a teacher or a student?\n";
cin >> person;
while (person != "student" && person != "Student" && person != "teacher" && person != "Teacher")
{
cout << "Please choose a valid option." << endl;
cin >> person;
}
if (person == "student" || person == "Student")
{
cout << "Welcome, student!\n";
cout << "Please register your username.\n";
cin >> STUDENT_USERNAME;
cout << "Please register your password.\n";
cin >> STUDENT_PASSWORD;
cout << "\nYour registration is complete! Thank you for registering!" << endl;
}
if (person == "teacher" || person == "Teacher")
{
cout << "Welcome, teacher!\n";
cout << "Please register your username.\n";
cin >> TEACHER_USERNAME;
cout << "Please register your password.\n";
cin >> TEACHER_PASSWORD;
cout << "\nYour registration is complete! Thank you for registering!" << endl;
}
cout << "\nPlease log in.\n";
cout << "Username: ";
cin >> username;
cout << "Password: ";
cin >> password;
while (!(username == STUDENT_USERNAME && password == STUDENT_PASSWORD) &&
!(username == TEACHER_USERNAME && password == TEACHER_PASSWORD))
{
cout << "\nPlease log in.\n";
cout << "Username: ";
cin >> username;
cout << "Password: ";
cin >> password;
}
if ((username == STUDENT_USERNAME) && (password == STUDENT_PASSWORD))
{
cout << "Welcome Student! Would you like to take the test? Choose Y or N\n";
cin >> choice;
switch (choice)
{
default: while (choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'n')
{
cout << "\nPlease choose a valid option." << endl;
cin >> choice;
break;
}
case 'y':
case 'Y': cout << "So you wish to take the test!" << endl;
inputFile.open("Test.txt");
inputFile >> name;
cout << name << endl;
cin >> answer;
inputFile >> number;
cout << number << endl;
outputFile.open("Results.txt");
outputFile.close();
inputFile.close();
break;
case 'n':
case 'N': cout << "" << endl;
break;
}
}
if ((username == TEACHER_USERNAME) && (password == TEACHER_PASSWORD))
{
cout << "Welcome Teacher! What would you like to do?" << endl;
cout << "1. Write a test." << endl;
cout << "2. Check the test scores." << endl;
cout << "3. Nothing - terminate the program." << endl;
cin >> option;
switch (option)
{
default: while (option != 1 && option != 2 && option != 3)
{
cout << "Please choose a valid option." << endl;
cin >> option;
break;
}
case 1: cout << "So you chose to write a test!" << endl;
outputFile.open("Test.txt");
cout << "How many questions are there going to be?" << endl;
cin >> numberOfQuestions;
while (numberOfQuestions <= 0)
{
cout << "Please enter in a valid number of questions that is not negative or zero." << endl;
cin >> numberOfQuestions;
}
cout << "So you choose to have " << numberOfQuestions << " questions on the test." << endl;
while (counter <= numberOfQuestions)
{
cout << "What is the question for question #" << questionNumber << "?" << endl;
getline(cin,question);
cout << "What is the answer to this question?" << endl;
getline(cin,solution);
outputFile << question << endl;
outputFile << solution << endl;
counter++;
questionNumber++;
}
outputFile.close();
cout << "Your questions and answers are saved!" << endl;
break;
case 2: cout << "So you wish to check the test scores!" << endl;
inputFile.open("Results.txt");
inputFile.close();
break;
case 3:
break;
}
}
return 0;
}
|