In: Computer Science
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 questionsin the quiz.
Assuming that file containing questions is qfileand the file containing answers isafile, to run your script in the interactive mode it should be executed as:
./scriptname qfile afile
How to test:
Number_of_correct_answers
Number_of_wrong_answers
Solution:
QAscript.sh
#!/bin/bash
question=$1
answer=$2
correctAnswer=0
wrongAnswer=0
while read -r -u 4 line1 && read -r -u 5 line2;
do
echo "$line1"
read -p "Ans(yes/no) :" ans
if [ "$ans" == "$line2" ];
then
#increment
correctAnswer=$((correctAnswer+1))
else
wrongAnswer=$((wrongAnswer+1))
fi
done 4<$question 5<$answer
echo "Number_of_correct_answers $correctAnswer"
echo "Number_of_wrong_answers $wrongAnswer"
qfile.txt
Is there 12 months in a year?
Is there 31 days in the month of january?
Is 2+2 is equal to 4?
Is 7*2 = 16?
Does total number of alphabets in english is 26?
Number of vowels in English is 5?
Number of consonants in English is 21?
Is dollar,the currency of USA ?
Is 3%2 is equal to 0?
Is 2/2 is equal to 2?
afile.txt
yes
yes
yes
no
yes
yes
yes
yes
no
no
OUTPUT :
To Run=> ./QAscript.sh qfile.txt afile.txt