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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
// 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,
person;
string username,
password,
STUDENT_USERNAME,
STUDENT_PASSWORD,
TEACHER_USERNAME,
TEACHER_PASSWORD,
question,
name;
int option,
numberOfQuestions,
counter = 1,
questionNumber = 1,
number,
answer = 0,
solution = 0,
registration = 0;
cout << "Are you a teacher or a student? Enter in t for teacher and s for student." << endl;
cin >> person;
while (person != 's' && person != 'S' && person != 't' && person != 'T')
{
cout << "Please choose a valid option." << endl;
cin >> person;
}
if (person == 's' || person == 'S')
{
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 == 't' || person == 'T')
{
inputFile.open("Registration.txt");
inputFile >> registration;
if (registration == 1)
{
cout << "You have already registered!" << endl;
inputFile.close();
}
if (registration == 0)
{
inputFile.close();
outputFile.open("Registration.txt");
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;
registration++;
outputFile << registration << endl;
outputFile << TEACHER_USERNAME << endl;
outputFile << TEACHER_PASSWORD << endl;
outputFile.close();
}
}
inputFile.open("Registration.txt");
inputFile >> registration;
inputFile >> TEACHER_USERNAME;
inputFile >> TEACHER_PASSWORD;
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;
while (choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'n')
{
cout << "\nPlease choose a valid option." << endl;
cin >> choice;
}
switch (choice)
{
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 << answer;
cout << "Your test answers are saved!" << endl;
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;
while (option != 1 && option != 2 && option != 3)
{
cout << "Please choose a valid option." << endl;
cin >> option;
}
switch (option)
{
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)
{
cin.ignore(1000,'\n');
cout << "What is the question for question #" << questionNumber << "?" << endl;
getline(cin,question);
cout << "What is the answer to this question?" << endl;
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 >> answer;
cout << answer << endl;
inputFile.close();
break;
case 3:
break;
}
}
return 0;
}
|