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

Structural Programming Set2 EXAM

This document provides instructions for a 2-hour examination on structural programming to be taken in January 2024. It includes 20 multiple choice questions in Section A worth 20 marks, and 10 structured questions in Section B worth 50 marks, covering topics like conditions, loops, arrays, functions, and structures in C programming. Students are expected to answer all questions clearly and show their work.

Uploaded by

T.B Abanda
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Structural Programming Set2 EXAM

This document provides instructions for a 2-hour examination on structural programming to be taken in January 2024. It includes 20 multiple choice questions in Section A worth 20 marks, and 10 structured questions in Section B worth 50 marks, covering topics like conditions, loops, arrays, functions, and structures in C programming. Students are expected to answer all questions clearly and show their work.

Uploaded by

T.B Abanda
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

FIRST SEMESTER EXAMINATION 2023/2024

SCHOOL: ENGINEERING AND TECHNOLOGY


Department: EDM & SWE
Course Title: Structural programming
Course code:
Credit Value:
Course Status: Specialty
Time allowed: 2 hours
Lecturer: Tebi Godlove
Level: 100
Venue: HITBAMAS
Date of Exam: JANUARY, 2024
Session: Normal Session
Max. 70 Marks
Answer all question clearly, well numbered

SECTION A: 20marks

1. Which keyword is used to define the b) To define a condition in a conditional


condition in a conditional statement? statement

a) for c) To store multiple values in a single


variable
b) if
d) To define a function or method
c) while
3. Which of the following is NOT a type of
d) switch loop in programming?

2. What is the purpose of a loop in a) for loop


programming?
b) if loop
a) To execute a block of code repeatedly
c) while loop
d) do-while loop b) int(arr)[];

4. What is the output of the following code c) arr int[];


snippet? ``` int i = 0; while (i < 5) { i++; }
System.out.println(i); ``` d) int arr[];

a) 0 8. How can you access the third element of


an array named "numbers"?
b) 4
a) numbers[2]
c) 5
b) numbers[3]
d) 6
c) numbers[1]
5. Which of the following is NOT a valid
comparison operator in programming? d) numbers[0]

a) > 9. What type of value does a function return


in programming?
b) ==
a) Integer
c) <>
b) String
d) <=
c) Character
6. How many elements can an array hold in
programming? d) It depends on the code inside the function

a) 1 10. What is the purpose of a return statement


in a function?
b) 10
a) To terminate the program execution
c) Unlimited
b) To output a value to the console
d) It depends on the size specified during
declaration c) To assign a value to a variable

7. What is the correct syntax to declare an d) To restart the loop execution


array of integers in programming?

a) int[] arr;
11. In programming, structures are used to d) Person { String name; int age; }
combine multiple variables of different
types into a single entity. 15. Can a structure contain functions in
programming?
a) True
a) Yes
b) False
b) No
12. Which operator is used to access the
members of a structure in programming? c) Only if the functions have a return type

a) . d) Only if the functions are static

b) -> 16. What is the purpose of a conditional


statement in programming?
c) ::
a) To repeat a block of code
d) :
b) To define a function or method
13. Is it possible to modify the value of
structure members in a function? c) To execute different blocks of code based
on a condition
a) Yes, using the assignment operator (=)
d) To store multiple values in a single
b) No, structure members cannot be variable
modified
17. Which of the following is a logical
c) Only if the structure is passed by value operator in programming?

d) Only if the structure is passed by a) +=


reference
b) <=
14. What is the correct syntax to define a
structure named "Person" with "name" and c) *
"age" as members?
d) &&
a) structure Person { String name; int age; }
18. What is the output of the following code
b) struct Person { String name; int age; } snippet? ``` int x = 5; int y = 10; if (x > y)
{ System.out.println("x is greater than y"); }
c) struct Person { name: String, age: int } else if (x < y) { System.out.println("x is less
than y"); } else { System.out.println("x and c) do-while loop
y are equal"); } ```
d) if loop
a) x is greater than y
20. What is the purpose of the break
b) x is less than y statement in a loop?

c) x and y are equal a) To terminate the loop and exit the block

d) No output will be displayed b) To skip the current iteration and continue


with the next iteration
19. Which loop is guaranteed to execute at
least once in programming? c) To define a condition for the loop
execution
a) for loop
d) To restart the loop execution
b) while loop

SECTION B: 50marks

Conditions (10 Marks)

1. (4 marks) Explain the difference between if and if-else statements in C with code examples.

2. (3 marks) Write a C program that calculates a person's age (current year - birth year). Check if
the year entered is already the current year and adjust accordingly. Use appropriate error
handling for invalid input.

3. (3 marks) What is the logical opposite of x > 5 && y < 10? Write the code for the opposite
condition.

Loops (15 Marks)


4. (4 marks) Explain the difference between for and while loops in C. Provide scenarios where each
is preferable.

5. (5 marks) Write a C program that prints the multiplication table of a given user-entered number,
(from 1-12) using a for loop.

6. (3 marks) Explain the concept of an infinite loop and how to avoid it.

7. (3 marks) Write a C program that calculates the sum of all even numbers between 1 and 50.

Arrays (13 Marks)

8. (3 marks) Define an array in C and showcase its declaration and initialization with examples.

9. (6 marks) Write a C program that finds the largest element in an array of integers entered by the
user.

10. (4 marks) Write a C program that reverses the order of elements in a character array and prints
the new sequence. (Use the string “Volvo”).

Functions (5 Marks)

11. (3 marks) Explain the purpose of functions in C, including parameter passing and return values.

12. (2 marks) Write a C function that calculates the Area of a circle and returns the result.

Structures (7 Marks)

13. (3 marks) Define a structure in C and demonstrate its declaration and initialization with member
variables.
14. (4 marks) Write a C program that reads a student's name, age, and email address and stores them
in a structure. Then, print the stored information to a structure members. (note: structure name is
info and structure member, me1)

You might also like