Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Without using vectors, I need to fix this program to test users on the Spanish vocab word for an English word. The voacb 1 .
Without using vectors, I need to fix this program to test users on the Spanish vocab word for an English word. The voacbtxt has both pairs of words with a space seperating them. This program does not actually quize the user or caculate overall totals for the total number of quizzes taken, quizzes pased, quizzes failed, or total words reviewed throughout all quizzes.
#include
#include
#include
#include
#include
using namespace std;
const int MAXWORDS ;
const string VOCABFILE "vocabtxt;
const string OUTPUTFILE "quizSummary.txt;
struct QuizResult
string userName;
int numQuestions;
int numCorrect;
double grade;
;
int countWordsInFile
ifstream fileVOCABFILE;
if file.isopen
cout "Error: Vocabulary file not found." endl;
return ;
int count ;
string line;
while getlinefile line
count;
file.close;
return count;
void generateRandomIndicesint indices int numWords, int numQuestions
srandtimenullptr;
for int i ; i numQuestions; i
indicesi rand numWords;
void displayQuizSummaryconst QuizResult& result
cout "Name: result.userName endl;
cout # of Question in the quiz: result.numQuestions endl;
cout # of Correct answers: result.numCorrect endl;
cout "Your Grade: result.grade endl;
cout "Decision: resultgrade "PASSED" : "FAILED" endl;
void writeQuizSummaryToFileconst QuizResult& result
ofstream outFileOUTPUTFILE, ios::app;
if outFile.isopen
cout "Error: Unable to open output file." endl;
return;
outFile "Name: result.userName endl;
outFile # of Question in the quiz: result.numQuestions endl;
outFile # of Correct answers: result.numCorrect endl;
outFile "Your Grade: result.grade endl;
outFile "Decision: resultgrade "PASSED" : "FAILED" endl;
outFile endl;
outFile.close;
void startQuiz
string userName;
int numQuestions;
cout "Welcome to EnglishSpanish Class. Please enter your name: ;
getlinecin userName;
cout "Maximum available words in the Quiz: MAXWORDS words." endl;
int numWords countWordsInFile;
if numWords
return;
cout "How many questions would you like to be quizzed on;
cin numQuestions;
cin.ignore; Clear the input buffer
if numQuestions numQuestions numWords
cout "Invalid number of questions." endl;
return;
int indicesnumQuestions;
generateRandomIndicesindices numWords, numQuestions;
ifstream vocabFileVOCABFILE;
if vocabFile.isopen
cout "Error: Vocabulary file not found." endl;
return;
int questionCount ;
int correctCount ;
string line;
cout endl;
cout "Quiz" endl;
cout endl;
while getlinevocabFile line && questionCount numQuestions
if indicesquestionCount questionCount
string english, spanish;
english line.substr line.find;
spanish line.substrlinefind;
string userTranslation;
cout "Question questionCount endl;
cout "English word: english endl;
cout "User answer in Spanish: ;
getlinecin userTranslation;
if userTranslation spanish
cout "Result: Correct!" endl;
correctCount;
else
cout "Result: Incorrect." endl;
cout endl;
questionCount;
vocabFile.close;
double grade staticcastcorrectCount numQuestions ;
QuizResult result userName numQuestions, correctCount, grade;
displayQuizSummaryresult;
writeQuizSummaryToFileresult;
int main
char choice;
do
startQuiz;
cout Do you want to take the quiz again YN: ;
cin choice;
cin.ignore; Clear the input buffer
while choice Y choice y;
cout "Thanks for taking the quiz." endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started