0% found this document useful (0 votes)
2K views5 pages

CSC404 Exam 1

This document contains a half-term test for a Programming II course. The test has 3 parts: Part A contains 10 multiple choice questions testing concepts like pointers, arrays, functions, and two-dimensional arrays. Part B contains 2 programming questions - one that swaps elements in an array and displays the new values, and one that writes a function to calculate a series. Part C contains one question with 4 subtasks: to input sales data into a 2D array, display it in a table, calculate the monthly sums, and find the largest value of the third month.

Uploaded by

adreana .z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views5 pages

CSC404 Exam 1

This document contains a half-term test for a Programming II course. The test has 3 parts: Part A contains 10 multiple choice questions testing concepts like pointers, arrays, functions, and two-dimensional arrays. Part B contains 2 programming questions - one that swaps elements in an array and displays the new values, and one that writes a function to calculate a series. Part C contains one question with 4 subtasks: to input sales data into a 2D array, display it in a table, calculate the monthly sums, and find the largest value of the third month.

Uploaded by

adreana .z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CSC 404: PROGRAMMING II

HALF-TERM TEST (30 MARKS)

PART A (10 Marks)

1. What is the operator used for dereferencing?

a. *
b. &
c. ()
d. **

2. A pointer variable pointed to myChar is

a. &myChar
b. *myChar
c. **myChar
d. myChar

3. What is the output of the following program segment?

char *ptr ;
char Str = 'P';
ptr = &Str;
Str +=5;
cout << Str;
cout << endl;
cout << *ptr;

S P
a. b.
S S

U U
c. d.
S U
4. Which of the following CORRECTLY accesses the ninth element of array Number1 with the size
of 11?

a. Number1 [9];
b. Number (9);
c. Number [10];
d. Number (10);

5. A two dimensional array can be processed as

a. The particular row of the array


b. The particular column of the array
c. The entire array
d. All of the above

6. _________________ is the keyword used in C++ for a function with return value, and
_________________ for a function with no return value

a. Void , parameter
b. Return, double
c. Return, Void
d. Void, Return

7. What is the types of variables used as parameter in the function header ?

a. Prototype variables
b. Local variables
c. Global variables
d. Block Variables

8. A two dimensional array can also be thought of as:

i. A list
ii. A table
iii. An array of arrays

a. i only
b. i and ii
c. ii and iii
d. i and iii
9. What is the output of the following code fragment?

char haiwan1[] = "kuda";


char haiwan2[] = “kucing";
int result = strcmp(haiwan1, haiwan2);
cout << result;

a. 1 b. 0 c. -1 d. 10

10. What is base address of an array?

a. A list of one-dimensional array


b. An address or location for the first array component
c. The first element of array
d. The address of the reference
PART B (10 Marks)

1. What is the output of the following program segment?

int main (){


int x[4]={1,2,3,4};
int *p=x ;
int i;
for (i=0;i<2;i++){
int temp = *(p+i);
*(p+i)=*(p+3-i);
*(p+3-i)=temp; }
for ( i=0; i<4; i++){
cout << x[i];
cout << endl;}
return 0;}

(4marks)

1. Given the following series :


𝑛 𝑛 𝑛
𝑓𝑢𝑛𝑐 (𝑛) = +1 + +2 + +3
2 2 2

a. Write a C++ program segment for the function func(n) that computes the
total sequence in the series.
(3 marks)
b. Write a C++ program segment that calls the function for the value 10 and
display the series as follows:

The function value for func(10) is 105


(3 marks)
PART C (10 Marks)

1. Given the following declaration:

const int rSIZE = 10;


const int cSIZE = 6;
double sale[rSIZE][cSize];

Write a C++ code that can store the monthly sale of six salespersons for the first six months in
two-dimensional array. Your program must consist of the following tasks:

 Read data into the two-dimensional array sale.


2 marks
 Display data in table form.
2 marks
 Compute and display the sum of each month.
3 marks
 Determine and display the largest value of the third month.
3 marks

<< END OF QUESTIONS >>

You might also like