CSC 1101 Final Exam sem 2 06-07

10
INTERNATIONAL ISLAMIC UNIVERSITY MALAYSIA END-OF-SEMESTER EXAMINATION SEMESTER II, 2006/2007 SESSION KULLIYYAH OF INFORMATION AND COMMUNICATION TECHNOLOGY Programme : PRSS/ICT/ BIT Level of Study : Undergraduate Time : 2.30 p.m. – 5.00 p.m. Date : 28 th March 2007 Duration : 2 Hr(s) 30 Min(s) Course Code : CSC 1101 Section(s) : All Course Title : STRUCTURED PROGRAMMING LANGUAGE This Question Paper Consists of 10 printed pages including cover page with 3 PARTS of questions and the total marks is 100 No calculators are allowed INSTRUCTION(S) TO CANDIDATES DO NOT OPEN UNTIL YOU ARE ASKED TO DO SO PART A: MULTIPLE CHOICE QUESTIONS (20 QUESTIONS) PART B: TRUE/FALSE QUESTIONS (10 QUESTIONS) PART C: PROGRAMMING QUESTIONS (3 QUESTIONS) Answer ALL questions in the Answer Booklet. Any form of cheating or attempt to cheat is a serious offence which may lead to dismissal. APPROVED BY

description

Stuctured Programming langguage CSC 1101 Final Exam ( current course code csc 1100 Elements of programming)

Transcript of CSC 1101 Final Exam sem 2 06-07

Page 1: CSC 1101 Final Exam sem 2 06-07

INTERNATIONAL ISLAMIC UNIVERSITY MALAYSIA

END-OF-SEMESTER EXAMINATION SEMESTER II, 2006/2007 SESSION

KULLIYYAH OF INFORMATION AND COMMUNICATION TECHNOLOGY Programme : PRSS/ICT/ BIT Level of Study : Undergraduate Time

:

2.30 p.m. – 5.00 p.m.

Date

:

28th March 2007

Duration

:

2 Hr(s) 30 Min(s)

Course Code

:

CSC 1101

Section(s)

:

All

Course Title

:

STRUCTURED PROGRAMMING LANGUAGE

This Question Paper Consists of 10 printed pages including cover page with 3 PARTS

of questions and the total marks is 100

No calculators are allowed

INSTRUCTION(S) TO CANDIDATES

DO NOT OPEN UNTIL YOU ARE ASKED TO DO SO

PART A: MULTIPLE CHOICE QUESTIONS (20 QUESTIONS) PART B: TRUE/FALSE QUESTIONS (10 QUESTIONS) PART C: PROGRAMMING QUESTIONS (3 QUESTIONS)

Answer ALL questions in the Answer Booklet.

Any form of cheating or attempt to cheat is a serious offence which may lead to dismissal.

APPROVED BY

Page 2: CSC 1101 Final Exam sem 2 06-07

2

PART A: MULTIPLE CHOICE QUESTIONS [30 marks; 1.5 marks each] Instruction: Answer ALL questions in the answer booklet provided.

1. What is the output of the following C++ code?

int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y – x; cout << x << " " << y << " " << z << endl;

A. 35 45 80 C. 35 45 –10 B. 35 45 10 D. 35 45 0

2. What is the output of the following code fragment?

x = 10; if (x > 15) x = 0; cout << x << endl; else cout << x + 5;

3. After the execution of the following code, what is the value of variable sum?

sum = 0; num = 10; if (num > 0) sum = sum + 10; else if (num > 5) sum = num + 15;

A. 0 C. 20 B. 10 D. 25

4. When one control statement is located within another, it is said to be ____.

A. blocked C. nested B. compound D. closed

A. 0 C. 10 B. 5 D. None of the above

Page 3: CSC 1101 Final Exam sem 2 06-07

3

5. What is the output of the following code?

char lastInitial = 'A'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; }

A. section 1 C. section 3 B. section 2 D. section 5

6. What is the output of the following program segment? int x = 14; int y = 60; while (((y - x) % 3) != 0) { cout << y << " "; y = y - 5; }

A. 60 55 C. 60 55 50 45 B. 60 55 50 D. 60 55 50 45 40

7. Which of the following loops is guaranteed to execute at least once?

A. counter-controlled while loop C. do...while loop B. for loop D. sentinel-controlled while loop

8. In an array, the values are related by their ____.

A. size C. position in the array B. length D. accuracy

Page 4: CSC 1101 Final Exam sem 2 06-07

4

9. Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code?

cin >> sum; cin >> num; for (j = 1; j <= 3; j++) { cin >> num; sum = sum + num; } cout << sum << endl;

A. 24 C. 41 B. 25 D. 42

10. Using the declarations const int ARRAYSIZE = 7; and double length[ARRAYSIZE] =

{7.8, 6.4, 4.9, 11.2}; ____ elements will be initialized to zero.

A. 0 C. 2 B. 1 D. 3

11. When an array is passed to a function, its ____ is the only item actually passed.

A. value C. address B. data type D. offset

12. A pointer ____ included as a parameter in a function header.

A. can not be C. should not be B. can be D. is rarely

13. Languages that use classes but do not provide inheritance and polymorphic features

are referred to as ____ languages.

A. object-oriented C. procedural B. object-based D. hybrid

14. The set of attributes and behaviors defining a class is frequently referred to as the

class’s ____.

A. interface C. environment B. specifications D. components

15. In a C++ class, a member function name ____ be the same as a data member name.

A. should not C. cannot B. should D. can

Page 5: CSC 1101 Final Exam sem 2 06-07

5

16. The private access designation used in C++ classes restricts a user from seeing how the data is actually stored and is referred to as data ____.

a. security c. enforcement b. protection d. hiding

17. Class functions declared as public ____ be called by any objects and functions not in

the class.

a. can c. should not b. cannot d. rarely

18. Whenever a new object of a class is defined, the class’s ____ function is

automatically called.

a. implementation c. constructor b. declaration d. extension

19. If no constructor is provided in a class definition, the compiler will ____.

a. supply a stub c. issue an error message b. do nothing d. supply a do-nothing default constructor

20. When a constructor function is used in a declaration, parentheses should ____ be

included for a zero parameter constructor.

a. always c. usually b. never d. rarely

Page 6: CSC 1101 Final Exam sem 2 06-07

6

PART B: TRUE/FALSE QUESTIONS [10 marks; 1 mark each] Instruction: Answer ALL questions in the answer booklet provided.

1. In a switch statement, every case must have a break.

2. The output of the following C++ code is 8.

alpha = 3; cin >> beta; //Assume input is 5 switch (beta) { case 3: alpha = alpha + 3; case 4: alpha = alpha + 4; break; default: alpha = alpha + 5; }

3. The output of the following C++ code is Legal Age.

age = 50; switch (age > 21) { case true: cout << "Legal Age"; break; case false: cout << "Below Legal Age"; break; default: cout << "Bad Input"; }

4. The following while loop terminates when j > 20.

j = 0; while (j < 20) j++;

5. Each item in an array is called an element or component of the array.

6. grade[5] refers to the fifth grade stored in the grade array.

7. The size of an array cannot be omitted from a declaration statement even if the

initializing values are included. 8. Passing a complete array of values to a function is a more complicated process than

passing individual elements.

Page 7: CSC 1101 Final Exam sem 2 06-07

7

9. One of C++’s advantages is that it provides the programmer access to the addresses of variables used in a program.

10. The address operator is the symbol (*).

Page 8: CSC 1101 Final Exam sem 2 06-07

8

PART C: PROGRAMMING QUESTIONS [60 marks] Instruction: Answer ALL questions in the answer booklet provided. QUESTION 1 [10 marks]:

1. Write a program that prompts user to enter strings of 4 zikr and store them in an

array named zikr. Reverse the zikr stored in that array so that the last zikr entered becomes the first, the second from the last becomes the second, and so forth. (Note: Do not use second array; it is permissible to use a variable to hold the number temporarily)

Sample of output: (Shaded strings were inputs entered by user)

Please enter 4 zikr:

Ya-Allah Alhamdulillah Subhanallah Allahu-akbar

Zikr reversed in the array are: Allahu-akbar Subhanallah Alhamdulillah Ya-Allah

[5 marks]

2. By using pointers, create a calculator program that can do the following:

Multiplication Division

(Note: For division, prints out the remainder as well)

Sample of output: (Shaded numbers were inputs entered by user)

Please enter first number: 5 Please enter second number: 3 5 * 3 is 15 5 / 3 is 1 with a remainder of 2

[5 marks]

Page 9: CSC 1101 Final Exam sem 2 06-07

9

QUESTION 2 [25 marks]:

Define a class called Month that is an abstract data type for a month. Your class will have one member variable of type int to represent a month (1 for January, 2 for February, and so forth). The complete class will include all the following member functions:

A constructor to set the month using the first three letters in the name of the month as three arguments

A constructor to set the month using an integer argument (1 for January, 2 for February, and so forth)

A default constructor An input function that reads the month as an integer An input function that reads the month as the first three letters in the name of the

month An output function that outputs the month as an integer An output function that outputs the first three letters in the name of the month A member function that returns the next month as a value of type Month.

Sample of output: (Shaded numbers/month were inputs entered by user)

Testing the default constructor ... Month: 1 Jan

Testing the constructor with one integer argument... Enter a month number: 5 Month: 5 May

Testing the constructor with 3 letters as arguments ... Enter the first three letters of a month (lowercase): nov

Month: 11 Nov

Do you want to test again? (y or n) y

Testing the default constructor ... Month: 1 Jan

Testing the constructor with one integer argument... Enter a month number: 8 Month: 8 Aug

Testing the constructor with 3 letters as arguments ... Enter the first three letters of a month (lowercase): jan

Month: 1 Jan

Do you want to test again? (y or n) n Press any key to continue . . .

Page 10: CSC 1101 Final Exam sem 2 06-07

10

QUESTION 3 [25 marks]: Write a program that ask for the user’s height, weight and age, and then computes clothing sizes according to the formulas:

Hat size = weight in pounds divided by height in inches and all that multiplied by 2.9.

Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by

adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes place after a full 10 years. So, there is no adjustment for ages 30 through 39, but 1/8 of inch is added for age 40)

Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for

each 2 years over age 28. (Note that the adjustment only take place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)

Use function for each calculation. Your program should allow the user to repeat the calculation as often as the user wishes.

Sample of output: (Shaded numbers/char were inputs entered by user)

Enter your age: 2288 Enter your height (in inches): 63 Enter your weight (in pounds): 143 Hat size: 7 Jacket size: 31 Waist size: 25 Do you want to do another calculation? Press y for yes, n for no, and then press return: y Enter your age: 20 Enter your height (in inches): 55.1 Enter your weight (in pounds): 88 Hat size: 5 Jacket size: 17 Waist size: 15 Do you want to do another calculation? Press y for yes, n for no, and then press return: n Press any key to continue . . .

-----------------------------------------End of question paper---------------------------------------------