Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / C++ Can I get help with the following code, my brain is mush right now, and I can't fathom what the includes are

C++ Can I get help with the following code, my brain is mush right now, and I can't fathom what the includes are

Computer Science

C++

Can I get help with the following code, my brain is mush right now, and I can't fathom what the includes are. Could I also get additional help with fixing errors?

 

 

#include <iostream>
#include
#include
#include
using namespace std;
// Function to get float data from user
float getFloatData(string message) {
float user_input;
cout << message;
cin >> user_input;
return user_input;
}
// Function to get integer data from user
int getIntegerData(string message) {
int user_input;
cout << message;
cin >> user_input;
return user_input;
}
// Function to get string data from user
string getStringData(string message) {
string user_input;
cout << message;
cin >> user_input;
return user_input;
}
// Function to load the dictionary from the txt file
void loadDictionary(string filename, vector &english_words, vector &spanish_words) {
string line;
ifstream myfile (filename);
// Error checking to make sure the file exists
if (myfile.is_open()) {
while ( getline (myfile,line)) {
// Separate English and Spanish words into two separate vectors
english_words.push_back(line.substr(0, line.find(",")));
spanish_words.push_back(line.substr(line.find(",") + 1));
}
myfile.close();
}
else {
cout << "Error: File not found!" << endl;
}
}
// Function to display the main menu
void displayMenu() {
cout << "---------------------------------------------------------" << endl;
cout << "Welcome to the Ally Baba English-Spanish Class." << endl;
cout << "Please enter your name: ";
}
// Function to display the quiz menu
void quizMenu() {
cout << "Maximum available words in the Quiz: " << english_words.size() << " words." << endl;
cout << "How many questions would you like to be quizzed on? ";
}
// Function to write the quiz summary to an output file
void writeToFile(string filename, vector english_words, vector spanish_words, vector user_answers, vector results) {
ofstream myfile;
myfile.open (filename);
myfile << "Name: " + name << endl;
myfile << "# of Question in the quiz: " << num_questions << endl;
myfile << "# of Correct answers: " << num_correct << endl;
myfile << "Your % Grade: " << final_grade << endl;
myfile << "Decision: " << decision << endl;
myfile << "Questions and Answers: " << endl;

for (int i = 0; i < num_questions; i++) {
myfile << english_words[i] + ": " + user_answers[i] + " - " + (results[i] ? "Correct" : "Incorrect") << endl;
}

myfile.close();
}
// Function to display the quiz grade
void displayQuizGrade(int num_correct, int num_questions) {
float final_grade = (float)num_correct / num_questions * 100;
cout << "Your % Grade: " << final_grade << endl;
if (final_grade >= 80) {
cout << "Decision: PASSED" << endl;
}
else {
cout << "Decision: FAILED. The passing score is 80%" << endl;
}
}
// Function to print the header
void header() {
cout << "---------------------------------------------------------" << endl;
cout << "Quiz" << endl;
cout << "---------------------------------------------------------" << endl;
}
// Function to print the footer
void footer() {
cout << "The quiz report with questions/answers are stored in an output file: quizSummary.txt." << endl;
cout << "---------------------------------------------------------" << endl;
}
// Main function
int main() {
string filename = "dictionary.txt";
vector english_words;
vector spanish_words;
vector user_answers;
vector results;
string name;
int num_questions;
int num_correct = 0;
float final_grade;
string decision;
char retake_quiz;
// Load the dictionary from the txt file
loadDictionary(filename, english_words, spanish_words);
// Display the main menu
displayMenu();
cin >> name;
// Print the count of English words in the file
cout << "Maximum available words in the Quiz: " << english_words.size() << " words." << endl;
// Prompt the user to enter the number of questions to be quizzed on
quizMenu();
num_questions = getIntegerData("");
// Error checking to make sure the number of questions is valid
if (num_questions > english_words.size() || num_questions < 1) {
cout << "Error: Invalid number of questions!" << endl;
return 0;
}

// Print the header
header();
// Quiz loop
for (int i = 0; i < num_questions; i++) {
cout << "Question " << i+1 << endl;
cout << "English word: " << english_words[i] << endl;
user_answers.push_back(getStringData("Your answer in Spanish: "));
if (user_answers[i] == spanish_words[i]) {
results.push_back(true);
num_correct++;
cout << "Result: Correct!" << endl;
}
else {
results.push_back(false);
cout << "Result: Incorrect." << endl;
}
cout << "---------------------------------------------------------" << endl;
}
// Display the quiz summary
cout << "Quiz Summary" << endl;
cout << "Name: " << name << endl;
cout << "# of Question in the quiz: " << num_questions << endl;
cout << "# of Correct answers: " << num_correct << endl;
displayQuizGrade(num_correct, num_questions);
// Write the quiz summary to an output file
writeToFile("quizSummary.txt", english_words, spanish_words, user_answers, results);
// Print the footer
footer();
// Prompt the user to retake the quiz
cout << "Do you want to take the quiz again (Y/N): ";
cin >> retake_quiz;
if (retake_quiz == 'Y' || retake_quiz == 'y') {
main();
}
else {
cout << "Thanks" << endl;
cout << "Quizzes Summary" << endl;
cout << "How many times the quiz taken: 1" << endl;
cout << "How many times passed: 0" << endl;
cout << "How many times failed: 1" << endl;
cout << "Total Count of questions in all quizzes: " << num_questions << endl;
cout << "Highest grade: " << final_grade << "%" << endl;
}

return 0;
}

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE