1. Answer each of the following. Each part of question should use the result of previous part where appropriate. [18 marks]
a) Declare an array of type integer called markah with 10 elements, and initialize the element to the values 1,2,3,4,5,6,7,8,9,10, [2 marks]
b) Declare a pointer Ptr that points to an object of type integer.[2 marks]
c) Print the element of array numbers using array subscript notation. Use looping structure (for/while/do..while) and assume the integer control variable i has been declared. [5 marks]
d) Assign the starting address of array numbers to the pointer variable Ptr.[2 marks]
e) Print the element of array numbers using pointer with the pointer Ptr. Use looping structure (for/while/do..while) and assume the integer control variable i has been declared.[5 marks]
f) Assuming that Ptr points to the beginning of array numbers, what address is referenced by nPtr + 2 (assumed that the address for nPtr + 0 is 1000) ? What value is stored at that location?[2 marks]
2. Write a program that counts the total number of vowels in a sentence. Output the frequency of each vowel.
For example:
Input: TATIUC Teluk Kalong
Output: A : 2
E : 1
I : 1
O : 1
U : 2
DCT1063 ASSIGNMENT 2
1. A file is opened by linking it to a stream. ( T / F )
2. There are three types of streams: Input, Output and Input/output ( T / F )
3. To open an input stream, you must declare the stream to be of class ofstream. ( T / F )
4. The header
5. To close a file, use the member function close( ). ( T / F )
2. Assume that each of the following statements applies to the same program. ( 10 marks)
a) Write a program that prompts user to enter:-
I. Name
II. Matric
III. Course
IV. CPA
b) Read the data above (a) and write into a file named student.txt as follows.
Name : Ahmad Ashraaf
Matric: 09A04035
Course: CIS
CPA: 3.6
3. Write a program that reads student.txt (as created in 3 b), display its content to screen. (10 Marks)
No comments:
Post a Comment