Вы находитесь на странице: 1из 3

KINGDOM OF SAUDI ARABIA

Ministry of Higher Education


UNIVERSITY OF JEDDAH
Faculty of Computing and Information Technology
‫كلية الحاسبات وتقنية المعلوما‬

Quiz 2 (8:00 – 8:50)


Programming I (CPCS 202)
Instructor: M. G. Abbas Malik Student Name: __________________________________
Date: October 11, 2015 Student ID: _____________________________________
Total Marks: 24 Obtained Marks: _________________________________

Instructions:

 Do not open this exam booklet until you are directed to do so.

 This exam will end in Twenty Five Minutes (25 Mins).

 Write your full name and Student registration No. clearly on the first page.

 When the exam is started, write your complete Student Registration No. clearly on the top of *EVERY* page.

 Write your solution in the space provided. If you need more space, write on the back of the sheet containing the problem. If still
you need more space then you can use extra sheets. In the case of extra sheet, clearly mention the question number whose answer
you are giving and you student registration number on the extra sheet.

 Plan your time wisely. Do not spend too much time on any one problem. Read through all of them first and attack them in order
that allows you to make the most progress.

 Show your work, as partial credit will be given. You will be graded not only on the correctness of your answer, but also on the
clarity and method correctness with which you express your answer.

Good luck.

1
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
UNIVERSITY OF JEDDAH
Faculty of Computing and Information Technology
‫كلية الحاسبات وتقنية المعلومات‬

Question 1: Fill in the blanks (24)

a) What is meant by the declaration of a variable? Explain you answer with an example. (2)

Declaration of a variable means that a variable is defined in our program and a memory area

according the size of the Data Type of the variable is reserved for it in RAM.

int a; // int is of size 4 byte thus for variable a, the memory area of 4 bytes is reserved for it in RAM

b) An informal high-level description of the operating principle of a computer program or other algorithm is
called Pseudo Code (1)
c) Every computer program consists of two things: (2)
(1) Data
(2) Processing
d) A Java class can be used as reference type of a variable. (1)
e) Declare a double variable named miles with initial value 100. (2)
double miles = 100;
f) Assume that variable int a = 1; and double d = 1.0;

What are the values of the variables d and a after the execution of the following line? (2)

d = 4 + d * d + 4 * ++a – 2

(1) d = 11

(2) a = 2

g) Identify and fix the errors in the following code: (4)

1 public class Test { 1 public class Test{


2 public void main(string [] args) { 2 public static void main(string [] args) {
3 int i = 1; 3 int i = 1;
4 int k = 100.0; 4 int k = 100; // or double k = 100.0;
5 int j = i / 5; 5 int j = i / 5;
6 System.out.println("j is " + (++j) + " and k is " + k) 6 System.out.println("j is " + (++j) + " and k is " + k);
7 } 7 }
8} 8}
After the correction of the above program, what is the output of the program?

j is 1 and k is 100

2
KINGDOM OF SAUDI ARABIA
Ministry of Higher Education
UNIVERSITY OF JEDDAH
Faculty of Computing and Information Technology
‫كلية الحاسبات وتقنية المعلومات‬

h) Computing Body Mass Index (BMI): BMI is a measure of health on weight. It can be calculated by taking
your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts
the user to enter a weight in pounds and height in inches and display the BMI. Note that one pound is
0.45359237 kilograms and one inch is 0.0254 meters. Here is a sample run: (10)
Please enter weight in pound: 95.5
Please enter height in inches: 50
BMI is 26.8573
import java.util.Scanner;

public class BMI{

public static void main (String [] args){

double weight, height, bmi;

Scanner input = new Scanner(System.in);

System.out.println(“Please enter weight in pound: ”);

weight = input.nextDouble();

System.out.println(“Please enter height in inches: ”);

height = input.nextDouble();

bmi = (weight * 0.45359237)/((height*0.0254)*(height*0.0254));

System.out.println(“BMI is ” + bmi);

Вам также может понравиться