Sei sulla pagina 1di 4

CAT -1 Model Question Paper

Programme : B.Tech
Course Title : Problem Solving Using Java Code : CSE1004
Time : Max. :
01:30 Hours 50
Marks
Part A- Answer all the Questions (5 x 10= 50 marks)
1. Here's a Snakes and ladders board game to play with your friends and family.

How to play:
 Each player puts their counter on the space that says 'start here'.
10
 Take it in turns to roll the dice. Move your counter forward the number of
spaces shown on the dice.
 If your counter lands at the bottom of a ladder, you can move up to the top
of the ladder.
 If your counter lands on the head of a snake, you must slide down to the
bottom of the snake.
 The first player to get to the space that says 'home' is the winner.

Draw the flow chart for the above scenario.


Answer :
2. write the algorithm to generate the following series for n terms.
𝑥 𝑥 𝑥 10
𝑥− + − …
3! 5! 7!
Answer:

Step 1: Start the Program


Step 2: Get x and n value
Step 3: Initialize i=1
Step 4: Calculate x= x*3.14 /180
Step 5: Assign t=x, sum=x
Step 6 : Repeat the steps until ( i<n)
t=(t*(-1)*x*x)/(2*i*(2*i+1))
sum=sum + t
i=i+1
else go to Step 8
Step 7: Go to Step 6
Step 8: Print sum
Step 9: Stop the program

3. Write an algorithm to check whether a number entered by user is a number that 10


is divisible only by itself and 1.
Answer:

Step 1: Start the Program


Step 2: Declare variables n, i, flag.
Step 3: Initialize variables flag=1, I=2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
If n%i==0
flag=0
Go to step 6
i=i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop the Program

4. Tirumala Tirupati Devasthanams board offering a Divya Darshan booking. The


fare and discount details as follows:
Non Season Months [Jan-March] Adult – Rs.1000 Child - Rs. 750 10% Discount
[Oct –Dec ] Adult - Rs.750 Child - Rs. 500 12% Discount
Season Months [April-June] Adult - Rs.2000 Child - Rs.1500 No Discount
[July-Sep ] Adult - Rs.3000 Child - Rs. 2500 No Discount 10
Write a Java program to read month, no. of adults and no. of children and find the
total booking price.
Input Output/ format :
Enter the month of Visit
5
Enter the number of Adult
2
Enter the number of child
1
Total Booking Price is Rs. 5500.00
Answer:

import java.util.*;
class Tirumala
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the month of Visit");
int m=sc.nextInt();
System.out.println("Enter the number of Adult");
int a=sc.nextInt();
System.out.println("Enter the number of Child");
int c=sc.nextInt();
double price;
if(m>=1 && m<=3 )
{
price=a*1000+c*750 -((a*1000+c*750)*0.1);
System.out.printf("Total Booking Price is Rs. %.2f",price );
}

if(m>=10 && m<=12 )


{
price=a*750+c*500 -((a*750+c*500)*0.12);
System.out.printf("Total Booking Price is Rs. %.2f",price );
}

if(m>=4 && m<=6 )


{
price=a*2000+c*1500 ;
System.out.printf("Total Booking Price is Rs. %.2f",price );
}

if(m>=7 && m<=9 )


{
price=a*3000+c*2500;
System.out.printf("Total Booking Price is Rs. %.2f",price );
}

}
}

Note :
It is also possible to solve using switch case.
5. Write a java program to get the following inputs from the student and calculate
the cut-off mark. Get the following inputs from user,
 Student Name
 Counselling Code
 State
 Get the Maths, Physic and Chemistry marks
 Cut –off = ((Maths+Physics+Chemistry)/ 300)*100
 Print the cut-off mark with 2 decimal points (eg. 75.25)

10
Expected Output

Student Register Number : 19XXXXX


Counselling Code: 18001153
State : AP
Maths : 50
Physics: 50
Chemistry: 50
Cut-off : 50.00

Answer :
import java.util.*;
class Student
{
public static void main(String args[])
{
System.out.println("Enter Student Register Number");
Scanner sc=new Scanner(System.in);
int regno=sc.nextInt();
System.out.println("Enter Counselling ID");
int id=sc.nextInt();
System.out.println("Enter Employee State");
String str2=sc.next();
System.out.println("Enter maths mark");
int m=sc.nextInt();
System.out.println("Enter physics mark");
int p=sc.nextInt();
System.out.println("Enter chemistry mark");
int c=sc.nextInt();
double cutoff=((m+p+c)/300)*100;
System.out.println("Student Register Number:"+regno);
System.out.println("Counselling ID:"+id);
System.out.println("State:"+str2);
System.out.println("Maths Mark:"+m);
System.out.println("Physics Mark:"+p);
System.out.println("Chemistry Mark:"+c);
System.out.println("Cut-off Mark:"+cutoff);
}
}

Potrebbero piacerti anche