C++ assignment for string comparison

Hello, I am brand new to programing and I been having a hard time with c++, so i would love some help, since I really want to learn how to program in this language.

For this program I need to create a quiz grader, I have to compare the answers given in a file vs the correct answers given in an other file.I found a program that does exactly that but I also have some questions about it.

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
  #include <iostream>
#include <fstream> // to read input files and create output files
#include <string>
#include <iomanip> //to set precision and width
using namespace std;

void read_answers(const string& filename, string* arr, int size)
{
	//arr - pointer to string array
	//size = size of that array

	ifstream ifs(filename);
	if (!ifs)
	{
		cout << "Couldn't open answer file " + filename << endl;
		return;
	}

	for (int i = 0; i < size; ++i)
	{
		ifs >> arr[i];   //reading string from file inside array
	}
}

//count correct answers and display wrong ones
double find_correct_answers(string* correct_answers, string* given_answers, int size)
{
	double correct = 0;
	cout << "Welcome to Alicia's grading quizz " << endl;
	for (int i = 0; i < size; ++i)
		

	{
		if (correct_answers[i] == given_answers[i])
			++correct;
		else
			cout << "Question " << i + 1 << " incorrect!" << endl;

	}

	return correct;
}

int main()
{
	const int ARRAY_SIZE = 11;  //how many test questions are there
	double score{ 0 };

	string correct_answers[ARRAY_SIZE];
	string answers[ARRAY_SIZE];

	//first read correct answers stored in file CorrectAnswers.txt
	read_answers("test.txt", correct_answers, ARRAY_SIZE);

	//after that read given answers
	read_answers("given.txt", answers, ARRAY_SIZE);

	double correct = find_correct_answers(correct_answers, answers, ARRAY_SIZE);
	score = 100 * correct / ARRAY_SIZE;

	cout << "\nScore = " << score << "%" << endl;
	system("pause");
	return 0;


My first question is how can I display all the given answers and compare them to the correct answers something like this:

CORRECT ANS STUDENT ANS
C++ C++
for for
if if
variable variable
function function
return cheese INCORRECT
array array
void robots INCORRECT
reference reference
main main
prototype prototype

this is my first semester dealing with programing and C++ is giving me a headache.Thanks for the help.
Last edited on
I’m afraid this post is closed:
http://www.cplusplus.com/forum/general/198386/

I think you’d better write your own code.
Topic archived. No new replies allowed.