Question: Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The
- Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (lets call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one and wait for users response. The users response should be then compared with the correct answer to that specific questions read from the file containing answers and as a result the script should produce statistics as to how many good and how many wrong answers were provided.
Questions should be formed so that either, YES or NO answer would apply. Questions file format can by any, whilst the answers format should contain only YES or NO answers, one answer per line. There should be exactly 10 questions in the quiz.
Assuming that file containing questions is qfile and the file containing answers is afile, to run your script in the interactive mode it should be executed as:
./scriptname qfile afile
How to test:
- Create a text file containing a number of questions.
- Create a text file containing correct answers to these questions.
- Execute your script:
- It should ask questions one at a time and then wait for your answer.
- Your answer should be then compared with the appropriate answer read from the file with answers,
- Depending on the correctness of your answer, the script it should count the answer and display statistics as:
Number_of_correct_answers Number_of_wrong_answers
However, if your script is executed with 3 command line parameters it should execute in automatic mode meaning that the first file should still be treated as questions, second as correct answers, but the third parameter should be treated as file containing users answers (for example sent on-line for verification). In such case the script should NOT display any questions, it only should compare users answers with the correct answers.
In the interactive mode the script should provide full statistics about the quiz results, hence the only thing your script is expected to return are two numbers without any additional prompt (like The number of correct answers is: or The number of wrong answers is: ), just numbers, each number in a separate line, reflecting the number of correct and wrong answers. Neither, runtime messages nor error messages should appear on the screen (you may need to re-direct the standard error stream for operations that might be source of any kind of error as command 2>/dev/null).
In the automatic mode the script should only return one number corresponding to the number of correct answers. Neither, runtime messages nor error messages nor prompts whatsoever should appear on the screen (you may need to re-direct the standard error stream for operations that might be source of any kind of error as command 2>/dev/null).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
