Computer programming assignment
Computer programming assignment
Computer programming assignment
Question 1
Page 1 of 4
Question 2
a) Consider the following code (Figure Q2.1) and explain each component indicated using
numbers.
Figure Q2.1
a) If
int x = 20; int y = 30; int z = 10;
Write down the output of the following C++ programs.
i. cout << (z = = y) && (x = = 20);
ii. cout << (x < = y) || (y = = z);
iii. cout << (x != y);
iv. cout << !(x > 3);
v. cout<< (x & y);
vi. cout<< (x | y);
vii. cout<< (~z);
viii. cout<< (x += 2);
ix. cout<< (x << 2);
x. cout<< (y >> 2);
Page 2 of 4
Question 4
Question 5
a) Write a function named "add" to take two integer values as arguments and return the
summation.
b) Include the "add" function that you have previously created in a class named "Class2".
c) Call the "add" method of "Class2" from the main method and print the return value
(summation).
Question 6
a) Write a C++ program that takes an integer as input and uses conditional statements to
determine if it's even or odd.
b) Implement a C++ function to find the largest element in an integer array using loops and
conditional statements.
c) Create a C++ function to find the smallest element in an integer array using loops and
conditional statements.
d) Define a C++ function that reverses the elements of an integer array.
e) Write a C++ function to count the occurrences of a specific element in an integer array.
f) Implement a C++ function that filters an integer array to remove duplicates and returns a
new array without duplicates.
g) Write a C++ function that takes two integer arrays as input and returns a new array
containing the elements that are common to both arrays.
h) Create a C++ function that takes two integer arrays as input and returns a new array
containing all unique elements from both arrays.
Page 3 of 4
i) Write a C++ function to search for a specific element in a 2D integer array and return its
location (row and column).
j) Write a C++ program to calculate the Diameter, Circumference and Area of a circle, if
the radius is given as an input. (Consider PI= 3.145). Create three functions to calculate
Diameter, Circumference and Area.
Assignment Submission:
Write answers in Microsoft Word file and rename the file with your
registration number then submit to the Google Classroom.
Page 4 of 4