EXAMSHARE

Western Delta University, Oghara Delta State

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


  1. Question 1 (Compulsory) (25 Marks)

    1. Develop a C++ program that displays "Hello, I am learning C++ Programming!" and "Coding is Fun!" on two different lines. (4 marks)
    2. What is the function of the following in C++ Programming:
      1. cin
      2. cout
      3. blank line
      4. #include <iostream>
      (4 marks)
    3. What is a variable? State the syntax for creating a variable. (2 marks)
    4. Copy and complete the table. (5 marks)
      Data TypeDescription
      boolean
      char
      int
      float
      double
    5. Hence, add the correct data type for the following variables:
      1. _______ myNumber = 9;
      2. _______ myNumber = 8.99;
      3. _______ myApp = 'A'
      4. _______ myCondition = false;
      5. _______ myVariable = "Hello World!"
      (5 marks)
    6. Suppose variable x = 20 and y = 5, compute the following:
      1. x * y
      2. x / y
      3. x % y
      4. x++
      5. y++
      (5 marks)
  2. Question 2 (15 Marks)

    1. Define the following:
      1. Operators (3 marks)
      2. Arithmetic operators (3 marks)
      1. Name four (4) arithmetic operators and with the aid of suitable examples, explain how to use them. (4 marks)
      2. List three (3) logical operators and using examples, describe what they are used for. (3 marks)
      3. 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 while loop. (5 marks)
  3. Question 3 (15 Marks)

    1. Study the C++ code below and use it to answer the question that follows:
      #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;
      }
      Determine the output of the program. (5 marks)
    2. Give the syntax of switch statement and do/while loop. Briefly explain them. (5 marks)
      1. What are nested loops? (2 marks)
      2. Using a for loop, display "Yes, I understand definite iterations" 5 times on the screen. (3 marks)
  4. Question 4 (15 Marks)

    1. Define Arrays. Explain how to declare multidimensional arrays. (4 marks)
    2. int myNumbers[20] = { }. How many elements should the array contain?(1 mark)
    3. Consider the array: string cars[5] = {"Audi", "Benz", "Ford", "Kia", "Toyota"}. What will the instruction cout << cars[2] display? (2 marks)
    4. Given the array string
      letters[2][6] = {{"I", "J", "K", "L", "M", "N"}, {"O", "P", "Q", "R", "S", "T" }}
      Determine the output of the following:
      1. cout << letters[0][4];
      2. cout << letters[1][3];
      3. (3 marks)
    5. Write a C++ program that obtains ten (10) integers from a user, stores them in an array and displays the sum. (5 marks)
  5. Question 5 (15 marks)

    1. Define the following:
      1. Structures
      2. Pointers
      3. Functions
      (6 marks)
      1. Give the syntrax for creating a function. (2 marks)
      2. void and return are keywords in computer programming. What do they mean? (2 marks)
      (6 marks)
    2. Develop a C++ function that calculates and returns the sum of three integer variables a, b, c. (5 marks)
  6. Question 6 (15 Marks)

    1. What is recursion? Highlight the role of recursion in programming. (5 marks)
    2. Describe how to create a class and an object. (4 marks)
    3. Create a class called Car. It has three attributes: brand = "FORD", model = "X20" and year = 2024. The class also has public access specifier. Create an object of class Car. Name it carObj. Display the attribute values of Car/object. (Hint: brand and model (string). year (integer)) (6 marks)