department of computer science
college of computing
western delta university
first semester examination 2022/2023 session
CSC203 - computer programming II time: 2hrs: 30mins
answer four (4) questions
Question 1
- Briefly define the following:
- Whitespace
- Constants
- Header files
- Write a C++ program that displays "Welcome to C++ Programming!" and "Computer Programming is an interesting endeavor!" (3 marks)
- Consider the following C++ program and use it to answer the question that follows:
Identify and correct at least ten (10) syntax errors in the given program (10 marks)// This program computes the area of a circle
#include <iosteam>
#include <cmath>
using namespace std
int main ()
const float pi = 3.142;
double radius, result, area, exponent = 2.0;;
cout >> "Enter the value of radius" >> endl;
cin << radius;
Result = power(radius, exponent);
cout >> "The area of the circie is " >> area;
return 0;
}
- Briefly define the following:
Question 2
- Define the following programming terms:
- comment
- setw manipulator
- variable name
- increment operator
- decrement operator
- Give six (6) examples of valid variable names in C++ programming. (3 marks)
- Suppose
total_tax = avg_ _Tax * ++count;
explain how a C++ compiler will execute the given statement (3 marks) - Write a C++ program that generates the table below
(4 marks)Year Profit 1950 500000000 1951 600000000 1952 700000000
- Define the following programming terms:
Question 3
- Using suitable examples, write explanatory notes on the following:
- Relational operators
- Loops
- Give the syntax of while and do loops (4.5 marks)
- Name four (4) arithmetic operators and describe them using examples (4 marks)
- Write a C++ program using a while loop that asks a user to enter numbers, calculates their sum, prints the result until the number entered is negative (5 marks)
- Using suitable examples, write explanatory notes on the following:
Question 4
- Highlight the role of decisions in computer programming (2 marks)
- With the aid of a flowchart only, describe the working principle of
if...else
statement (3.5 marks) - Write down the syntax of a
switch
statement (4 marks)
- With the aid of a flowchart only, describe the working principle of
- State three (3) examples of logical operators and show how they are represented in C++ (3 marks)
- Write a C++ program that obtains test score and assigns grade according to the following information. The test score is an integer from 1 to 100
(5 marks)Test Score Grade 70 and above Distinction 60 - 69 Merit 50-59 Pass Below 50 Fail
Question 5
- What is a Structure? (2.5 marks)
- State the syntax of a structure (3 marks)
- Write a program that defines a structure, assigns values to the structure and displays the values (5 marks)
- Define Enumeration (2 marks)
- Give the syntax of enumeration and write an enumeration whose values are months of the year (5 marks)
Question 6
- Define a function (2 marks)
- Give two (2) reasons for using functions in computer programming (2 marks)
- What is an argument? (2 marks)
- Name three (3) parameter passing techniques to functions (3 marks)
- Define recursion (2 marks)
- Write a recursive function that adds a range of numbers by adding two numbers each time it is called by a main program (6 marks)