0% found this document useful (0 votes)
32 views

COM 1202 Introduction To Programming PAPER

The document contains a past exam paper for an Introduction to Programming course. It has two sections - Section A contains short answer and programming questions and Section B contains longer programming questions. Some questions ask students to write algorithms, programs, or code snippets to perform tasks like calculating area, comparing values, or converting between temperature scales.

Uploaded by

too robaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

COM 1202 Introduction To Programming PAPER

The document contains a past exam paper for an Introduction to Programming course. It has two sections - Section A contains short answer and programming questions and Section B contains longer programming questions. Some questions ask students to write algorithms, programs, or code snippets to perform tasks like calculating area, comparing values, or converting between temperature scales.

Uploaded by

too robaa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MAASAI MARA UNIVERSITY

REGULAR UNIVERSITY EXAMINATION


2017/2018 ACADEMIC YEAR
FIRST YEAR SECOND SEMESTER
BACHELOR OF SCIENCE (MATHEMATICS)
COURSE CODE: COM 1202
COURSE TITLE: INTRODUCTION TO
PROGRAMMING

DATE : 2ND MAY 2018 TIME: 0830 – 1030 HRS

INSTRUCTIONS:
Attempt all Questions in section A and any other two questions from section B

This paper consists of 5 printed pages. Please turn over.


SECTION A (30 Marks): Answer all questions from this section

QUESTION 1
(a)Explain the meaning of the following terms (3 Marks)
(i) Algorithm
(ii) String Concatenator
(iii) Variable

(b) Suggest a good variable name for the following variables providing a sample
declaration/assignment statement for each (5 Marks)
(i) Age
(ii) The number of stars in the galaxy
(iii)The average rainfall for the month of December
(iv) Your name
(v) A status value corresponding to failure or success
(c) Discuss four main qualities of a good programming language (4 Marks)
(d) Give the output of the following block of code (3 Marks)
class IfSample {
public static void main(String args[]) {
int x, y;
x = 10;
y = 20;
if(x < y) System.out.println("x is less than y");
x = x * 2;
if(x == y) System.out.println("x now equal to y");
x = x * 2;
if(x > y) System.out.println("x now greater than y");
// this won't display anything
if(x == y) System.out.println("you won't see this");
}
}
(e) Write a complete java program to converts a temperature from degrees
Fahrenheit to degrees Celsius. Use comments to explain your code.
Hint: °C = (°F - 32) x 5/9 (5 Marks)
(f) Write the code for the calculate area button to display the area on jLabel3
using the variables indicated in the following figure (3 Marks)

Page|2
textLen

textWid

(g) Write a program to do the following (6 Marks)


1. get from the user the radius of a cone in cm
2. get from the user the height of a cone in cm
3. compute the cone's volume
4. display the volume of the cone in cm3
The volume of a cone is ⅓πr2h where r is the radius and h is the height.

SECTION B (40 Marks): Answer TWO questions from this section

QUESTION 2
(a)
(b) Write an algorithm and a program to reads two values, determines the
largest value and prints the largest value with an identifying message
(5 Marks)
(c) Draw a flowchart to find the sum of first 50 natural numbers (5 Marks)

QUESTION 3
(a) Draw a flow chart to calculate the average marks of students (4 Marks)
(b) Write an input process and output (IPO) chart for a payroll system.
(4 Marks)
(c) Write a payroll program in java program using the IPO chart (b) above
(6 Marks)

Page|3
(d) Identify six errors by first indicating the line number then the error and
finally suggest how to correct the error (6 Marks)
1. public class Narf {
2. public static void zoop(string fred int bob) {
3. System.out.println(fred);
4. if (bob = 5) {
5. ping("not ");
6. } else {
7. System.out.println("!");
8. }}
9. }
10. public static void main(String[] args) {
11. int bizz = 5;
12. int buzz = 2;
13. zoop("just for", bzz);
14. clink(2*buzz)
15. }
16. public static void clink(int fork) {
17. System.out.print("It's );
18. zoop("breakfast ", fork) ;
19. }
20. public static void ping(string strangStrung) {
21. System.out.println("any " + strangStrung "more ");
22. }
23. }

QUESTION 4
(a)What is the output of the following block of code (2 Marks)
for (int i=1;i < 5;i++)
{
if (i % 2= =0)
System.out.println(“Hello World: ”+i);
}
(b) Write a program that will output the following (3 Marks)

Page|4
(c) Identify what is wrong with the following program code (3 Marks)
public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect;
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}
(d) Write an algorithm and a complete java program that reads three numbers
and prints the value of the largest number. (3 Marks)
(e)Write a pseudocode, algorithm, flowchart and a complete java program to
perform the following tasks
(i) Compute the perimeter of a rectangle (5 Marks)
(ii) Compute the area of a triangle (5 Marks)

END//

Page|5

You might also like