Code with Vinay

ISC practical papers › ISC 2017 › Question 2

Quiz Scores

ISC 2017 Computer Science Practical, Question 2 · Arrays and matrices, Simulation and records

The 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 (N×5) 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 :
.---------------.-----.-----.-----.-----.-----.
|               | Q.1 | Q.2 | Q.3 | Q.4 | Q.5 |
:---------------+-----+-----+-----+-----+-----:
| Participant 1 | A   | B   | B   | C   | A   |
:---------------+-----+-----+-----+-----+-----:
| Participant 2 | D   | A   | D   | C   | B   |
:---------------+-----+-----+-----+-----+-----:
| Participant 3 | A   | A   | B   | A   | C   |
:---------------+-----+-----+-----+-----+-----:
| Participant 4 | D   | C   | C   | A   | B   |
'---------------'-----'-----'-----'-----'-----'
.---------------------.---.---.---.---.---.
| Key to the question | D | C | C | A | B |
'---------------------'---'---'---'---'---'

Note: Array entries are line fed (i.e. one entry per line)

Test your program for the following 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 = 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.

Question: ISC 2017 Computer Science Paper 2 (Practical), Question 2, set by the Council for the Indian School Certificate Examinations (CISCE). Solution and video: Vinay Singh.

Java solution

ISC2017Q2.java Download GitHub
import java.util.*;

class Quiz {
    private int N;
    private char response[][], answer[];
    private int score[],highestScore;

    public Quiz(int N) {
        this.N = N;
        response = new char[N][5];
        answer = new char[5];
        score=new int[N];
    }

    public void input() {
        Scanner in = new Scanner(System.in);
        String input;

        for (int participant = 0; participant < N; participant++) {
            System.out.printf("%-10s %15s ", "", "Participant " + (participant + 1) + " ");
            input = in.nextLine();
            for (int question = 0; question < 5; question++) {
                response[participant][question] = input.charAt(2 * question);
            }
        }
        System.out.printf("%-10s %15s ", "", "Key: ");
        input = in.nextLine();
        for (int question = 0; question < 5; question++) {
            answer[question] = input.charAt(2 * question);
        }
        in.close();
    }

    public void display() {
        for (int row = 0; row < N; row++) {
            System.out.println(Arrays.toString(response[row]));
        }

        System.out.println(Arrays.toString(answer));

    }
    public void prepareResult(){
        int max=0,question,participant;
        for( question=0; question<5; question++){
            for( participant=0; participant<N; participant++){
                if(response[participant][question]==answer[question]){
                    score[participant]++;
                }
                if(score[participant]>max){
                    max=score[participant];
                }
            }
            
        }
        highestScore=max;
    }
    public void displayResult(){
        System.out.printf("%-10s %-15s \n", "OUTPUT:", "Scores");
        for( int participant=0; participant<N;participant++){
            System.out.printf("%-10s %15s \n", "", "Participant " + (participant + 1) + " = "+score[participant]);
        }
        String msg="Highest score: ";
        for( int participant=0; participant<N;participant++){
            if(highestScore==score[participant]){
                System.out.printf("%-10s %15s %-20s\n", "", msg ,"Participant "+(participant+1));
                msg="";
            }
        }
    }
}

public class ISC2017Q2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.printf("%-10s %15s ", "INPUT:", "N = ");
        int N = in.nextInt();
        Quiz quiz = new Quiz(N);
        quiz.input();
        //quiz.display();
        quiz.prepareResult();
        quiz.displayResult();
        in.close();
    }
}

All these solutions in one free book

Pragmatic Solutions to ISC Computer Science Practical Problems collects every program from 2004 to 2021 in a 202-page PDF.

Get the free PDF ₹0 ISC 2027 mock papers