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

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

True or False (12 Points)

True or False (15 Points)

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

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)

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

True or False (14 Points)

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

True or False (15 Points)

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.

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

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

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

C++ Final Exam 2017/2018

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

Why Is Repetition Needed?

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

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

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

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

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

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

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

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


C++ Programming Lecture 7 Control Structure I (Repetition) Part I

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

REPETITION CONTROL STRUCTURE LOGO

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

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

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

CSCE 206: Structured Programming in C++

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

Definition Matching (10 Points)

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

Functions, Arrays & Structs

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)

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

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

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

Programming. C++ Basics

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

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

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

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):

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

! Pass by value: when an argument is passed to a. ! It is implemented using variable initialization. ! Changes to the parameter in the function body

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

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

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

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

CMPS 221 Sample Final

WARM UP LESSONS BARE BASICS

Introduction to Programming

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

Looping. Arizona State University 1

CPT101- Principles of Programming

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

Lab Instructor : Jean Lai

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

C++ Programming for Non-C Programmers. Supplement

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

In this chapter you will learn:

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

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

Homework #3 CS2255 Fall 2012

a. a * c - 10 = b. a % b + (a * d) + 7 =

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

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

C++ Programming for Non-C Programmers. Supplement

CSCE 110 PROGRAMMING FUNDAMENTALS

Chapter void Test( int, int, int ); // Function prototype int main() // Function heading { int h; // Local variable

Spring 2002 Page 1 of 8 READ THIS NOW!

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

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

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

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

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Topics. Functions. Functions

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

CSCE Practice Midterm. Data Types

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Exam 3 Chapters 7 & 9

Chapter 5: Loops and Files

Chapter 7. Additional Control Structures

Ch 6. Functions. Example: function calls function

Functions, Arrays & Structs

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

pointers + memory double x; string a; int x; main overhead int y; main overhead

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

Chapter 3 Problem Solving and the Computer

EP241 Computing Programming

Input And Output of C++

Chapter 8 - Notes User-Defined Simple Data Types, Namespaces, and the string Type

Introduction to Programming EC-105. Lecture 2

Lecture 23: Pointer Arithmetic

Transcription:

Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value from function call to function call. F c) Local variables can be accessed only within the block in which they are declared. F d) Arguments corresponding to reference parameters must be variables. F e) A break statement causes an immediate exit from the loop in which it occurs. F f) A continue statement causes an immediate exit from the loop in which it occurs F g) void functions can use the statement return 0; F h) Member names within a structure must be unique. F i) A structure variable contains information for one member only at any given time F j) he lifetime of a local variable is for the duration of the program F k) Static variables in a function maintain their value from function call to function call. F l) Switch statements require at least one case label and a default label. Multiple Choice (12 points) Questions 2 13 For these problems circle all correct answers. For example if answers A, C and E are all valid then circle A, C and E. 2. How many function values does a void function return? A) 0 B) 2 C) 1 D) As many as necessary F) None of these Page 1 of 11

3. Which operations below ARE ALLOWABLE aggregate operations on structures? A) Assignment B) Input/Output C) Comparison D) Return as a functions return value E) Arithmetic 4. A function SomeFunc has two parameters, alpha and beta, of type int. he data flow for alpha is one-way, out of the function. he data flow for beta is two-way, into and out of the function. What is the most appropriate function heading for SomeFunc? (One answer only) A) void SomeFunc(int alpha, int beta) B) void SomeFunc(int& alpha, int beta) C) void SomeFunc(int& alpha, int& beta) D) void SomeFunc(int alpha, int& beta) E) None of the above 5. 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) wo-way, into and out of the function D) None of the above 6. 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) wo-way, into and out of the function D) None of the above 7. Which parameters in the following function heading are value parameters? void DoSomething(string& date, int& num, float average, float sum, string name) A) date B) num C) average D) sum E) name 8. Which parameters in the following function heading are reference parameters? void DoSomething(string& month, int day, float& cost, float pay, string& year) A) month B) day C) cost D) pay E) year Page 2 of 11

9. A function that returns a function value is known as what kind of function? A) Expression less B) Void C) Empty D) Reference Parameter E) Value returning F) None of these 10. he void function named GetNums has two parameters: A pass-by- reference parameter named num of type float. A pass-by- value parameter named x of type int Which of the following choices is the most appropriate function prototype for the function GetNums? (here is only one answer on this problem) A) void GetNums( float, int& ); B) void GetNums( float&, int ); C) void GetNums( float, int ); D) void GetNums( float&, int&); 11. he void function named GetNums has two parameters: a pass-by-reference parameter named num of type float. a pass-by-value parameter named x of type int Which of the following choices is a valid function prototype for the function GetNums? (more than one answer is possible) A) void GetNums( float&, int& ); B) void GetNums (float&, int); C) void GetNums (float& num, int& x ); D) void GetNums (float& num, int x ); 12. An individual pass through, or repetition of, the body of a loop is called a(n)????. A) Loop test B) Event C) ermination condition D) Iteration E) None of the above 13.. in loops, a variable that is incremented each time the loop body executes is called????. A) A loop counter B) An event counter C) An iteration counter D) A sentinel value E) None of the above Page 3 of 11

Short Answer (76 points) Questions 14 23 14. (6 pts) here are four functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code. value = Compute(SumUp(count), MyCalc()); sum = otal(infile, num); A) Which function(s) is(are) most likely value-returning function(s)? B) Which function(s) is(are) most likely void function(s)? C) What are the arguments that are used in the function calls? 15. (6 pts) If a user enters the numbers 1 1 2 3-5 3-1 -8 9 0, what is the output for the following segment of code? Place one character per box, and skip a box to indicate a space. int sum = 0; int number; do cin >> number; // read in a number from standard input if (number < 0) continue; sum = sum + number; cout << sum << - ; while (sum < 11); Page 4 of 11

16. (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. #include <iostream> using namespace std; void function_a(int); void function_b(int); int number = 3; // global variable declaration of number int main() int number = 5; cout << number in main is: << number << endl; function_a(number); return 0; void function_a(int number) number = number - 1; cout << number in function A is: << number << endl; function_b(number); void function_b(int sum) sum = sum - 2; cout << number in function B is: << number << endl; cout << sum in function B is: << sum << endl; he identifying phrases written by the cout statements in this program are shown 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). he value output is placed in the blank at the end of the line. number in main is: number in function A is: number in function B is: sum in function B is: Page 5 of 11

17. (5 pts) Consider the following structure declarations when answering the questions below. struct Color int red; int green; int blue; ; struct Pixel Color color; int intensity; ; a) Write a statement that declares the identifier purple as a variable of Dataype Color. b) Write an output statement that will output the value of green of the variable purple. c) Write a statement that declares the identifier dot as a variable of Dataype Pixel. d) Write a statement that assigns a value of 50 to the intensity member of dot. e) Write an output statement that will output the value of blue of the color member of dot. 18. (5 pts) Write the type declaration for a struct Dataype named Appointment containing the following members: - a string variable representing the name of the appointment - A Date variable indicating the date of the appointment where Date is a structure data type already declared - A ime variable indicating the time of the appointment where ime is a structure data type already declared Page 6 of 11

19. (10 pts) Finish the program below by adding the void function specified below. Add only a function prototype, function call statement and function definition to the following program. No other information is to be added (i.e. variables) he name of the void function is Initime. he function has three integer parameters for the hour, minute and second of the time and one string parameter for indicating am or pm. he function is to initialize the parameters so that they contain the time 11:59:59 pm. Information stored in the parameters must be available in main() after the function call. #include <iostream> #include <string> using namespace std; // Place the function prototype below this line int main() int hour; int minute; int second; string ampm; // Place the function call statement below this line cout << hour<< ":"<< minute<< ":" << second << << ampm << endl; return 0; // Place the function definition below this line Page 7 of 11

20. (8 pts) Rewrite the value returning function definition below as a void function definition such that the caller of the void function still has access to the result that is being returned by FindSum. he void function will have three parameters float FindSum(float value, int num) float sum = 0.0; // holds sum of the values supplied for (int x = 0; x < num; x++) sum = sum + value; return sum; 21. (8 pts) What is the output for the following segment of code? Place one character per box and skip a box to indicate a space. int i = 0, j; do if (i > 2) break; cout << i << - ; for (j = 0; j < 8; j++) if ( j > 2) continue; cout << j; cout << - << j << endl; i++; while(i < 5); // output j 22. (8 pts) For the following code segment, write out what is printed to the screen. Show the displayed output precisely by using the following rules: Page 8 of 11

o Write one character per box. o Skip a box to indicate the presence of a blank space in the output. o Skip a row to indicate the presence of a blank line in the output. #include <iostream> using namespace std; void Sum(int); int main() Sum(1); Sum(2); Sum(3); Sum(4); return 0; void Sum(int add) static int sum = 0; static int j = 1; sum = sum + add; cout << j << << sum << endl; j++; Page 9 of 11

23. (12 pts) Write a void function definition that is described below: he name of the void function is OpenOutput. he function has one parameter an output file stream. he function is to: a) Prompt the user for the name of an output file and read it. b) Open the file. c) If the file did not open successfully, print out a message stating as such, reset the output stream variable (code to do this is outputfilestreamvariableused.clear();) d) Repeat steps a,b,c until a file is successfully opened or the user enters ctrl-c. Page 10 of 11

Extra Credit #1 (2 pts) Given the do-while loop below, write an equivalent for loop. int loop = 1; do cout<< loop is: << loop << endl; loop ++; while(loop < 15); Extra Credit #2 (4 pts) Write a void function definition that sums the number of positive integers(value is > 0) contained in an input file, and returns this sum and a count of the number of positive values to the caller of the function. his function requires three parameters one of the parameters is the input file stream (function assumes the file stream is open and valid and contains integers only with one integer per line). Page 11 of 11