0% found this document useful (0 votes)
171 views6 pages

Programming Exam Questions and Solutions

The document is a practice exam for an Introduction to Programming course. It contains 3 programming problems testing concepts like conditionals, loops, functions, and arrays. Problem 1 has multiple choice questions testing code snippets. Problem 2 asks students to write a program calculating car insurance premiums based on age and accidents. Problem 3 asks students to write a program that continuously takes user input until -1, then displays statistics of the entered values. The document provides sample runs for problems 2 and 3 to demonstrate expected output. It is a practice exam assessing students' understanding of core programming concepts through short programming challenges.

Uploaded by

32230951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views6 pages

Programming Exam Questions and Solutions

The document is a practice exam for an Introduction to Programming course. It contains 3 programming problems testing concepts like conditionals, loops, functions, and arrays. Problem 1 has multiple choice questions testing code snippets. Problem 2 asks students to write a program calculating car insurance premiums based on age and accidents. Problem 3 asks students to write a program that continuously takes user input until -1, then displays statistics of the entered values. The document provides sample runs for problems 2 and 3 to demonstrate expected output. It is a practice exam assessing students' understanding of core programming concepts through short programming challenges.

Uploaded by

32230951
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Computer Science and Information Technology

Course CSCI250 Introduction to Programming


Date 25 Nov 2022 Time 12:30 –01:45 Duration 75 minutes
Pages 6 Calculators Not Allowed Documents Not Allowed

Problem #1: [30 pts: 5 pts for each]


Circle the correct answer
What is the output of the following code? Output

a) 67
char ch = ‘A’;
b) B
System.out.println((char)(ch + 2));
c) C
d) SyntaxError

a)135
for(inti = 1; i< 6; i += 2)
b) Nothing will be printed
if(i % 3 == 0)
System.out.print(i); c) 123456

d) 3
int m = 2;
switch(m){ a) 2
case 2: m+=1; b) 3
case 4:m-=1;break;
c) 4
case 9: m+=1;break;
d) Syntax Error
}
System.out.println(m);
if(2 < 6)
System.out.print(“A”);
if(4 > 4)
System.out.print(“B”);
if(9 < 6)
a) ABD
System.out.print(“C”);
b) AE
else
c) ADE
System.out.print(“D”);
d) SyntaxError
System.out.print(“E”);

Page 1 of 6
int k = 1;
while (k <= 3) {
if (k % 2 == 0) a) @#@#
System.out.print('@'); b) #@##
c) #@##@
System.out.print('#'); d) #@@@#
k++;
}
a. int f = 1, s = 0;
b. boolean x = false;
c. do { a) 8
b) 4
s += f;
c) 1
f *= 3;
d) 13
d. } while (x);
System.out.println(s + f);

Page 2 of 6
Problem #2: [35 pts]
Write a program that computes the cost of car insurance premium. The cost depends on the age of the driver and
the number of accidents that he has had during the last five years.
The basic insurance cost is $750/year with a surcharge of $100 if the driver is under 25 or above 65. The additional
surcharge for accidents is given in the following table:

Number of accidents Surcharge


1 $25
2 $50
3 $100
4 or more Insurance not accepted

Sample run 1:
Enter the driver's age: 30
Enter the number of accidents in the past 5 years: 6
Insurance not accepted.

Sample run 2:
Enter the driver's age: 20
Enter the number of accidents in the past 5 years: 1
The insurance cost for driver whose age is 20 and has had 1 accident(s) in the past
five years is $875

Page 3 of 6
Page 4 of 6
Problem #3:[35 pts]
Write a program that asks the user for entering certain values, until he/she ends the program by entering -1. When
the user finishes entering the numbers, the program should display the number of entered numbers, their sum,
average and the maximum.
Sample run:
Enter a value (-1 to end program): 34
Enter a value (-1 to end program): 56
Enter a value (-1 to end program): 77
Enter a value (-1 to end program): -1

You entered 3 values


Their sum is: 167.0
Their average is 55.67
The highest number is: 77.0

Page 5 of 6
Page 6 of 6

You might also like