department of computer science
college of computing
western delta university
first semester examination 2023/2023 session
CSC203 - computer programming II (C++) time: 2hrs: 30mins
Answer question one (1) and any other three (3) other questions
Question 1 (Compulsory) (25 Marks)
- Develop a C++ program that displays "Hello, I am learning C++ Programming!" and "Coding is Fun!" on two different lines. (4 marks)
 - What is the function of the following in C++ Programming:
cincout- blank line
 #include <iostream>
 - What is a variable? State the syntax for creating a variable. (2 marks)
 - Copy and complete the table. (5 marks)
Data Type Description booleancharint float double  - Hence, add the correct data type for the following variables:
_______ myNumber = 9;_______ myNumber = 8.99;_______ myApp = 'A'_______ myCondition = false;_______ myVariable = "Hello World!"
 - Suppose variable 
x = 20andy = 5, compute the following:x * yx / yx % yx++y++
 
Question 2 (15 Marks)
- Define the following:
- Operators (3 marks)
 - Arithmetic operators (3 marks)
 
 - Name four (4) arithmetic operators and with the aid of suitable examples, explain how to use them. (4 marks)
 - List three (3) logical operators and using examples, describe what they are used for. (3 marks)
 - Write a C++ program that continuously accepts inputs, but terminates when the user enters a zero (0) value. Hint: Assign variable number to an integer value. Use a 
whileloop. (5 marks) 
- Define the following:
 Question 3 (15 Marks)
- Study the C++ code below and use it to answer the question that follows:
Determine the output of the program. (5 marks)#include <iostream>
#include <cmath>
using namespace std;
int main () {
cout << sqrt(25) << endl;
cout << round(8.7) << endl;
cout << max(200, 300) << endl;
cout << min(500, 1000) << endl;
string txt = "Programming";
cout << txt.length();
return 0;
} - Give the syntax of 
switchstatement anddo/whileloop. Briefly explain them. (5 marks) - What are nested loops? (2 marks)
 - Using a for loop, display "Yes, I understand definite iterations" 5 times on the screen. (3 marks)
 
- Study the C++ code below and use it to answer the question that follows:
 Question 4 (15 Marks)
- Define Arrays. Explain how to declare multidimensional arrays. (4 marks)
 int myNumbers[20] = { }. How many elements should the array contain?(1 mark)- Consider the array: 
string cars[5] = {"Audi", "Benz", "Ford", "Kia", "Toyota"}. What will the instructioncout << cars[2]display? (2 marks) - Given the array string
Determine the output of the following:letters[2][6] = {{"I", "J", "K", "L", "M", "N"}, {"O", "P", "Q", "R", "S", "T" }}cout << letters[0][4];cout << letters[1][3];(3 marks)
 - Write a C++ program that obtains ten (10) integers from a user, stores them in an array and displays the sum. (5 marks)
 
Question 5 (15 marks)
- Define the following:
- Structures
 - Pointers
 - Functions
 
 - Give the syntrax for creating a function. (2 marks)
 voidandreturnare keywords in computer programming. What do they mean? (2 marks)
- Develop a C++ function that calculates and returns the sum of three integer variables a, b, c. (5 marks)
 
- Define the following:
 Question 6 (15 Marks)
- What is recursion? Highlight the role of recursion in programming. (5 marks)
 - Describe how to create a class and an object. (4 marks)
 - Create a class called 
Car. It has three attributes:brand = "FORD",model = "X20"andyear = 2024. The class also has public access specifier. Create an object of classCar. Name itcarObj. Display the attribute values of Car/object. (Hint: brand and model (string). year (integer)) (6 marks)