Midterm-paper 1 sample-question PDF

Title Midterm-paper 1 sample-question
Course Programming Technique I
Institution Universiti Teknologi Malaysia
Pages 10
File Size 444.9 KB
File Type PDF
Total Downloads 1
Total Views 48

Summary

1UNIVERSITI TEKNOLOGI MALAYSIAMID TERM TESTPAPER I (THEORY)SUBJECT CODE : SECJ1023 / SCSJSUBJECT NAME : PROGRAMMING TECHNIQUE IISECTION :TIME : (90 MINUTES)DATE/DAY :VENUE : INSTRUCTIONS :This test book consists of TWO (2) sections:Section A: Multiple Choices Single Answer 30 MarksSection B: Multipl...


Description

UNIVERSITI TEKNOLOGI MALA

IA

MID TERM TEST

PAPER I (THEORY)

SUBJECT CODE

:

SECJ1

SUBJECT NAME

:

P

SECTION

:

TIME DATE/DAY VENUE ________________ INSTRUCTION

_____________________________

This test Sectio Section B: M

30 Marks nswers

40 Marks

TOTAL

70 Marks

INSTRUCTION: ANSWER ALL QUESTIONS.

1

SECTION A: MULTIPLE CHOICES SINGLE ANSWER QUESTIONS

[30 Marks]

Instruction: This section consists of TWENTY (20) questions.. Read each question carefully and choose the letter A, B, C or D that BEST describe the answer. Each question is worth 1.5 marks.

Notes: Only 12 questions are shown in this sample paper. In actual test, this section will consist of 20 questions.

Question 1 and 2 are based on Program A-1 below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

// Program A-1 int add(int a, int b){ return a + b; } int multiply(int a, int b){ return a * b; } void result(int r){ cout > x >> c; y = multiply(m, x); y = add(y, c); result(y); return 0; }

1. Which of the following statements is INCORRECTLY describing Program A-1? A. Data reside in the main function. B. Data flows around from one function to another. C. Each function in the program communicate thru message passing mechanism. D. Parameter passing is heavily used in the program.

2. Program A-1 is written in __________ style. A. Dynamic programming B. Object-oritented programming C. Procedural programming D. Functional programming

3. UTM librarian intend to categorize the books in the library system into History Books, Computer Books and Science Books. For Computer Books, it will be further categorized into Software Engineering Books, Database Books and Computer Networking Books. This example is related to the OOP concept called _________. A. Encapsulation B. Association C. Inheritance D. Polymorphism

Question 4, 5 and 6 are based on Program A-2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

// Program A-2 const string DAYS[7] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; class Date{ private: int year, month, day; void adjustYear(int y){ if (y < 99) year = y + 1900; else if (y < 20) year = y + 2000; else year = y; } public: Date(int y = 19, int m, int d) : month(m), day(d) { adjustYear(y); }

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 }; 37

void setYear(int y){ adjustYear(y); } string getDayName() const{ return DAYS[day - 1]; } void setDay(int d) { day = d; } void setDay(string name){ for (int d = 0; d < 7; d++) if (name == DAYS[d]) day = d + 1; }

4. This statement is FALSE about the method adjustYear()of the class Date. A. It must be put under the public section. B. It helps to avoid writing the same code over and over again. C. It converts the year 99 to 1999. D. It is used internally by the class’s methods.

5. Which of the followings is TRUE about what the method getDayName()does? A. If the attribute day is 0 then it returns "Mon". B. If the attribute day is 0 then it returns "Tue" . C. If the attribute day is 1 then it returns "Mon". D. If the attribute day is 1 then it returns "Tue" .

6. What is the main reason of the class Date having two methods with the same name setDay() A. So that each Date object can store the day information either in the form of day number or day name. B. So that each Date object can be specified either with the day number or day name. C. So that the second method of setDay() will overwrite the first one. D. To overload the attribute day.

7. What is the this in C++? A. It is an instance of a class. B. It is a variable of the current object. C. It is a pointer. D. It is a built-in class.

Question 8 and 9 are based on Program A-3. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

// Program A-3 class Bread{ private: float price; int quantity; string breadName; public: // Constructor with default argument Bread(float p=5.00,int qtty=10,string name="Croissant") { price=p; quantity = qtty; breadName = name; } }; int main() { // declaring bread array Bread bread[4]={ Bread(3.00), Bread(4.50,20,"Raisin Bread"), Bread(3.50,30) }; }

8. Based on the declaration of bread array at Line 20, what is the content of bread array at index 3? A. price = 3.50, quantity = 30, breadName= Raisin Bread B. price = 5.00, quantity = 10, breadName= Croissant C. price = 3.50, quantity = 30, breadName= Croissant D. The bread array declaration has an error.

9. Which of the following is INCORRECT regarding passing any part of bread array (either the whole array or certain element in the array) to functions? (Assume the functions are given) A. calculateTotal(bread); B. getSales(bread[0]); C. int x = 2; getSales(bread[x]); D. getSales(bread[4]);

10. If a member variable is declared as ____________, all objects of that class will share that variable. A. static B. dynamic C. inline D. friend

11. Based on the variables below, which of the followings is TRUE to convert a string to an integer? string p char q string r int s A. stoi(p)

= = = =

"7"; '7'; "seven"; 7;

B. stoi(q) C. stoi(r) D. stoi(s)

12. Consider the following code segment. What is the new value of the variable str? string str = "seven"; int i = str.find("e"); str[i] = '7'; A. "s7v7n" B. "s7ven" C. "sev7n" D. "7"

SECTION B: MULTIPLE CHOICES MULTIPLE ANSWERS

[40 Marks]

Instruction: This section consists of FIFTEEN (15) questions. Each question can have either TWO, THREE or FOUR correct answers as stated in each question. You MUST NOT choose your answers more than the amount required. Any additional choice will be deducted by 1 mark. For example, if the question states, “Choose THREE correct answers”, and you choose five, then 2 marks will be deducted for that question.

Notes: Only 8 questions are shown in this sample paper. In actual test, this section will consist of 15 questions. 1. Which of the followings are computer programming paradigms. Choose THREE correct answers A. Dynamic programming B. Object-oritented programming C. Procedural programming D. Functional programming E. Linear Programming F. Recursive Programming (3 marks)

2. Choose the Object-Oriented Programming (OOP) concepts applied to the class Triangle in Figure B-1. Choose TWO correct answers

Figure A-1

A. Data hiding B. Encapsulation C. Inheritance D. Association (2 marks)

3. Which of the followings are TRUE about objects? Choose FOUR correct answers. A. When an object is created, a constructor will execute. B. Each object has its own copy of attributes. C. An object is instantiated from a class. D. An object is instantiated from another object. E. Objects are used to instantiate classes F. Objects from the same class share the same structure of data. G. Objects from the same class share the same data. H. An object can be passed as parameters to functions but cannot be returned from a function. (4 marks) Consider the class Rectangle in Program B-1 and answer Question 4. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

// Program B-1 class Rectangle{ private: double w, h; public: double width(){ return w; } double area() const{ return w * h; } void getWidth(){ cout > w; } double getHeight(double scale){ h *= scale; return h; } };

4. Which of the following methods are accessors for the class Rectangle? Choose TWO correct answers. A. width() B. area() C. getWidth() D. getHeight() (2 marks)

5. Which of the followings will set the string variable str to "AAA" ? Choose TWO correct answers. A. string str(3, 'A'); B. string str("AAA-AAA", 3, 3); C. string str = "AA"; str.insert(1, "A"); D. string str = "A";

str + "AA"; (2 marks)

6. Which of the followings are CORRECT about friend in C++? Choose THREE correct answers. A. friend is used to enable outsiders accessing the public members of a class. B. friend is used to enable outsiders accessing the private members of a class. C. friend is used to expose local variables of a method from a class. D. A regular function or another class can be declared as friend to a class. E. A function declared as friend in a class is not a member of the class. F. Declaring a function as friend in a class will make it running faster. (3 marks)

7. Which of the followings are TRUE about operator overloading in C++? Choose TWO correct answers. A. All operators can be overloaded. B. The operator == can be overloaded for comparing the equality of two objects . C. Overloaded operatatros are faster than the existing operators. D. Once an operator is overloaded, the existing operator still can be used.

(2 marks) 8. Based on the code segment in Program B2, determine which user inputs will make the program prints out the message Hello World!

Choose TWO correct answers.

// Program B2 string secret = "twenty"; string guess; cout > guess; if ( secret.compare(guess) > 0 ){ cout...


Similar Free PDFs