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

Similar documents
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)

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

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

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)

Name Section: M/W or T/TH. True or False (14 Points)

True or False (12 Points)

True or False (15 Points)

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

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

Why Is Repetition Needed?

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

REPETITION CONTROL STRUCTURE LOGO

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.

True or False (14 Points)

CS2141 Software Development using C/C++ C++ Basics

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

CSCE 206: Structured Programming in C++

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

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

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

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

Increment and the While. Class 15

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

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

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

C++ Final Exam 2017/2018

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

In this chapter you will learn:

CS242 COMPUTER PROGRAMMING

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

Definition Matching (10 Points)

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

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

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

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Objectives. In this chapter, you will:

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

Computer Programming : C++

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

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

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

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

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

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 (!

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

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

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

Name. Classes and Objects 1. We re going to develop a class to help out Café Below is the definition for a class called

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

Programming. C++ Basics

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

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

CSCE Practice Midterm. Data Types

Chapter 1 INTRODUCTION

A First Program - Greeting.cpp

Chapter 3 Problem Solving and the Computer

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

CSCE 110 PROGRAMMING FUNDAMENTALS

Exam 3 Chapters 7 & 9

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

Programming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does

Add Subtract Multiply Divide

WARM UP LESSONS BARE BASICS

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

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

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Chapter 5: Control Structures II (Repetition)

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

2 nd Week Lecture Notes

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

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:

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

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

True or False (15 Points)

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

Repetition Structures

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

CIS 130 Exam #2 Review Suggestions

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

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

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

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

The C++ Language. Arizona State University 1

Programming Language. Functions. Eng. Anis Nazer First Semester

CS2255 HOMEWORK #1 Fall 2012

Transcription:

Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program what you have been writing in lab. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. Unless otherwise noted, assume a single space between all words. For this test the two-character sequence \n is to be taken to mean the newline character. here are no INENIONAL syntax errors. Assume that all code in this exam will compile. here may be logic errors in some of the code. Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) 1) A(n) is a function that does not return a function value to its caller and is invoked as a complete, stand-alone statement. A) Value-returning function B) Main Function C) Subprogram D) Void Function E) None of these 2) How many function values does a void function have? A) 0 B) 1 C) As many as necessary D) 2 E) 3 F) None of these 3) Circle all of the following that are examples of event-controlled loops: A) Count-Controlled B) Sentinel-Controlled C) Flag-Controlled D) Previous-Value E) End-Of-File Controlled F) All of these 4) An individual pass through, or repetition of, the body of a loop is called a(n). A) Loop test B) Priming read C) ermination condition D) Iteration E) None of the above Page 1 of 12

5) Reference parameters (passing by reference) are used if a parameters data flow is: A) one-way, into the function B) one-way, out of the function C) two-way, into and out of the function D) None of these 6) Value parameters (passing by value) are used if a parameters data flow is: A) one-way, into the function B) one-way, out of the function C) two-way, into and out of the function D) None of these 7) A loop is a loop that executes a specified number of times. A) While B) Count-Controlled C) Looping D) Event-Controlled E) None of hese 8) A(n) loop is a loop that terminates when something happens inside the loop body to signal that the loop should be exited. A) Sequence B) Selection C) Looping D) Sub-program E) None of hese 9) A(n) is a variable declared in a function heading. A) Function Call B) Reference C) Parameter D) Argument E) None of hese 10) A(n) parameter is a parameter that receives a copy of the value of the corresponding argument. A) Function B) Value C) Variable D) Reference E) None of these 11) A(n) parameter is a parameter that receives the location (memory address) of the caller s argument. A) Function B) Value C) Variable D) Reference E) None of these 12) is the precedence that a local identifier in a function has over a global identifier with the same name. A) Scope B) Non-Local Identifier C) Name Precedence D) Local Identifier E) None of these Page 2 of 12

13) With respect to a given block, a is any identifier declared outside that block. A) Scope B) Non-Local Identifier C) Name Precedence D) Local Identifier E) None of these 14) (2 pts) What are the three logical operators for C++? 15) (6 pts)he void function named GetNums has two parameters: a pass-by-value parameter named x of type float a pass-by-reference parameter named num of type int. write a valid function prototype and function heading for the function GetNums? Function Prototype: Function Heading: 16) (6 pts) Assume that the Boolean variables X and Y both have the value true. What is the Boolean value of the following expressions? a) (!(X!Y) && ( X && (Y!Y)) ) X b) (Y && (X!X)) c) (Y!X && X!Y) && X && Y Page 3 of 12

17) (6 pts) For the operators shown below, CLEARLY indicate if the operator is: Relational (use an R), Logical (use an L) or Neither (use an N). NOE: that there are no spaces between characters even though it may appear that there is a blank in some of the operators a) >= b)?? c) && d) >> d) >! e)! f) =! g)!= h) =< i) == j) <= k) = 18) (12 pts) rue/false questions. Select for true and F for false.. F a) An if statement cannot occur inside of another if statement. F b) he body of a for loop executes one or more times. F c) Local identifiers have name precedence over global identifiers. F d) he use of the statement: return; is not valid in a void function. F e) A logical expression can consist of a single relational expression? F f) Static variables in a function maintain their value from function call to function call. F g) A compile error results when the Dataype defining a functions value type is omitted. F h) he statement for(;;); is a valid C++ statement. F i) Value parameters receive a copy of the arguments value. F j) A function call can contain more arguments than the number of parameters in the corresponding function heading. F k) In sentinel-controlled loops, the sentinel is a value expected as normal input? F l) An argument corresponding to a reference parameter can be a constant or arbitrary expression? Page 4 of 12

19) (10 pts) Match the words with their definitions. Choose the BES definition for each word. a) Static Variable b) Scope c) Function Prototype d) Lifetime e) Loop f) Event Counter g) Function Call h) Iteration Counter i) Local Variable j) Argument A) Definition is not listed below (may be used more than once). B) A parameter that receives a copy of the value of the corresponding argument. C) A variable declared within a block and not accessible outside of that block. D) he region of a program where it is legal to reference (use) an identifier. E) he fundamental control structure that allows branches in the flow of control F) A variable or expression listed in a call to a function. G) A variable that is incremented when a particular event occurs. H) he period of time during program execution when an identifier has memory allocated to it. I) A statement that transfers control to a function. J) A variable for which memory remains allocated throughout the execution of the entire program. K) A function declaration without the body of the function. L) A control structure that causes a statement or group of statements to be executed repeatedly 20) (6 pts) What is the output for the code segment below: int count = 0; bool finished = false; while (!finished) finished = count > 5 count++; cout << count << - ; Page 5 of 12

21) (6 pts) In the following code segment, all variables are integers. maxheight = 50; maxweight = 30; if ( height < maxheight) if (weight < maxweight) cout << Message #1\n ; else cout << Message #2\n ; else if (weight < maxweight) cout << Message #3\n ; else cout << Message #4\n ; If the variables height and weight have the following values, what is the output of the above segment of code when it is executed? a) height = 50, weight = 20 b) height = 30, weight = 50 22) (6 pts) Consider the following segment of code int loop = 0; while (loop < 7) cout << Hello ; loop = loop + 2; Rewrite the above code segment as a for loop such that the same output is obtained. Page 6 of 12

23) (8 pts) Finish the segment of code below by using an if-then-else-if statement to print out the following information based on the value of grade: A if grade has a value of 90, B if grade has a value of 80, C if grade has a value of 70, and Error if grade is not 90, 80 or 70. Note: he output is to be only one value A, B, C or Error. int grade; cout << Enter in the grade value: ; cin >> grade; // if-then-else-if statement follows this comment. 24) (8 pts) A program requires a user to enter a positive (greater than zero) integer. Use a while loop to continually prompt the user to enter a positive integer until one is entered. If a negative integer is entered, print out an error message and prompt the user again for a positive integer. Assume that integer values only are entered. Declare any necessary variables. Page 7 of 12

25) (6 pts) For the following code segment, write out what is printed to the screen. Place a single character in each box, skip a box to indicate a space, and skip a row to indicate a blank line. #include <iostream> using namespace std; void est(); int main() est(); est(); est(); return 0; void est() static int i = 5; int j = 5; i++; j--; // increment i and decrement j cout << i << << j << endl; 26) (6 pts) For the following code segment, write out what is printed to the screen. Place a single character in each box, skip a box to indicate a space, and skip a row to indicate a blank line. int loop_b; int loop_a = 3; while ( loop_a > 0) for (loop_b = 0; loop_b <= loop_a; loop_b++) cout << loop_b; loop_a--; cout << loop_a << endl; Page 8 of 12

27) (10 pts) Finish the program below by adding a value-returning function specified below. Add only a function prototype, function call statement and function definition to the following program. he name of the value-returning function is CalcValue. he function has two float parameters. he function is to divide the first parameter by the second parameter and return, as its function value, the floating point result of the division. #include <iostream> using namespace std; // Place the function prototype below this line int main() float sum = 4563; float number = 20; float value; // number to be divided // number that divides into sum // holds value returned by the function // Place the function call statement below this line return 0; // Place the function definition below this line Page 9 of 12

28) (8 pts) Rewrite the value-returning function definition below as a void function definition such that the caller of the function still has access to the value returned by the value-returning function. float Calculate (float num1, float num2) float result; result = (num1 + num2)*5.0; return result; 29) (10 pts) Write a Boolean value-returning function definition called OpenInputFile. - he function prompts the user for the name of the input file, reads the name of the input file and then tries to open the input file (use.c_str()). - he function returns a value of true if the input file was successfully open. - A value of false is returned if the input file was not successfully opened. - he function requires two parameters. he first parameter represents the name of the input file that is entered for opening, and the name of this file must be available for use in main(). - he second parameter represents the input stream to use. Page 10 of 12

30) (8 pts) When the program shown below is executed, what is the output to the screen? his problem deals with the scope of a variable in a program, and the order of execution of statements. here will be a total of 4 lines written to the screen from this program. #include <iostream> using namespace std; void function_a(int&); void function_b(int); int number = 4; int main() int number = 3; function_a(number); cout << number in main is: << number << endl; function_b(number); return 0; void function_a(int& num) int number = 2; num = num +2; cout << number in function A is: << number << endl; void function_b(int sum) cout << number in function B is: << number << endl; sum = sum + 1; cout << sum in function B is: << sum << endl; he output for this program is as indicated below. In the blank to the left of the lines, place 1,2,3 or 4 to indicate the order the statements are printed (1 for first, 4 for last). In he blank at the end of the line, put in the output value. number in main is: number in function A is: number in function B is: sum in function B is: Page 11 of 12

Bonus Question (+8 pts) he following program is executed. he user enters the integer 6 when prompted for a number. What is the output to the screen? Just fill in the blanks indicated in the output line shown Be careful on this problem. hink about what is being performed with which variables #include <iostream> using namespace std; void Summation( int num, int& result ); int main () int number = -1; int result = -1; cout << Enter an integer between 1 and 10: ; cin >> number; Summation(number, result); // first function call Summation(number, result); // second function call // show the output for this cout statement only cout << Summation for << number<< is: <<result <<endl; return 0; void Summation( int num, int& result) static int loop = 0; for (loop = num; num >=1; num--) result = result + loop; num = num 1; return; Answer: Summation for is Page 12 of 12