7
8/8/2019 Introduction to Programming Environments C UNIX 115 http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 1/7 Sri Lanka Institute of Information Technology 001387 B. Sc. Special Honours Degree/ Diploma In Information Technology Mid Term Examipation Year 1, Semester 1 (2008) Introduction to Programming Environments . (C++/UNIX) (115) I Duration: tHour I Friday, 02nd May 2008 (Time 02.00 p.m. - 03.00 p.m.) Instruction to Candidates: This paper has 20 questions. Answer All Questions. Use the answer sheet provided in..the last page This paper contains 6 pages with Cover Page.

Introduction to Programming Environments C UNIX 115

Embed Size (px)

Citation preview

Page 1: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 1/7

Sri Lanka Institute of Information Technology

001387

B. Sc. Special Honours Degree/ DiplomaIn

Information Technology

Mid Term Examipation

Year 1, Semester 1 (2008)

Introduction to Programming Environments

. (C++/UNIX) (115)

I Duration: tHour IFriday, 02nd May 2008

(Time 02.00 p.m. - 03.00 p.m.)

Instruction to Candidates:

• This paper has 20 questions. Answer All Questions.

• Use the answer sheet provided in..the last page

• This paper contains 6 pages with Cover Page.

Page 2: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 2/7

1. Find the correct identifier list from the followings

a. int, data, marks, data_l

b. mark, markl, Imark, mark_lc. tax rate, Tax_Rate, TaxRate, TaxJate

d. data, total_marks, tax_rate, marks2

2. What are the data types of the foHowing respectively

'6', 5.0L, 5.0, 2.Of, "6"

a. char, int, long int, float, string

b. string, long double, double, double, char

c. char, long double, float, float, string

d. char, long double, double, float, string

3. What are the values of the variables after the following statements are executed?

j :1;k

:++;

m

;:::(++k--++) ;

a. j = 2 k = 2 m = 0

b.

j= 3 k

= ~m = 1

c. j = 3 k = 2 m = 1

d. j = 3 k = 2 m = 0

4. Which of the following statement is false?

a. A logical operator will always return a value of 0 or 1.

b. A value is a logical FALSE if it is equal to O.

c. A value is a logical TRUE if it is equal to -I.

d. Negative values cannot be interpreted as logical values.

5. If j ;:::0, k ;::: 12 and m ;::: 2, what value is stored in n?

n= (k+m) + (j * (k/m)) + (j + (m)) + (m/k)il

a. 0

b. II

c. 16

d. 20

Page 1/ Page 5

Page 3: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 3/7

6. Which operator is not defined for floating point data types?

a.%=

b./=

c.

<=

d. +=

7. What is the most accurate value ofy in the following coding?

int kfloat y

a. 10

b. 10.01'c. 0

d. O.Of

2, i =3, j = 1;= ((k / i) + i * 10 / j) % i;

8. Consider the following statement:

lint i = 100, j = 0;

a. i< 3

b. !(j<l)

c. (i>0) II (j>50)d. (j<1) && (i<=10)

Which of the following statements is true?

9. What is the value of the following expression?

(1((4-4%3) < 5 && (6/4 >3)))

a. true.

b. false.

c. invalid.

d. notle of the above.

10. What is the value ofb after evaluating the following expression?

int a = 3, b = 8, C = 3;b += ++a * b-- % c--;

a. 1

b. 10

c. 2

d. 9

Page 2/ Page 5

Page 4: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 4/7

11. What must be true of a switchO statement.

a. The controlling expression must always set for one variable.b. A default case is a must for a switchO statement.

c. The only way to exit a switch() structure is through the use·ofthe break statement.

d. Multiple values can be listed on the case line - such as case 1.2.3 :

12. Which of the following assignments produces the value zero?

a.esult = 9%3 - 1;

b.

result = 8%3 - 1;

c.

result = 2 - 6%3;

d.

result = 2 - 8%3;

13. What is the purpose of type casting?

a. To create new data types.

b. To change the data type of a variable.c. To convert the data stored in a variable to a different type before using it in an

expressIon ..

d. To prevent the loss of data when passing values to functions.

14. If your program does not compile and produce an error message called "Undeclared

Identifier A" you should look for:

a. The missing for loop semicolons.

b. Missing curly braces

c. Misspelled the variables

d. Misspelled the header file iostream

15. What is value of ans after evaluating the expression bellow?

int a = 5, b = 8, ans = 2;

ans += a++ + ++b * 5 / b-- + b % 2;

a. 21

b. 11

c. 13

d. 12

Page 3/ Page 5

Page 5: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 5/7

\~ 11-

To answer question number ~ and }4 use the following code given. The code calculates

the sum of 10 integers and prints the total.,

cout«"Enter number: ";

cin»number;

total = total * number;

}

int num, toatal=O, i;

for(i = 1 i i<=10 i++)

{

cout«"Total = "«total«endl;

return 0;

}

#include <iostream>

using namespace std;int main ()

{

l.2 .

3.

4.

5.6 .

7.

8 .

9.

10.

ll.

12.

13.

14.

15.

16.

16. What is/are the line number/s where you can find a syntax error/s?

a. 5,9

b. 5,10,11

c. 11, 14

d. 7,10,11

17. What is the line number you can find a logical error?a. 5

b. 7

c. 11

d. ]4

18. What output will the following code fragment produce?

int score = 87, rank = 2;

if (score >= 95)

if(rank <= 5)cout « "Nice job!";

else

cout « "Good job!";

a. Nicejob!

b. Goodjob!

c. "Nice job!"

d. "Good job!"

Page 4/ Page 5

Page 6: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 6/7

19. What is the output of the following code?

#include <iostream>

using namespace std;

int main () {

int r,i;

for (r=5; r>O; r--) {

if (rl=3)

cout « r « " ";

else

for (i=O; i<2; i++)

cout « i « H H;

}

return 0;

a. 5 4 3 2 1 0 0 1 2

b. 5 4 1 0 1 2 1

c. 54 1 0 1 2

d. 540 1 2 1

20. What is the output.ofthe following coding if the inpyts are 8 12 30 7 6 -99?

#include <iostream>

using namespace std;

int main() {

int n;

do

{cin»n;

if(n>10)

cout«n«" H;

cout«n«H H;

}while(nl= -99);

return 0;

}

a. 8 8 12 12 30 30 7 7 6 6 -99

b. 8 1230307766 -99 -99

c. 8 12 12 30 30 7 6 -99

d. 8 123076 -99

Page 5/ Page 5

Page 7: Introduction to Programming Environments C UNIX 115

8/8/2019 Introduction to Programming Environments C UNIX 115

http://slidepdf.com/reader/full/introduction-to-programming-environments-c-unix-115 7/7

Mid Term Examination

Year 1, Semester 1 (2008)02/05/2008

Introduction to Programming

Environments (C++/ UNIX) (115)

Answer Sheet

Student No: lL- ._J

1. la Ib Ie Id I

2. I a I b I e I d I

3.. I a I b I e I d I

4. I a I b I e ·1 d I

5. I a I b I e I d I

6. I a I b. I e I d I

7. ! a fbl e I d I

8. I a I b !'e I d I

9. I a I b I e I d I

10·1 a I b Ie I d I

11. la Ib Ie ~

12.. 1 a I b ! e ~

13. I a I b I e ~

14. I a. I b I e ~

15. I a I b I e ~

16. I a I b I e ~

17. I a I b I e ~

18. I a I b I e ~

19. I a I b I e '-d I

20. Ia I b I e ~