Question:
C++ Program question...Help?
?
2009-04-22 21:05:53 UTC
The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers:
1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. C 14. A 19.D
5. C 10. D 15. D 20. A
Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, which should be stored in another array. This activity should be placed in a function called input which returns the user’s answers (don’t forget data validation). After the student’s answers have been entered, the program should display a message indicating whether the student passed or not (considered pass if over 15 questions got right). To aid with this calculation, you are to use a function correct that accepts two characters and returns a boolean. correct works as follows:
returns true when invoked by correct(‘A’, ‘A’)
returns false when invoked by correct(‘B’, ‘D’)
The program should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question number of the incorrectly answered questions. A function report will be used that accepts two integers and an array, where the arguments represent the number correct, the number incorrect, and an array of missed questions, that performs the reporting feature. The main method should be driven off of a menu that allows the user to grade any number of tests they wish. This menu should be in its own function.
---------------------------------------------------------------------------
I have really tried, but still can't solve this problem.. Would any one help me out and finish the code for me? Thanks a lot !! It's really urgent..
Underneath is the attempt I've made so far:
------------------------------------------------------------------------------

#include "stdafx.h"
#include
using namespace std;
const int size = 20;
void input(char a[]);
bool correct(char a[],char b[]);

int main()
{
char b[size];
char answer[size]= {'b','d','a','a','c','a','b','a','c','d','b','c',' d','a','d','c','c','b','d','a'};
input(b);
correct(input(),answer[size]);
return 0;
}
void input(char a[])
{
for (int i = 0; i < size; i++)
{
cout << "Please enter your answer for question " << i+1 << ":";
cin >> a[i];
bool temp;
temp = (('a'<=a[i] && a[i] <= 'd') || ('A'<=a[i] && a[i] <= 'D'));
while (!temp)
{
cout << "Invalid Input!! Please enter again: \n";
cin >> a[i];
temp = (('a'<=a[i] && a[i] <= 'd') || ('A'<=a[i] && a[i] <= 'D'));
}
}

cout << "Your answer from question number 1 to number 20 are: ";
for(int i=0; i {
cout << a[i] << " ";
}


}

bool correct(char a[], char b[])
{
int correct=0;
int incorrect=0;
for (int count=0; count<=size-1;count++)
{
if (a[count] == b[count])
correct += 1; //If they got this one right, then add one to 'correct'.
else
incorrect +=1;
}

if(correct >= 15) //They got 15 right
{
cout << "You passed the test. Congratulations." << endl;
cout << "You answered " << correct << " questions right out of " << size;
}
else
{
cout << "You failed." << endl;
cout <<"You got " << incorrect << " questions wrong out of " << size;
}
}
Three answers:
femtorgon2
2009-04-22 21:44:55 UTC
You're having a problem in main with how you are calling the correct method.



correct(input(),answer[size]);



input() is not a value, or a correct call to the function.

input places the values you need to pass to the correct function into the array b. Also, answer[size] is a reference to a to a single cell of the array, which is actually past the end of the array. Depending on your compiler, it may allow you to do this, but it certainly won't function correctly.

This call should look like:



correct(b,answer);



Other than that I believe you are fine.



Oh, and I believe:

#include "stdafx.h"

is superfluous in this case. Won't cause any problems, but just had to mention it.
2014-07-15 14:12:40 UTC
I need help I have the same issue but im getting an error



The local Driver's License Office has asked you to write a program that grades the written

portion of the driver's license exam.

The exam has 20 multiple choice questions.

Here are the

correct answers:

1. B

6. A

11. B

16. C

2. D

7. B

12. C

17. C

3. A

8. A

13. D

18. D

4. A

9. C

14. A

19. D

5. C

10. D

15. D

20. A

Your program should store the correct answers shown above in an array.

It

should ask the user

to enter the student's answers for each of the 20 questions, and the answers should be stored in

another array.

After the student's answers have been entered, the program should display a list

showing the question numbers of the incorr

ectly answered questions, the total number of

correctly answered questions, and the total number of incorrectly answered questions. It should

then display a message indicating whether the student passed or failed the exam. (A student must

correctly answer

15 of the 20 questions to pass the exam.)

Create a function named

inputAnswers

to obtain the 20 answers from the user.

Create another function called

checkAnswers

to compare the user's answers to the correct

answers.

The function should display a list s

howing the question numbers of the

inncorrectly

answered questions and return the number of correct answers.

Create 1 more function called

displayResult

that takes the number of correct answers as a

parameter and determines if the user passed and displays

the total number of correctly answered

questions and the total number of incorrectly answered questions





This is what i have so far,

#include

#include

#include

#include

#include

#include

#include



using namespace std;



void inputAnswers();

void checkAnswers();

void displayResults();



int point1, point2, point3, point4, point5, point6, point7, point8, point9, point10, point11, point12,

point13, point14, point15, point16, point17, point18, point19, point20;

int c_answer, i_answer;

const int i_answers = 20;

int A, B, C, D;

int sum = (point1 + point2 + point3 + point4 + point5 + point6 + point7 + point8 + point9 + point10 + point11 + point12 +

point13 + point14 + point15 + point16 + point17 + point18 + point19 + point20);





int main()

{





//***************************************************************************************************************

// function calls

//***************************************************************************************************************



inputAnswers();

checkAnswers();

displayResults();



return 0;



}



//***************************************************************************************************************

// Return Type list - inputAnswers ( [20] )

//***************************************************************************************************************



void inputAnswers(int i_answer[20]) // Collects answers from student



{

const int i_answers = 20;

int count;



for (count = 0; count < 20; count++)



while (!((i_answers == 'a') || (i_answers == 'A')

|| (i_answers == 'b') || (i_answers == 'B')

|| (i_answers == 'c') || (i_answers == 'C')

|| (i_answers == 'd') || (i_answers == 'D')))



cout << "invalid" << endl;



cout << "Applicant, please enter your /n";

cout << i_answer << "answers." << endl;



cin >> i_answer[0];

cin >> i_answer[1];

cin >> i_answer[2];

cin >> i_answer[3];

cin >> i_answer[4];

cin >> i_answer[5];

cin >> i_answer[6];

cin >> i_answer[7];

cin >> i_answer[8];

cin >> i_answer[9];

cin >> i_answer[10];

cin >> i_answer[11];

cin >> i_answer[12];

cin >> i_answer[13];

cin >> i_answer[14];

cin >> i_answer[15];

cin >> i_answer[16];

cin >> i_answer[17];

cin >> i_answer[18];

cin >> i_answer[19];





return;



}









//***************************************************************************************************************

// Return Type checkAnswers ( [20] )

//***************************************************************************************************************





void checkAnswers() // Compares student's answers to the correct answers,



//displays wrong answers, and totals correct answers

{



int c_answer[20] = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D',

'B', 'C', 'D', 'A', 'D', 'C', 'C', 'D', 'D', 'A' };

int *i_answer;



if (i_answer[0] = c_answer[0])

point1 = 1;

else cout << "1. Incorrect" << endl;

point1 = 0;



if (i_answer[1] = c_answer[1])

point2 = 1;

else cout << "2. Incorrect" << endl;

point2 = 0;



if (i_answer[2] = c_answer[2])

point3 = 1;

else cout << "3. Incorrect" << endl;

point3 = 0;



if (i_answer[3] = c_answer[3])

point4 = 1;

else cout << "4. Incorrect" << endl;

point4 = 0;



if (i_answer[4] = c_answer[4])

point5 = 1;

else cout << "5. Incorrect" << endl;

point5 = 0;



if (i_answer[5] = c_answer[5])

point6 = 1;

else cout << "6. Incorrect" << endl;

point6 = 0;



if (i_answer[6] = c_answer[6])

point7 = 1;

else cout << "7. Incorrect" << endl;

point7 = 0;



if (i_answer[7] = c_answer[7])

point8 = 1;

else cout << "8. Incorrect" << endl;

point8 = 0;



if (i_answer[8] = c_answer[8])

point9 = 1;

else cout << "9. Incorrect" << endl;

point9 = 0;



if (i_answer[9] = c_answer[9])

point10 = 1;

else cout << "10. Incorrect" << endl;

point10 = 0;



if (i_answer[10] = c_answer[10])

point11 = 1;

else cout << "11. Incorrect" << endl;

point11 = 0;



if (i_answer[11] = c_answer[11])

point12 = 1;

else cout << "12. Incorrect" << endl;

point12 = 0;



if (i_answer[12] = c_answer[12])

point13 = 1;

else cout << "13. Incorrect" << endl;

point13 = 0;



if (i_answer[13] = c_answer[13])

point14 = 1;

else cout << "14. Incorrect" << endl;

point14 = 0;



if (i_answer[14] = c_answer[14])

point15 = 1;

else cout << "15. Incorrect" << endl;

point15 = 0;



if (i_answer[15] = c_answer[15])

point16 = 1;

else cout << "16. Incorrect" << endl;

point16 = 0;



if (i_answer[16] = c_answer[16])

point17 = 1;

else cout << "17. Incorrect" << endl;

point17 = 0;



if (i_answer[17] = c_answer[17])

point18 = 1;

else cout << "18. Incorrect" << endl;

point18 = 0;



if (i_answer[18] = c_answer[18])

point19 = 1;

else cout << "19. Incorrect" << endl;

point19 = 0;



if (i_answer[19] = c_answer[19])

point20 = 1;

else cout << "20. Incorrect" << endl;

point20 = 0;



return;

}













//***************************************************************************************************************

// Return Type product - displayResults ()

//***************************************************************************************************************







void displayResults() // determines whether the student passed the test



{



int Results = (sum / 20) * 100;



cout << sum << " correct answers" << endl;

cout << Results << "%" << endl;



if (sum >= 15)

cout << "You Passed!!!!!" << endl;

else

cout << "Try Again" << endl;

}



the error

Error 1 error C2660: 'inputAnswers' : function does not take 1 arguments c:\users\kocha3\documents\visual studio 2013\projects\cop2001\consoleapplication1\program6_7.cpp 36 1 ConsoleApplication1
gaurang_chintu
2009-04-22 21:15:43 UTC
reminds me of my advanced C++ class ...



it had taken away sleep of nights at that time ...



well .. keep trying ...



and best luck with your assignment ..


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...