Question

Using C++ programming Write a program that compares a student’s answers in a 5-question quiz to...

Using C++ programming

Write a program that compares a student’s answers in a 5-question quiz to the teacher’s answer key.

The answer key is: {'C', 'D', 'B', 'B', 'A'}

You MUST use TWO functions: One for input and the other for comparing/output. The output is simply the # of questions answered correctly. This program will test your ability to handle parallel arrays.

Output:

Look at the questions and choices on page 999 of your textbook.

Enter the UPPERCASE letter of your choice for each question when prompted below.

Enter your response for Question 1: [user types: a]

Enter your response for Question 2: [user types: D]

Enter your response for Question 3: [user types: B]

Enter your response for Question 4: [user types: b]

Enter your response for Question 5: [user types: A]

You answered 4 out of 5 questions correctly


Notes and Hints:

1) You must accept both upper and lower case responses from the student

2) The only things in main() are the constant, arrays, introductory output, and two function calls

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<iostream>

#include<string.h>

using namespace std;

char* input_student_key() //function for taking input student key

   {

       char student_key[5]; //student key array

       int i;

       for(i=0;i<5;i++) //iterate loop to take the key values

           {

               cout << "Enter your response for Question " << i+1 << ": ";

               cin >> student_key[i];

               if(student_key[i]>='a' && student_key[i]<='z') //check if the key is lower case then convert to upper

           {

           student_key[i] -= 32;

           }

           }

       return student_key; //finally return the student key

   }

int compare_keys(char* teachers_key,char* student_key) //function used to compare the keys

   {

   int i,count=0;

   for (i=0;i<5;i++) //iterate over loop

       {

       if (teachers_key[i]==student_key[i]) //check the teacher key value equals to student key

           {

           count++; //if yes increment the value

           }  

       }

   return count;       //finally return the count

   }

int main()

{

   char teachers_key[]={'C','D','B','B','A'}; //teachers key decalration

   char *student_key=input_student_key();   //calling input function and storing results

   int results_count=compare_keys(teachers_key,student_key); //calling compare function and stroing returned result

   cout << "You answered " << results_count << " out of 5 questions correctly."; //finally printing the number of correct answers count

   return 0;

}


Code and Output Screenshots:

#include<iostream> #include<string.h> using namespace std; char* input_student_key() 1/function for taking input student key

Enter your response for Question 1: a Enter your response for Question 2: D Enter your response for Question 3: B Enter your

Note: if you have any queries please post a comment thanks a lot..always available to help you...

Add a comment
Know the answer?
Add Answer to:
Using C++ programming Write a program that compares a student’s answers in a 5-question quiz to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • Please solve this question using c++ language Problem 2. More Probleml. The program builds the array...

    Please solve this question using c++ language Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that...

    Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that uses at least two arrays, and has at least one loop that accesses the data in the arrays. As long as your program satisfies the requirements listed below, you are free to design and write any type of program that you care to. You are encouraged to be creative, and pick something that has meaning for you, because you'll have more fun. Feel free...

  • In C... Write a program to simulate a pick-5 lottery game. Your program must generate and...

    In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...

  • Write a C++ program that will deliver a multiple choice quiz. The program should Read questions...

    Write a C++ program that will deliver a multiple choice quiz. The program should Read questions from the file questions.txt Read the answer key for each test question from the file answers.txt When the program runs it will present each question and obtain a response After all questions have been answered, the program should output a report with the question number, the response given and either “correct” or “incorrect”. Show the output on the console and store the report in...

  • The answer need to write in C programming. QUESTION 2 Write a program using array to...

    The answer need to write in C programming. QUESTION 2 Write a program using array to generate a multiplication table based on the user's input. For example if user enter 5 as input then a multiply table for 1 to 5 is printed as output as shown in Figure Q2. There are three main steps in this program which are: Print rows (a) (b) Print columns Print multiplication of data inside table (c) Select C:\example1 \bin\Debuglexample 1.exe enter the value...

  • This is a C++ question we do not use namespace std at the beginning of the...

    This is a C++ question we do not use namespace std at the beginning of the program 9. Arrays: Functions and Reading From File Although this code is a little long, the strategy is straightforward and it will really help you practice functions. I have provided a large amount of detail to help you out. In a nutshell, you're going to read some numbers from a file (into an array) and then ask the user for a number that will...

  • Using C++ programming. This exercise will test your knowledge of passing structures to functions. Create a...

    Using C++ programming. This exercise will test your knowledge of passing structures to functions. Create a structure that stores information about various plumbers that you are getting repair estimates from. As you can see from the output, the structure must store the name, phone number, and estimate. Since you are only getting estimates from two companies, only two structure variables are needed. Functions: 1) Get data from the user. This function must be called TWICE. 2) Print the summary you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT