[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Question:

The result of a quiz competition is to be prepared as follows:
The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer. Design a program to accept the number of participants N such that N must be greater than 3 and less than 11. Create a double dimensional array of size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single dimensional array of size 5. Display the scores for each participant and also the participant(s) having the highest score.
Example: If the value of N = 4, then the array would be:
Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data:
Example 1
INPUT : N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A
OUTPUT : Scores :
Participant 1 D A B C C
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest score: Participant 5
Example 2
INPUT : N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT : Scores :
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3
INPUT : N = 12
OUTPUT : INPUT SIZE OUT OF RANGE.

SOURCE CODE


import java.io.*;
import java.util.*;
public class ISC2017_QuizResult
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter number of participants  :");
        int n=sc.nextInt();
        System.out.println("\n");
        if(n<=3 || n>=11)
        {
            System.out.println("INPUT SIZE OUT OF RANGE");
        }
        else
        {
            System.out.println("Enter your answer in single line seperated by space");
            char ans[][]=new char[n][5];
            char key[]=new char[5];
            for(int i=0;i<n;i++)
            {
                System.out.print("Paticipant "+(i+1)+":");
                for(int j=0;j<5;j++)
                {
                    ans[i][j]=sc.next().charAt(0);
                }
            }
            System.out.print("\nEnter answer Key    :");
            for(int i=0;i<5;i++)
            {
                key[i]=sc.next().charAt(0);
            }
            int marks=0,high=0,pos;
            int score[]=new int[n];//Additional array to store score      
            System.out.println("\nSCORE:");
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<5;j++)
                {
                    if(ans[i][j]==key[j])
                    {
                        marks++;
                    }
                }
                score[i]=marks;
                if(marks>high)
                {
                    high=marks;
                }
                System.out.println("Participant "+(i+1)+" : "+marks);
                marks=0;
            }
            System.out.println("\n\nHighest score:");
            for(int i=0;i<n;i++)
            {
                if(score[i]==high)
                {
                    System.out.println("Participant "+(i+1));
                }
            }
        }
    }
}


OUTPUT




If you have any question then leave a comment below I will do my best to answer that question.

Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.