CSCE 206: Structured Programming in C++

Similar documents
CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

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

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

Chapter 5: Loops and Files

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

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

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

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

Exceptions, Case Study-Exception handling in C++.

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

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

CSCE Practice Midterm. Data Types

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

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

Unit 7. 'while' Loops

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

204111: Computer and Programming

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

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Multiple Choice Questions (20 questions * 5 points per question = 100 points)

Why Is Repetition Needed?

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

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

Increment and the While. Class 15

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

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

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Chapter 4 - Notes Control Structures I (Selection)

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

CSCE Practice Midterm. Data Types

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

Introduction to Programming

4.1. Chapter 4: Simple Program Scheme. Simple Program Scheme. Relational Operators. So far our programs follow a simple scheme

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

VuZs Team's Work. CS201 Spring Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May :52

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

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.

Lab Instructor : Jean Lai

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSCE 2004 Final Exam Spring Version A

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

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

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

REPETITION CONTROL STRUCTURE LOGO

Chapter 6: Functions

CSCI 1061U Programming Workshop 2. C++ Basics

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

Decisions. Arizona State University 1

Chapter 4: Making Decisions

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

Looping. Arizona State University 1

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

Chapter 4: Making Decisions

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

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

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Repetition Structures

C++ Quick Guide. Advertisements

Chapter 3. More Flow of Control

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Loops and Files. of do-while loop

Chapter 6 Topics. While Statement Syntax Count-Controlled Loops Event-Controlled Loops Using the End-of-File Condition to Control Input Data

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Ch 6. Functions. Example: function calls function

Programming Language. Functions. Eng. Anis Nazer First Semester

CS2255 HOMEWORK #1 Fall 2012

LECTURE 06 FUNCTIONS

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

To become familiar with array manipulation, searching, and sorting.

6.1. Chapter 6: What Is A Function? Why Functions? Introduction to Functions

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

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

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

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

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

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

5. Selection: If and Switch Controls

Short Notes of CS201

Introduction. C provides two styles of flow control:

Chapter 2 - Control Structures

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Chapter 2. Flow of Control. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

CS201 - Introduction to Programming Glossary By

C++ Programming Lecture 1 Software Engineering Group

Quiz Determine the output of the following program:

Standard Version of Starting Out with C++, 4th Edition. Chapter 6 Functions. Copyright 2003 Scott/Jones Publishing

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

LECTURE 04 MAKING DECISIONS

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

CS313D: ADVANCED PROGRAMMING LANGUAGE

Transcription:

CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam, count the pages to make sure you have all 13. Read the questions and instructions carefully to see what kind of answer is expected. Some code snippets may not have the header and std namespace inclusion, but assume that there are included. Put the Exam Code on your scantron in the lower right corner There are 50 questions worth 2 points each. On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work Signature: Name (Print): UIN: Section: 1

TRUE/FALSE: Select A if the statement is true and B if the statement is false. 1) If the specified input file doesn t exist, the program will create one when it tries to open it. 2) The >> operator not only reads data from a file, but also returns a true or false value indicating whether the data was successfully read or not. 3) When evaluating a conditional expression, any value except 0 and negative values is considered true. 4) The following expression will evaluate to true given x = 115, y = 27, z = 3. (x <= z) (y!= z) 5) Following code snippet generates compilation error. int a; char x = '&'; a = x > 100? 0 : 1; 6) The output of the following code snippet is 01234 for (int i = 0; i < 5; i++) cout << i; i++; 7) A function prototype eliminates the need to place a function definition before all calls to the function. 8) The result of expression 1 < 2 is same as the expression 1 < 2. 9) If not all the parameters of a function have default values, the ones that don t are declared first in the parameter list. 10) When passing by value, changes to the parameter in the function do not affect the value of the argument. 11) Local (auto) variables, static variables, and global variables are all created on the stack. 12) The expression of a switch statement must be an integer variable or an expression that evaluates to an integer value. 2

13) The following if statement will test whether x is between 0 and 4: if (0 <= x <= 4) 14) In a nested loop, the inner loop goes through all repetitions for each repetition of the outer loop. 15) The value of c after the execution of the following program is 31. int a = 5; int b = 6; int c = ++(a*b); MULTIPLE CHOICE: Choose the the single option that best completes the statement or answers the question. 16) Which type of loop is best when the number of iterations is known? A) for B) while C) do-while D) Both B and C E) Both A and C 17) What is the value of n after the following code is executed? int n = 8; (n % 2 == 0)? n = n/2 : n = (3*n)+1; A) 8 B) 25 C) 4 E) Either A or B, depending on the computer. 3

18) What is the output of the following code? for (int i = 0; i > 4; i++) cout << i*i << ; A) 0 1 4 9 B) 0 1 4 9 16 C) No output E) Garbage value 19) If a switch statement without a default does not have a matching case for the value being evaluated, the program: A) Ends immediately B) Moves to the first line of code after the switch statement C) Has a runtime error D) Has a compilation error E) Prints garbage values 20) A function s local variables exist. A) As long as the program is executing B) From the first function call in the program to the end of the program C) From the first function call in the program to the last function call in the program D) As long as the function is executing 21) A function definition includes: A) Return type B) Function name C) Parameter List D) Function body E) All of these 22) Which type of loop is best when the loop must execute at least once? A) for B) while C) do-while D) Any of these 4

23) What is the output of the following code? int count = 0; while (count < 5); cout << Hello << endl; count++; A) An infinite loop B) Hello will print four times C) Hello will print five times 24) Which of the following expressions will return true if x is between 27 and 38? A) 27 < x < 38 B) 27 <= x <= 38 C) 27 < x x < 38 D) 27 <= x x <= 38 E) 27 < x && x < 38 25) When you print a variable within an inner block that has the same name as the variable in an outer block, the result is: A) The value of the outer variable is printed B) The value of the inner variable is printed C) A runtime error E) Garbage value is printed 26) If multiple expressions in an if/else if block are true, the program will. A) Throw an compilation error B) Execute all blocks with a true expression C) Execute one of the blocks with a true expression at random D) Execute the first block with a true expression E) Halt abruptly 5

27) What is the output of the following code? int count = 0; do cout << Goodbye << endl; count++; while (count < 5) A) An infinite loop B) Goodbye will print 4 times C) Goodbye will print 5 times 28) Which of the following is a valid function prototype for a function that takes a single integer argument and doesn t return a value? A) void displayprice(int); B) void displayprice(int) C) displayprice(int price); D) displayprice(int); E) Both B and D 29) What is the output of the following code? int grade = 83; if (grade >= 90) cout << Congratulations, ; cout << you got an A! ; A) Congratulations, B) Congratulations, you got an A! C) Congratulations, you got an A! 6

30) What is the output of the following code? int x = 12; int p = 10 * --x * x++; cout << p++; A) 1320 B) 1210 C) 1321 D) 1211 31) Inspecting user input to determine whether it is acceptable or not is called. A) Menu selection B) Compiling C) Input grounding D) Range checking 32) What is the output of the following code? int x = 23; if (x < 20); cout << x is less than 20 ; A) x is less than 20 B) There is no output C) A runtime error 7

33) What is the output of the following code? int sum(int, int = 5, int); int main() cout << sum(12, 15); return 0; int sum(int val1, int val2, int val3) return val1 + val2 + val3; A) 17 B) 27 C) 32 D) A runtime error E) Compilation error 34) What is the output of the following code? bool rainy = true, cold = true; if (rainy) cout << It is raining today ; else if (cold) cout << It is cold today ; else cout << The weather is nice today ; A) It is raining today B) It is cold today C) It is raining today It is cold today D) The weather is nice today E) The program will crash 8

35) What is the output of the following program. int a = 3 * 4; int b = 4; if(a%b == 0) cout << "Variable" << a << "is even"; break; A) Variable 4 is even B) Variable a is even C) Compilation error D) Run time error E) No output 36) Values passed to a function are called, variables in a function that hold the values passed to it are called. A) Arguments, specifications B) Arguments, parameters C) Parameters, arguments D) Parameters, specifications E) Formal argument, Actual argument 37) The correct order of operations for logical operators based on their precedence is: A), &&,! B) &&,,! C) &&,!, D)!, &&, E)!,, && 38) To read/write to files, the header must be included. A) iostream B) filestream C) fstream D) fileio 9

39) What is the output of the following code? int n = 1; switch (n) case 0: cout << Four score << endl; break; case 1: cout << and seven << endl; break; default: cout << years ago << endl; A) Four score B) and seven C) years ago D) and seven years ago E) Compilation error 40) Which of the following is a valid function call for a function that takes two integer arguments and returns an integer value? A) sum(int, int); B) sum(4, 5); C) sum(int num1, int num2); D) int sum(4, 5); E) Both B and D 41) Functions with the same name, but different parameter lists are called functions. A) Overwritten B) Overpowered C) Overloaded D) Overflow E) Shortcut 10

42) Which of the following statements will increase x by 1? A) n += 1; B) n++; C) ++n; D) n = n+1; E) All of these 43) What is the value of n after the following code is executed? int addstatic(int); int main() int n = 0; n = addstatic(n); n = addstatic(n); return 0; int addstatic(int n) static int x = 0; return n + ++x; A) 0 B) 1 C) 2 D) 3 E) Compilation error 11

44) What is the output of the following code snippet. int a = 8, b = 7, c = 3; c *= a + b++; b = c++ + ++b; cout << a << " " << b << " " << c; A) 8 54 46 B) 8 40 32 C) 8 65 57 D) Depends on the computer E) Compilation error 45) Which keyword can be used to terminate the execution of a loop? A) stop B) halt C) exit D) break 46) A compiler must know the following about a function before it is called, except: A) Its name B) Its return type C) The number of the parameters D) The data type of each parameter E) It s local variables 47) What is the output of the following code if word.txt exists? ofstream outfile; outfile.open( word.txt ); outfile << balloon ; outfile.close(); A) A runtime error B) balloon is written at the end of the file C) The file is overwritten with the word balloon E) The program ask create a new file word(1).txt and the word balloon is written into it 12

48) A(n) argument is an argument that is passed automatically to a parameter if the argument is missing on the function call. A) Automatic B) Constant C) Static D) Default 49) A variable that signals a condition is called a(n): A) Flag B) Boolean C) Warning D) Constant E) Sentinel 50) retain their contents between function calls. A) Local variables B) Parameters C) Static local variables D) Auto variables E) Register variables 13