Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Solution to Mid-Semester

SECTION A: ANSWER ALL


1. With the use of line number indicates the line of code that has error and identify the type of error

6 MARKS
ANY 6 ATTRACTS 1 MARK EACH
LINE NUMBER TYPE OF ERROR
1 Syntax (one missing backslash for comment)
2 Syntax (one missing backslash for comment)
3 Syntax (one missing backslash for comment)
4 Syntax (header file not indicated)
8 Syntax (omission of semi colon)
10 Syntax (missing placeholder)
11 and 15 Semantic and logical (missing braces { } for more
than one executable statement associated with if
statement

SECTION B:
a. i. What is computer science?
SOLUTION 2 marks
Computer Science is about building abstract models of real-world objects or phenomena ½ mark, with the
aim of using the model to solve problems ½ mark by automating the models through the use of algorithm
½ mark, and implementing the algorithm in form of instructions which the computer can understand ½
mark.

ii. State the four steps of creating a C program.


a. Editing ½ mark
b. Compiling ½ mark
c. Linking ½ mark
d. Execution ½ mark
b. You need to develop an application that can be useful for a casual worker whose salary is calculated
based on the number of hours worked. Each casual worker is paid N1500 per hour and paid N1000 per hour
if he did extra hour. Draw a flowchart to determine the monthly pay of a worker at the end of the month. To
do this you are to do the followings:
i. Perform the analysis, i.e., input data, output data and processing requirements

Input data:

Number of hours worked ½ mark


Pay per hour=N1500 ½ mark

Pay per extra hour=N1000 ½ mark

Number of extra hours ½ mark

Output data:

Monthly pay ½ mark

Processing requirements:

IF (Number of extra hours==0) ½ mark

THEN

CALCULATE ½ mark

Monthly pay=Number of hours worked*1500

OUTPUT ½ mark

Monthly pay

ELSE

CALCULATE ½ mark

Monthly pay=(Number of hours worked*1500)+( Number of extra hours worked*1000)

OUTPUT ½ mark

Monthly pay

ii. Draw the flowchart for computing the monthly salary of a worker.
The flowchart should reflect:
a. Salary if a worker does not have overtime
b. Salary if a worker does overtime

SOLUTION 5 MARKS

Mark for correct flow of arrows= ½ mark

Flowchart drawing 4.5 + mark for correct mark 0.5 = 5 marks


FLOWCHART FOR COMPUTING MONTHLY SALARY

TOTAL: 14 marks

1. With the use of nested if develop a preliminary visa interview application using C programming language.
The application should be able to test if an applicant is qualified for a visa based on the following dependent
conditions.
i. If you are a born Nigerian, if not, it will instruct you to regularize your citizenship
ii. Have a genuine purpose for traveling, if not, it will output visa denied based on purpose
iii. If you are married, if yes--grant visa, if no—it will output visa denied 10 marks

SOLUTION: 10 MARKS
2. Using C language develop an application that will aid a prospective University student to determine his/her
preliminary admission status. The program should determine admission status based on student age and
UTME score. According to JAMB, a student should not be less than 16 and UTME score must not be less
than 200 in order to gain admission into any University in Nigeria.
i. Using a single option if statement determine if a student is qualified to gain admission into the university.
ii. Develop another application that uses double or alternate option if statement that will instruct the user whether
he/she is qualified or not. 10 marks

SOLUTION 3i. 3 marks

SOLUTION 3ii:
Revision on Compound If and Switch Case
(a) Briefly describe the concept of control structure. (Read about this !!!)

(b) Suppose you're given a scenario where a student's eligibility for a discount at a movie
theater is determined based on their age and whether they are a student or not. Write a C
program that takes the age and student status (1 for student, 0 for non-student) as input and
outputs whether the student is eligible for a discount or not using compound using if
statement.
Conditions:
i. Students aged 18 or below are eligible for a discount.
ii. Non-students aged 60 or above are eligible for a discount.

Solution:
// A C program to check student eligibility for discount using compound if statement
#include <stdio.h>
int main()
{
// Variable declaration
int age, isStudent;
// Input age and student status
printf("Enter your age: ");
scanf("%d", &age);
printf("Are you a student? (1 for yes, 0 for no): ");
scanf("%d", &isStudent);
// Check eligibility for discount
if ((age <= 18 && isStudent == 1) || (age >= 60 && isStudent == 0))
{
printf("You are eligible for a discount.\n");
}
else
{
printf("Sorry, you are not eligible for a discount.\n");
}
return 0;
}

Question
(a) With the aid of a diagram, describe the switch case structure. (Read about this !!!)

(b) As a microbiology student, you are studying different types of microorganisms and their
characteristics. Write a C program to help classify microorganisms based on their type. The
program should take a character representing the type of microorganism as input and output
its classification.
Microorganism types and their classifications:
B: Bacteria
V: Virus
F: Fungus
P: Protozoa
Use a switch case statement to classify the microorganism based on its type. If the input
character does not match any of the specified types, output "Unknown microorganism
type." 10 marks

Solution:
// A C program to classify micro-organism using switch case statement
#include <stdio.h>

int main() {
char microorganismType;

// Prompt the user to input microorganism type


printf("Enter the type of microorganism (B/V/F/P): ");
scanf(" %c", &microorganismType);

// Classify the microorganism based on its type


switch (microorganismType) {
case 'B':
printf("Classification: Bacteria\n");
break;
case 'V':
printf("Classification: Virus\n");
break;
case 'F':
printf("Classification: Fungus\n");
break;
case 'P':
printf("Classification: Protozoa\n");
break;
default:
printf("Unknown microorganism type.\n");
}

return 0;
}

You might also like