Assignment

Pages: 12
I am to make an application that will grade a multiple choice exam with 10 questions. Here are the correct answers for the exam.
1. B
2. D
3. A
4. A
5. C
6. A
7. B
8. A
9. C
10.D
In main() I am to define 2 arrays. Initializing one array with the correct answers given. Initializing while declaring it...

Then I have to call these functions:
Pass the second array to a function that will prompt the user to enter their answers to the ten questions and store them in that array. Accepting only letters A, B, C, D as answers. I must use a while loop for this validation. Can't end the program if the user enters invalid data. *There are no questions for this exam, but instead pretending the student has been given a paper and only used the computer to record their answer.

The second function will receive the two array as parameters. This function will compare the letters in the two arrays and output a report showing whether each question was answered correctly or incorrectly. The function will total the number correct and return it to main.

The third and last function will receive the number correct as its parameter and output if the student passed or failed the quiz. A student must correctly answer 6 questions correctly to pass the exam.

*must use prototypes
*no global variables
*define the arrays in main and pass them to the required functions. Remember you are passing by reference.


If someone could please help me - it is due tomorrow, maybe with some pseudo, or some code that will help put it together. thank you - Richard
how do i delete the other post?
Deleting posts is generally not possible in forums such as these.
I'm very stuck with the loop. I don't know where to start
Start here:

In main() I am to define 2 arrays. Initializing one array with the correct answers given. Initializing while declaring it...


Write out the lines of code that do this and only this.

Make sure your code compiles and runs.

Show us your work.
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;



int main()
{
char rightAnswers[10] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D'};

int questions[10] = {1,2,3,4,5,6,7,8,9,10};

system("pause");
return 0;

}

Now work on the function that accepts the array and checks it.
char enterAnswers(int questions)
{
int count; //loop counter

//Input the answers to the questions
for (count = 0; count < questions; count++)
{
cout << "Enter your answer for question "
<< (count + 1) << ": ";
cin >> questions;
}

//Display the answers
cout << "The answers you entered are:";
for (count = 0; count < questions; count++)
cout << " " << questions;
cout << endl;
}
You are doing well. Before going as far as Zhuge suggests, I think we should take this in smaller steps.

I would recommend adding the declarations for the three functions -- no code, just the declarations -- and make sure it compiles and runs.

Then add the functions with empty bodies. Again, make sure it compiles and runs.

Then add calls to the functions in main. Compile/run. You will just be calling functions with empty bodies at this point.

Only when that's done, start work on the function bodies. But show us what you have before you get to this point and we'll see if we can help.

Also, the button on the side that looks like "<>" will put your code in code tags. Highlight your code and click the button. You also can go back and edit your earlier post to add code tags if you want.

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
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;


char enterAnswers(int questions);
int compareLetters(char rightAnswers, int questions);
int passOrFail();


int main()
{
    char rightAnswers[10] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D'};
    
    int questions[10] = {1,2,3,4,5,6,7,8,9,10};   

    //Call the functions
    char enterAnswers();
    int compareLetters();
    int passOrFail();
    
    system("pause");
    return 0;
}



char enterAnswers(int questions)
{
    int count; //loop counter

	//Input the answers to the questions
	for (count = 0; count < questions; count++)
	{
		cout << "Enter your answer for question "
			 << (count + 1) << ": ";
		cin >> questions;
	}

	//Display the answers
	cout << "The answers you entered are:";
	for (count = 0; count < questions; count++)
		cout << " " << questions;
	cout << endl;
}



int compareLetters(char rightAnswers, int questions)
{
       
}



int passOrFail()//Parameter will be the number correct
{
    
}

char enterAnswers(int questions);

questions will need to be passed as a pointer or array.
Hmmm something of this sort? I passed questions as an array i believe.


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
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;


char enterAnswers(int questions);
int compareLetters(char rightAnswers, int questions);
int passOrFail();


int main()
{
    char rightAnswers[10] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D'};
      
    const int SIZE = 10;
    int questions[SIZE] = {1,2,3,4,5,6,7,8,9,10};
    
    //Call the functions
    char rightanswers();
    int compareLetters();
    int passOrFail();
    
    //
    for (int index = 0; index < SIZE; index++)
        enterAnswers(questions[index]);
        
    
    system("pause");
    return 0;
}



char enterAnswers(int question)
{
    cout << question << ". ";
    
    
        
}



int compareLetters(char rightAnswers, int questions)
{
       
}



int passOrFail()//Parameter will be the number correct
{
    
}
as my catch to the questions,
you do not need the initialize array, just declare it first..
and the function call rightanswer etc, mustn't need to above the enterAnswer.

the reference syntax should like this.
1
2
3
char enterAnswers(int *question)
{      
}


and we can call function with syntax like this ?
1
2
3
char rightanswers();
    int compareLetters();
    int passOrFail();

please guide me, i am new too :)
I missed something earlier: why did you define questions and answers as two different types? Note: you are going to need to compare them later on.

Pass the second array to a function that will prompt the user to enter their answers to the ten questions and store them in that array. Accepting only letters A, B, C, D as answers. I must use a while loop for this validation. Can't end the program if the user enters invalid data. *There are no questions for this exam, but instead pretending the student has been given a paper and only used the computer to record their answer.



You can pass it one of two ways:
 
void enterAnswers(char* questions); // as a pointer 


or:
 
void enterAnswers(char questions[]); // as an array 


There is no practical difference. Not that these return "void".

When passing arrays, it is best to always be explicit about the size:

void enterAnswers(char* questions, size_t len);

That way, if the number of questions changes, enterAnswers does not need to change.

Re-read the instructions for the other functions and fix their calling signature.
Last edited on
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
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;


void enterAnswers(char questions);
void compareLetters(char correctAnswers[] , char questions[])


int main()
{
    //First Array
    char correctAnswers[] = {'a', 'd', 'a', 'a', 'c', 'a', 'b', 'a', 'c', 'd'};
    
    //Second Array  
    char questions[] = {1,2,3,4,5,6,7,8,9,10};
    
    
    //Pass the second array to a function:
    void enterAnswers(char questions[]);
    //Call the other functions, both arrays in the second function
    void compareLetters(char correctAnswers[] , char questions[]);
    void passOrFail();
     
    system("pause");
    return 0;
}



void enterAnswers(char questions)
{
    //Stuck on the while loop
    //Will the prompt be inside the loop? 
     
            
}



void compareLetters(char correctAnswers[] , char questions[])
{
       
}



void passOrFail()//Parameter will be the number correct
{
    
}

Have you tried compiling and running this yet?
Yes, works fine.
this does nothing but am I on the right track for the loop?

1
2
3
4
5
6
while(questions != 'a' && questions != 'b' && questions != 'c' &&
          questions != 'd')
        {
            cout << "Please enter a, b, c, d for your answer for question: ";
            cin >> questions;
        }
Maybe. Your problem statement lists upper case characters. Does case matter for this assignment?
Pages: 12