Question: Turn the code below in java: #include #include #include #include #include #include #include #include using namespace std; // All the states that the project will

Turn the code below in java:

Turn the code below in java: #include #include #include #include #include #include

#include #include using namespace std; // All the states that the project

will go into enum QuizState { welcome, quit, loginAdmin, adminFirstScreen, loginStudent, studentFirstScreen,

studentQuiz, studentResults }; struct Questions { int id; string question; string firstAlternative;

string secondAlternative; int correct_alternative; string category: }; Estruct Admin { int id;

string username; string password; }; - struct Student { int id; string

first_name; string last_name; int age; string username; string password; }; struct Test

{ int id; int student_id; string date; int correct; int total; };

list allAdmins; list allstudents; list allTests; Admin loggedInAdmin; Student loggedInStudent; Different other

functions string get_todays_date() time_t rawtime; struct tm* timeinfo; char buffer[80]; time (&rawtime);

timeinfo - localtime (&rawtime); strftime (buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%s", timeinfo); string str(buffer);

return str; ----- Functions to read data void read_questions() { ifstream file;

file.open("questions.txt"); if (file.is_open() string line; while(getline(file, line)) { // stringstream converts line

string as a sequence of characters that we can process one by

one istringstream ss( line ); Questions question; string id, correct, category; getline

(ss, id, ';'); question.id = stoi(id); // Convert string to int getline(

ss, question.question, ';'); getline( ss, question.firstAlternative,','); getline( ss, question.secondAlternative, ';'); getline( ss,

correct, ';'); question.correct_alternative = stoi(correct); //Convert getline( ss, question.category, ';'); allquestions.push_back(question); }

} file.close(); } void write_questions() { ofstream file; file.open("questions.txt"); // Use an

iterrator to go through all questions list ::iterator questions_i; for(questions_i = allquestions.begin();

#include #include #include #include #include #include #include #include using namespace std; // All the states that the project will go into enum QuizState { welcome, quit, loginAdmin, adminFirstScreen, loginStudent, studentFirstScreen, studentQuiz, studentResults }; struct Questions { int id; string question; string firstAlternative; string secondAlternative; int correct_alternative; string category: }; Estruct Admin { int id; string username; string password; }; - struct Student { int id; string first_name; string last_name; int age; string username; string password; }; struct Test { int id; int student_id; string date; int correct; int total; }; list allAdmins; list allstudents; list allTests; Admin loggedInAdmin; Student loggedInStudent; Different other functions string get_todays_date() time_t rawtime; struct tm* timeinfo; char buffer[80]; time (&rawtime); timeinfo - localtime (&rawtime); strftime (buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%s", timeinfo); string str(buffer); return str; ----- Functions to read data void read_questions() { ifstream file; file.open("questions.txt"); if (file.is_open() string line; while(getline(file, line)) { // stringstream converts line string as a sequence of characters that we can process one by one istringstream ss( line ); Questions question; string id, correct, category; getline (ss, id, ';'); question.id = stoi(id); // Convert string to int getline( ss, question.question, ';'); getline( ss, question.firstAlternative,','); getline( ss, question.secondAlternative, ';'); getline( ss, correct, ';'); question.correct_alternative = stoi(correct); //Convert getline( ss, question.category, ';'); allquestions.push_back(question); } } file.close(); } void write_questions() { ofstream file; file.open("questions.txt"); // Use an iterrator to go through all questions list ::iterator questions_i; for(questions_i = allquestions.begin(); questions_i != allquestions.end(); questions_i++) YULUI { file questions_i->id ","; file questions_i->question ", file firstAlternative secondAlternative correct_alternative category ::iterator admin_i; for(admin_i - allAdmins.begin(); admin_i != allAdmins.end(); admin_i++) { file id ","; file username password ::iterator student_i; for(student i = allstudents.begin(); student i != allstudents.end(); student_i++) { file id ","; file first_name last_name age username password ::iterator test_i; for(test_i = alltests.begin(); test_i != alltests.end(); test_i++) { file id student_id date ","; file test_i->correct total ::iterator admin_i; for(admin_i = allAdmins.begin(); admin_i !- allAdmins.end(); admin_i++) { if(admin_i->username == username) { 1/A username is found, check password if(admin_i->password == password) { //Password matches loggedInAdmin.id admin_i->id; loggedInAdmin.username = admin_i->username; studentTests.push_back(*test_i); //Pass the copy by pointer return studentTests; } Functions for admin void add_question( string temp; Questions newQuestion; newQuestion.id = allQuestions.back().id + 1; cout > choice; while(choice > 2 || choice > choice; newQuestion.correct_alternative = choice; cout > category; newQuestion.category = category; allquestions.push_back(newQuestion); cout > question_id; //use an iterator to loop through all Questions, list :: iterator questions_i; bool question_found = false; for(questions_i = allquestions.begin(); questions_i != allquestions.end(); questions_i++) { if(questions_i->id question_id) { question_found = true; Questions editted = &questions_i; // We copy the current question cout questionfirstAlternativesecondAlternativecorrect_alternative> choice; while(choice > 2 || choice > choice; } cout category studentTests) { int correctsum = 0; int totalsum = 0; //use an iterator to loop through all Tests, list ::iterator tests_i; for(tests_i = studentTests.begin(); tests_i != studentTests.end(); tests_i ++) { correctSum += tests_i->correct; totalsum += tests_i->total; e) { if (totalsum == return e; }else{ // We need to cast it to float since we divide two integers float score = (float) correctSum/totalsum; return ceil(score # 100); void print_all_students() { int student Count = allstudents.size(); int student_data[ studentCount][3]; //use an iterator to loop through all Questions, list Student>::iterator students_i; int index = a; for(students i = allstudents.begin(); students_i != allstudents.end(); students_i++) {//Get all student tests list id); //calculate score int score = calculate_score(studentTests); // Store in array student_data[index][@] = index; //Student's index student_data[index][1] = students_i->id; //Student's id student_data[index][2] = score; //Student's score index++; } 1/Sort 2D array using selection sort for (int i = e; i student_data[min] [2]) min j; }swap (student_data(min), student_data[i]); cout first_name; //get first name string lastname = students_i->last_name; //get last name cout > input_username; //Doing a sequential search for the username in Student's list Student foundstudent; list ::iterator student_i; bool found = false; for(student_i = allstudents.begin(); student_i != allstudents.end(); student_i++) { if(student_i->username input_username) { foundstudent = *student_i; //get copy of the student found = true; //we say that we found a student == if(!found) { cout studentTests = get_student_tests(student_id); cout ::iterator test_i; for(test_i = studentTests.begin(); test_i != studentTests.end(); test_i+ { // Print only data of the student cout date correct total :: iterator question_i; for(question_i allquestions.begin(); question_i != allquestions.end(); question_i++) { cout category id question firstAlternative secondAlternative > choice; while(choice > 2 || choice > choice; } //check result if (choice question_i->correct_alternative) { cout myTests - get_student_tests(loggedInStudent.id); //use an iterator to loop through all Tests, list ::iterator test_i; for(test_i = myTests.begin(); test_i != myTests.end(); test_i++) { //Print only data of the loggedInStudent cout date correc total > choice; switch(choice) { case 1: current state = loginAdmin; break; case 2: currentstate - loginstudent; break; case 3: currentstate = quit; break; default: cout > username; cout > password; bool loginSuccess = login_admin(username, password); if (loginSuccess) { currentstate - adminFirstscreen; } else { cout > choice; switch(choice) case 1: add_question(); break; case 2: edit_question(); break; case 3: print_all_students(); break; case 4: search_student(); break; case 5: cout > username; cout > password; bool loginSuccess = login_student(username, password); if (loginSuccess) { currentstate = studentFirstscreen; } else { cout > choice; switch(choice) { case 1: take_quizo; break; case 2: print_student_results(); break; case 3: cout #include #include #include #include #include #include #include using namespace std; // All the states that the project will go into enum QuizState { welcome, quit, loginAdmin, adminFirstScreen, loginStudent, studentFirstScreen, studentQuiz, studentResults }; struct Questions { int id; string question; string firstAlternative; string secondAlternative; int correct_alternative; string category: }; Estruct Admin { int id; string username; string password; }; - struct Student { int id; string first_name; string last_name; int age; string username; string password; }; struct Test { int id; int student_id; string date; int correct; int total; }; list allAdmins; list allstudents; list allTests; Admin loggedInAdmin; Student loggedInStudent; Different other functions string get_todays_date() time_t rawtime; struct tm* timeinfo; char buffer[80]; time (&rawtime); timeinfo - localtime (&rawtime); strftime (buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%s", timeinfo); string str(buffer); return str; ----- Functions to read data void read_questions() { ifstream file; file.open("questions.txt"); if (file.is_open() string line; while(getline(file, line)) { // stringstream converts line string as a sequence of characters that we can process one by one istringstream ss( line ); Questions question; string id, correct, category; getline (ss, id, ';'); question.id = stoi(id); // Convert string to int getline( ss, question.question, ';'); getline( ss, question.firstAlternative,','); getline( ss, question.secondAlternative, ';'); getline( ss, correct, ';'); question.correct_alternative = stoi(correct); //Convert getline( ss, question.category, ';'); allquestions.push_back(question); } } file.close(); } void write_questions() { ofstream file; file.open("questions.txt"); // Use an iterrator to go through all questions list ::iterator questions_i; for(questions_i = allquestions.begin(); questions_i != allquestions.end(); questions_i++) YULUI { file questions_i->id ","; file questions_i->question ", file firstAlternative secondAlternative correct_alternative category ::iterator admin_i; for(admin_i - allAdmins.begin(); admin_i != allAdmins.end(); admin_i++) { file id ","; file username password ::iterator student_i; for(student i = allstudents.begin(); student i != allstudents.end(); student_i++) { file id ","; file first_name last_name age username password ::iterator test_i; for(test_i = alltests.begin(); test_i != alltests.end(); test_i++) { file id student_id date ","; file test_i->correct total ::iterator admin_i; for(admin_i = allAdmins.begin(); admin_i !- allAdmins.end(); admin_i++) { if(admin_i->username == username) { 1/A username is found, check password if(admin_i->password == password) { //Password matches loggedInAdmin.id admin_i->id; loggedInAdmin.username = admin_i->username; studentTests.push_back(*test_i); //Pass the copy by pointer return studentTests; } Functions for admin void add_question( string temp; Questions newQuestion; newQuestion.id = allQuestions.back().id + 1; cout > choice; while(choice > 2 || choice > choice; newQuestion.correct_alternative = choice; cout > category; newQuestion.category = category; allquestions.push_back(newQuestion); cout > question_id; //use an iterator to loop through all Questions, list :: iterator questions_i; bool question_found = false; for(questions_i = allquestions.begin(); questions_i != allquestions.end(); questions_i++) { if(questions_i->id question_id) { question_found = true; Questions editted = &questions_i; // We copy the current question cout questionfirstAlternativesecondAlternativecorrect_alternative> choice; while(choice > 2 || choice > choice; } cout category studentTests) { int correctsum = 0; int totalsum = 0; //use an iterator to loop through all Tests, list ::iterator tests_i; for(tests_i = studentTests.begin(); tests_i != studentTests.end(); tests_i ++) { correctSum += tests_i->correct; totalsum += tests_i->total; e) { if (totalsum == return e; }else{ // We need to cast it to float since we divide two integers float score = (float) correctSum/totalsum; return ceil(score # 100); void print_all_students() { int student Count = allstudents.size(); int student_data[ studentCount][3]; //use an iterator to loop through all Questions, list Student>::iterator students_i; int index = a; for(students i = allstudents.begin(); students_i != allstudents.end(); students_i++) {//Get all student tests list id); //calculate score int score = calculate_score(studentTests); // Store in array student_data[index][@] = index; //Student's index student_data[index][1] = students_i->id; //Student's id student_data[index][2] = score; //Student's score index++; } 1/Sort 2D array using selection sort for (int i = e; i student_data[min] [2]) min j; }swap (student_data(min), student_data[i]); cout first_name; //get first name string lastname = students_i->last_name; //get last name cout > input_username; //Doing a sequential search for the username in Student's list Student foundstudent; list ::iterator student_i; bool found = false; for(student_i = allstudents.begin(); student_i != allstudents.end(); student_i++) { if(student_i->username input_username) { foundstudent = *student_i; //get copy of the student found = true; //we say that we found a student == if(!found) { cout studentTests = get_student_tests(student_id); cout ::iterator test_i; for(test_i = studentTests.begin(); test_i != studentTests.end(); test_i+ { // Print only data of the student cout date correct total :: iterator question_i; for(question_i allquestions.begin(); question_i != allquestions.end(); question_i++) { cout category id question firstAlternative secondAlternative > choice; while(choice > 2 || choice > choice; } //check result if (choice question_i->correct_alternative) { cout myTests - get_student_tests(loggedInStudent.id); //use an iterator to loop through all Tests, list ::iterator test_i; for(test_i = myTests.begin(); test_i != myTests.end(); test_i++) { //Print only data of the loggedInStudent cout date correc total > choice; switch(choice) { case 1: current state = loginAdmin; break; case 2: currentstate - loginstudent; break; case 3: currentstate = quit; break; default: cout > username; cout > password; bool loginSuccess = login_admin(username, password); if (loginSuccess) { currentstate - adminFirstscreen; } else { cout > choice; switch(choice) case 1: add_question(); break; case 2: edit_question(); break; case 3: print_all_students(); break; case 4: search_student(); break; case 5: cout > username; cout > password; bool loginSuccess = login_student(username, password); if (loginSuccess) { currentstate = studentFirstscreen; } else { cout > choice; switch(choice) { case 1: take_quizo; break; case 2: print_student_results(); break; case 3: cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!