Quick Links to Application questions (with solutions)!

C++.

Java.

Saturday, April 17, 2010

A program to grade a student who has taken a multiple choice test. (a question has 4 options to choose from)

Let's understand the problem first before we start writing.
A student takes a multiple choice test.
A multiple choice question has four options to choose from.
Only one option out of four is the correct answer.
So, the chance of the student getting an incorrect answer in a question is 3 out of 4 or 75%
and the chance of him getting the correct answer is 1 out of 4 or 25%
Therefore,
When we grade the student,
we will use this system.

If the student gets 25% or above,
The student passes the test.
If the student gets 50% or above,
The student gets credit for the course for his commendable achievement.
If the student gets 75% or above,
The student completes the course with distinction.
If the student gets 100%;
The student, of course, has completed the test/exam with full mark.
But if the student unfortunately gets lower than 25%
The student fails the test.

----------


import java.util.Scanner;
class bananas
{
public static void main(String args[])
{
int nq,nca,p;
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of questions in the test.");
nq = input.nextInt();
System.out.println("Enter the number of correct answers in the test.");
nca = input.nextInt();
p = (nca*100)/nq; //it is not p = (nca/nq)*100;
System.out.println("The percentage of correct answers in the question =" + p +"%");
if (p == 100)
System.out.println("The student scores full mark!");
else if (p >= 75)
System.out.println("The student completes the course with distinction.");
else if (p >= 50)
System.out.println("The student passes and gets credit for the course.");
else if (p >= 25)
System.out.println("The student passes the test.");
else
System.out.println("The student fails the test.");
}
}

No comments:

Post a Comment