C++ Final Exam 2017/2018

Similar documents
1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.


1. In C++, reserved words are the same as predefined identifiers. a. True

C++ Programming: From Problem Analysis to Program Design, Third Edition

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Review Summer CSC1322 Adv Programming in C++ Professor: Zhang

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

REPETITION CONTROL STRUCTURE LOGO

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Name SECTION: 12:45 2:20. True or False (12 Points)

Why Is Repetition Needed?

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Name Section: M/W T/TH Number Definition Matching (8 Points)

C++ Programming: From Problem Analysis to Program Design, Third Edition

Do not start the test until instructed to do so!

Increment and the While. Class 15

LAB 4.1 Relational Operators and the if Statement

If Control Construct

Chapter 7. Additional Control Structures

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

Boolean Algebra Boolean Algebra

Name Section: M/W T/TH Number Definition Matching (6 Points)

Definition Matching (10 Points)

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

CIS 130 Exam #2 Review Suggestions

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Exam 3 Chapters 7 & 9

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

Chapter 4 - Notes Control Structures I (Selection)

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

Chapter 2: Basic Elements of Java

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Chapter 3 Problem Solving and the Computer

FORM 2 (Please put your name and form # on the scantron!!!!)

Chapter 5: Control Structures II (Repetition)

6. C++ Subprograms David Keil CS I slides 7/03 1

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

CSCE 206: Structured Programming in C++

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

a data type is Types

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

True or False (14 Points)

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

Test Bank for Problem Solving with C++: The Object of Programming, 8/e Chapter 2 C++ Basics

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

CS242 COMPUTER PROGRAMMING

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

C++ For Science and Engineering Lecture 12

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

INTRODUCTION TO COMPUTER SCIENCE - LAB

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

Chapter-8 DATA TYPES. Introduction. Variable:

J. P. Cohoon and J. W. Davidson 1999 McGraw-Hill, Inc. Control Constructs. Mechanisms for deciding when and how often an action should be taken

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

Control Structures of C++ Programming (2)

CS Spring 05 - MidTerm

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018

C/C++ Programming Lecture 7 Name:

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Chapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1

Objectives. In this chapter, you will:

Introduction to Programming

Chapter 7 Array. Array. C++, How to Program

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Chapter 8 Statement-Level Control Structure

IS0020 Program Design and Software Tools Midterm, Fall, 2004

Looping. Arizona State University 1

CS1100 Introduction to Programming

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

CS2255 HOMEWORK #1 Fall 2012

Transcription:

1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value is 5? 1. cin >> numb; 2. if (numb > 0) 3. numb = numb + 10; 4. else 5. if (numb > 5) 6. numb = numb + 15; o A 0 o B 5 o C 25 o D 15 3) What type of C++ statement(s) stores a value in a variable? o A both input and assignments o B assignments o C output o D input 4) Which of the following is NOT a reserved word in C++? o A return B int C const D num 5) What is the output? 1. int n = 0; 2. cout << ((n)? n++ : ++n); o A 0 o B 1 o C None of these o D 2 Page 1 of 18

6) What is the output? 1. int x = 5; 2. cout<< (x++)+x<<endl; o A 11 o B 10 o C None of these o D 12 7) What is the output of the following code? 1. if ( 6 > 8) 2. { 3. cout << " ** " << endl ; 4. cout << "****" << endl; 5. } 6. else if (9 == 4) 7. cout << "***" << endl; 8. else 9. cout << "*" << endl; o A **** o B *** o C * o D ** 8) Which of these is a valid reserved word in C++? o A Char B Include C Double D Const o E None of these 9) Suppose that x, y, z, and w are int variables. The expression x(y+z)/w in C++ is written as o A x * (y + z) / w o B x * y + z / w o C x * y + x * z / w o D x (y + z) / w 10) The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to. o A 14 o B 14.8 o C 13 o D 15 Page 2 of 18

11) Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C **What is the value of ch3 after the following statements execute? 1. cin.get(ch1); 2. cin.get(ch2); o cin.get(ch3); o A 'B' o B 'C' o C 'A' o D '\n' 12) Suppose x and y are int variables. Consider the following statements: 1. if (x > 5) 2. y = 1; 3. else if (x < 5) 4. { 5. if (x < 3) 6. y = 2; 7. else 8. y = 3; 9. } 10. else 11. y = 4; **What is the value of y if x = 3? o A 3 o B 1 o C 2 o D 4 Page 3 of 18

13) The value of the expression 26 14 % 3 + 1 is. o A 1 o B 25 o C 24 o D 0 14) Suppose that x is an int variable, ch is a char variable, and the input is: 276. **Choose the values after the following statement executes: cin >> ch >> x; o A ch = '2', x = 76 o B ch = '2', x = 276 o C ch = ' ', x = 276 o D Input Failure 1. char ch1, ch2; 2. cin >> ch1; 3. cin.get(ch2); 4. cout << ch1 << ch2; 15) If the input is: M N **what is the output? o A MN B M C M N D None of these E N 16) What is the output of the following C++ code? 1. x = 6; 2. if (x > 10) 3. cout << "One "; 4. cout << "Two "; o A One o B Two o C One Two o D Two One Page 4 of 18

17) What is the output? 1. int x = 1; 2. while (--x) 3. cout<< x; o A 0 o B 1 o C No output o D Infinite loop 18) Which of the following operators has the highest precedence? o A * B! C % D = 19) If the input is: 35 62&1.78 **what are the values of x,z,ch? 1. int x; 2. double z; 3. char ch; 4. cin>>x>>ch>>z; o A x = 35, ch = '6', z= 2.0 (or 2) o B x = 35, ch = 6, z= 2.0 o C Input Failure o D x = 35, ch = 62, z= 78 20) What is the output? 1. int n = 0; 2. cout << ((n)? n++ : ++n); o A 1 o B 0 o C None of these o D 2 Page 5 of 18

21) After the execution of the following code, what is the value of sum? 1. int sum = 0; 2. int num = 10; 3. if (num > 0) 4. sum = sum + 10; 5. else if (num > 5) 6. sum = num + 15; o A 20 o B 10 o C 25 o D 0 22) Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0)? x : y; o A 2 o B 3 o C 6 o D 4 23) What is the output? 1. cout << static_cast<int>(7.5 + static_cast<double> (19 / 2)); o A 16 o B 16.5 o C None of these o D 17 o E 17.5 Page 6 of 18

24) Which of the following is a reserved word in C++? o A Char o B include o C void o D duble 25) Which of these is an invalid identifier? o A None of these o B pop_ o C _D3 o D 1b o E _sum3 26) Which of the following is a legal identifier? o A 1program o B program_1 o C program 1 o D program! 27) What is the output? 1. cout<<"welcome\rhi"; o A Syntax Error B Hilcome C Hi D HiWelcome Welcome Page 7 of 18

28) What is the output? 1. int i = 4, j = 6, k = 7, n = 3; 2. cout << i + j*k - k%n << endl; 3. cout << i / k << endl; o A 45 0.66667 o B None of these o C 0 0 o D 45 0 29) What is the output? 1. int x = 5; 2. if (x-- == 4) 3. cout << "One" << endl; 4. cout << x << endl; 5. cout << "Two"; o A 5 Two o B One Two o C One 5 Two o D 4 Two o E One 4 Two Page 8 of 18

30) The conditional operator? : takes arguments. o A 1 o B 2 o C 3 o D 4 31) What is the output? 1. if (15 % 5) 2. cout << "Two"; 3. else cout << "One"; o A One o B None of these o C Two o D Two One 32) Which of the following is the new line character? o A '\r' o B '/n' o C '\n' o D '/r' 33) Which of the following expressions correctly determines that x is greater than 10 and less than 20? o A 10 < x < 20 o B (10 < x < 20) o C 10 < x && x < 20 o D 10 < x x < 20 Page 9 of 18

34) What is the output? 1. if (1 == 4 >= 1) 2. cout << "One"; 3. else 4. cout << "Two"; o A OneTwo o B One o C Two o D None of thes 35) Which of these will cause a syntax error? o A float f = 1000; o B char ch = ' '; o C bool b = 111; o D None of these 36) What is the output of the following code fragment? 1. int x = 10; 2. if (x > 15) 3. x = 0; 4. cout << x << endl; 5. else 6. cout << x + 5; o A 5 o B 10 o C 0 o D None of these Page 10 of 18

37) Suppose x and y are int variables. Consider the following statements: 1. if (x > 5) 2. y = 1; 3. else if (x < 5) 4. { 5. if (x < 3) 6. y = 2; 7. else 8. y = 3; 9. } 10. else 11. y = 4; **What is the value of y if x = 6? o A 1 o B 3 o C 2 o D 4 38) What is the output? 1. int n = 1; 2. cout << ((n)? n++ : ++n); o A 3 o B 1 o C 2 o D None of these Page 11 of 18

39) Which of these is a valid use of c? 1. const int c = 9; o A c = c+1; o B cout<< c*3; o C c = 20; o D None of these o E cin>>c; 40) Which of the following is a relational operator? o A == o B && o C = o D! 41) Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 **Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; o A x = 28, y = 12, z = 32.6 o B x = 28, y = 32, z = 0.6 o C x = 28, y = 12, z = 0.6 o D x = 28, y = 32, z = 12.0 Page 12 of 18

42) Suppose that alpha and beta are int variables. The statement alpha = beta-- ; is equivalent to the statement(s) o A alpha = beta - 1; beta--; o B alpha = 1 - beta; beta--; o C None of these o D alpha = beta; beta = beta - 1; 43) Consider the following statement: int y =!(12 < 5 3 <= 5 && 3 > x)? 7 : 9; **What is the value of y if x = 2? o A 3 o B 2 o C 7 o D 9 44) Which of the following will cause a semantic error, if you are trying to compare x to 5? o A if (x = 5) o B if (x >= 5) o C if (x == 5) o D if (x <= 5) Page 13 of 18

45) What is the value of x after the following statements execute? 1. int x; 2. x = (5 <= 3 && 'A' < 'F')? 3 : 4; o A 2 o B 3 o C 5 o D 4 46) In a control structure, the computer executes particular statements depending on some condition(s). o A repetition o B looping o C selection o D sequence 47) What is the output of the following C++ code? 1. int x = 55, y = 5; 2. switch (x % 7) 3. { case 0: case 1: y++; 4. case 2: case 3: y = y + 2; 5. case 4: break; 6. case 5: case 6: y = y 3;} 7. cout << y << endl; o A 2 B 5 o C 8 D None of these 48) Consider the following statement: int y =!(12 < 5 3 <= 5 && 3 > x)? 7 : 9; **What is the value of y if x = 2? o A 2 o B 3 o C 7 o D 9 Page 14 of 18

49) A(n) statement causes an immediate exit from the switch structure. o A break o B endl o C default o D exit 50) After the execution of the following code, what is the value of sum? 1. int sum = 0; 2. int num = 10; 3. if (num > 0) 4. sum = sum + 10; 5. else if (num > 5) 6. sum = num + 15; o A 20 o B 10 o C 25 o D 0 51) Consider the following code. 1. const int LASTVAL = -99; 2. int entry; 3. cin >> entry; 4. while (entry!= LASTVAL) 5. { 6. triple = entry * 3; 7. cout << triple << endl; 8. cin >> entry; 9. } **This code is an example of a(n) while loop. o A EOF-controlled o B counter-controlled o C sentinel-controlled o D None of answers. Page 15 of 18

52) Assume all variables are properly declared. What is the output of the following C++ code? 1. num = 100; 2. while (num <= 150) 3. num = num + 5; 4. cout << num << endl; o A 160 o B 150 o C 145 o D 155 53) What is the output? 1. int x = 5; 2. cout<< (x++)+x<<endl; o A 10 B 12 o C None of these D 11 54) What is the output of the following program segment? 1. int x = 14, y = 60; 2. while (((y - x) % 3)!= 0) 3. { 4. cout << y << " "; 5. y = y - 5; 6. } o A 60 55 B 46 27 o C 60 55 50 D 60 55 50 45 Page 16 of 18

55) Which of the following is true about a while loop? o A It cannot contain if statement. o B The body of the loop may not execute at all. o C The body of the loop is executed at least once. o D The logical expression controlling the loop is evaluated before the loop is entered and after the loop exits. 56) What is the output of the following C++ code? 1. count = 1; 2. num = 25; 3. while (count < 25) 4. { num = num - 1; 5. count++;} 6. cout << count << " " << num << endl; o A 25 1 o B 24 1 o C 24 0 o D 25 0 57) In structures, the computer repeats particular statements a certain number of times depending on some condition(s). o A looping o B branching o C sequence o D selection 58) What is the output of the following C++ code? 1. num = 0; 2. while (num < 5) 3. { cout << num << " "; 4. num = num + 1; } o A 0 1 2 3 4 5 B 0 1 2 3 4 o C 1 2 3 4 5 D 1 2 3 4 0 Page 17 of 18

59) Suppose sum and num are int variables, and the input is 18 25 61 6 -A What is the output of the following code? 1. sum = 0; 2. cin >> num; 3. while (num!= -1) 4. { 5. sum = sum + num; 6. cin >> num; 7. } 8. cout << sum << endl; o A 110 o B 92 o C 109 o D 111 ^_^ GOOD LUCK ^_^ Page 18 of 18