Вы находитесь на странице: 1из 4

2 AACS3514 SOFTWARE DESIGN AND PROGRAMMING TECHNIQUES Q1

Mark

(a)

0,)
111 -1,

Declare a two-dimensional array, in C++, called mark[5][3] of type i n t(e6g ,e nrlatrhko represents this semester's test marks for 5 students with 3 test marks each. InitializP the array mark[5][3] with the following values: Test 1 56 34 80 67 76 Test 2 76 45 86 82 88 Test 3 65 23 90 80 42

r;] El] Student 1 Student 2 Student 3 Student 4 Student 5

3-; (s) pi- total


5rLiht 1:: 6 ; -6Y( ;at-J=6
1 =

A text file, average.txt, contains last semester's average marks of test 1, test 2, test 3, respectively.

3 i ttI-)
3) 4-

average - Notepad File Edit Format View Help

= tvuokrii if c -CctqA-P< "Tes+ "<<i ottk,Alt tAc.t (6. C .3 el ye, cot,i

r;33

65 88 78

Write C++ statements to perform the following: Create an instance of ifstream called input and associate it with the average.txt file. (2 marks)

t,-11 5vcY

(ii) Check whether the file average.txt has been opened successfully. If no ; (3 marks ) At( i_e, ticrte +x 1 display an error message and exit the program. Cary, hpA ,1 Lt' ) -C ex; 4-c ) (iv) GVIZne k Do3) tAn,le (else kge i (c) Close the text file. i) C--al 5e i; Jo'rov- ' orvtil) Declare an appropriate one-dimensional array of integer type called averageMark[ ]. Read from the file average.txt and store the details into the array. (5 marks)

(a)

Write C++ statements to calculate this semester's average mark for each test as recorded in the two-dimensional array mark[5][3] in Ql(a). Then comp.,are this 65c e4U semester's average and last semester's average (stored in averageMark[ in Ql(b)(iii) above) for each of the test. Output some messages to indicate whether this semester's tests are higher (or lower). For example: (8 marks) avel-e.tArk.ri+A-3 This semester's Test 1 average is higher/lower than last semester's average This semester's Test 2 average is higher/lower than last semester's average This semester's Test 3 average is higher/lower than last semester's average

[Total: 25 marks]

3 53514 SOFTWARE DESIGN AND PROGRAMMING TECHNI I UES Q2. (a) itiat The C++ program segment below contains a recursive function called computed. Write down all the outputs in the program segment. (7 marks) int compute (int k, int n); int main( ) 01) At, vitim.e, o4- X { Ii int x, m=3; 1/ for (int n = 0; n < 4; n++) 1/ 3A x { WO (- ) x = compute(m, n); 4. cout << "The value of x = " << x << endl; return 0;
}

-- : _ _ -_-_

3
9 3A 3

3e , E I , 3 1-/ 33

int compute(int k, int n) Sa if (n < 0)

a 9.2cs is rwc

cout << "Illegal argument to power. \n"; exit (1); r?/ LOL

:-p

th the narks)
}

else if (n > 0) return ( k * compute(k, n-1) ) else return (1);

If not narks) (b) called lto the7' larks): mark) Evaluate the following bitwise expression by showing all the detailed steps in the esulting bit pattern and convert the final result to the equivalent hexadecimal value.
t(i+0 , X3D0i A

(0x51C8 >> 3) Ox73FA (6 marks)

c (.// 11 >> Write a C++ program that will first declare a one-dimensional integer type array called myArr[ ] and initialize it with {3, 6, 9, 12, 15}. The program will then assign the array to a pointer p. After thatr-loop will be used with the pointer p to find and the !ill alle and output lue of the integers in the array. (12 marks) (Note: Declare a necessary variables in your program.] [Total: 25 marks] a AY, )

est as e this in er this larks)

)11-t- tv
-11,41k.

r 3= -L 3, p= rIny Arr.;it41/41-r[o]` s)rii; tvvivx 4 pcJ

40-t-u,1
M1 h

puj
1M; ;

Cott+ ,< CirLi C)

4 AACS3514 SOFTWARE DESIGN AND PROGRAMMING TECHNIQUES

(1

entrecordi tap as 3 eYlbt'N to k Declare a C++ structure called (e0 midterm r track of student's assignment , and final _.-examinati; mark. (4 marki ) s+rt4c-1- st-tidefrif _recOr -C(b) Gic IAlc EMIWrite a C++ program segment to, declares a one-dimensional array called stud4' of type student_record which is declared in Q3(a) above. double f1 M) (2 marks] ,A0A6i- 4.4 (w41 Eg-3
Q3. (a) Use a for-loop in C++ to prompt the user to enter 5 students' assignment maa midterm test marks, and final examination marks. (4 marks' IS-, }-) (c) Ass For the five students' results entered in Q3(c) above, write a C++ program segment calculate and print out the final mark (out of 100) for each student. Assume /, assignment, the midterm test and the final exam contribute 30%, 20% and 50% to (6 m final mark, respectively.

Modify the declaration of structure in Q3(a) above by making the structure into ;' linked list. Then write a C++ program segment to prompt the user to enter 5 studenf4 records into the linked list. Assume the linked list is empty to beg in with. (9 marks [Total: 25 marks] 4:0
6^3

[ I\ t (a)

5.-tuJ r; -wry, 1,-

-KA

[C.3

$)* )00

" \n.

3-

Q4.

Given the following seven integers, trace the steps taken to sort the integers by using the Selection Sort algorithm. Marks will be awarded for the correct order of steps. (6 marks e 27 80 02 46 16 12 54

-c Aok,ble Aro
sAAdtv,./

sAv IA-i- ck

e"f

Note: The selection sort algorithm is as follows:

A.0471 k. Noel cto,.61e rA

void SelectionSort (int a (] , int int min index; for (int i = 0 ; i<n- i++ )

{
min index = i; for (int j = i+1; j <n

{
if (a [j] < a [min index] ) min index = j; temp = a [i] ; a [i] = a. [minindex] ; a [min index] = temp;

5 4 SOFTWARE DESIGN AND PROGRAMMING TECHNI I UES 4ACS351 4SPL tinued (b) List the characteristics of the ISA bus. ()(.. I) (4 marks)

tin ti
Mar

\\-\,I Cv,,
(3 marks)

tudi

(c)

Describe the concept of multithreading and explain its purpose. o4 ) 17 r-1.)01-arv) kets 1\16iC. -14Acti I

(d)

-1-1,,0,91e, r^f ()'6 14 I IN(\c``c-'<Given the 16 bits BASE:SEGMEIyT virtual Memory address 662F:DA88, convert it 4 marks) into its actual memory address. 6 6 ,2__F
PAg Given the following C++ declaration forThinary tree structure,

/1 -[ ilic5ame (old mox- 1--cpuosuiVt

meti me 1001 mar

struct Tree (
char element ; Tree *left ; Tree *right ;

into
stuck mark marks and the following binary tree storage rules Values that are less than the LI node value are in the left subtree. Values that are greater than the root node value are in the right subtree. The above rules apply recursively to the right and left subtrees. Build and draw a binary tree that will store the follo7g characters using the rules above. S, F, U

using", [narks

(8 marks) [Total: 25 marks] o

Q(

c
si

ci

Вам также может понравиться