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

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

True or False (12 Points)

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

True or False (15 Points)

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)

Multiple Choice (Questions 1 14) 28 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 (!

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?

C++ Final Exam 2017/2018

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

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

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

Definition Matching (10 Points)


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

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

CMPS 221 Sample Final

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

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

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

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

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)

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

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

REPETITION CONTROL STRUCTURE LOGO

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

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

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

CSCE 206: Structured Programming in C++

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

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

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

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

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

Introduction to Programming

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

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

Exam 3 Chapters 7 & 9

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

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

Functions, Arrays & Structs

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

A SHORT COURSE ON C++

DELHI PUBLIC SCHOOL TAPI

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

CSCE Practice Midterm. Data Types

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

C++ Programming for Non-C Programmers. Supplement

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

WARM UP LESSONS BARE BASICS

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

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

CSCE Practice Midterm. Data Types

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

Programming. C++ Basics

Chapter 5: Loops and Files

Looping. Arizona State University 1

CS2255 HOMEWORK #1 Fall 2012

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

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

1 Unit 8 'for' Loops

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

CPT101- Principles of Programming

Input And Output of C++

C++ Programming for Non-C Programmers. Supplement

Introduction to Programming EC-105. Lecture 2

In this chapter you will learn:

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Fundamentals of Programming CS-110. Lecture 2

Homework #3 CS2255 Fall 2012

Scientific Computing

CSCE 110 PROGRAMMING FUNDAMENTALS

Chapter 3 Problem Solving and the Computer

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

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

Local and Global Variables

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

Topics. Functions. Functions

Spring 2002 Page 1 of 8 READ THIS NOW!

Increment and the While. Class 15

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

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

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

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

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

Transcription:

Name SECION: 12:45 2:20 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 value 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; F h) Member names within a structure must be unique. F i) A structure variable contains information for one of its members 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) A default statement is optional in a switch statement. 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 value-returning function have? 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) Input/Output B) Assignment 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, into the function. he data flow for beta is one-way, 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- value parameter named num of type float. A pass-by- reference 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-reference 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 a particular event occurs is called????. A) A loop control 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. (8 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. Compute(inFile, MyCalc()); Average(SumUp(num), 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 2-5 6 7 8 9, 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) break; 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 = 4; // global variable declaration of number int main() int number = 5; cout << number in main is: << number << endl; function_b(number); return 0; void function_a(int& number) number = number - 2; cout << number in function A is: << number << endl; void function_b(int& sum) cout << number in function B is: << number << endl; function_a(sum); sum = sum - 1; 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 Date int day; int month; int year; ; struct Purchase string name; Date purchasedate; ; a) Write a statement that declares the identifier payday as a variable of Dataype Date. b) Write a cout statement that will output the value of month of the variable payday. c) Write a statement that declares the identifier item as a variable of Dataype Purchase. d) Write a statement that assigns a value of Car to the name member of item. e) Write a cout statement that will output the value of year of the purchasedate member of item. 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 already defined - A ime variable indicating the time of the appointment where ime is a structure already defined 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 InitDate. he function has three parameters(2 integers and a string) for the day month and year of a date. he function is to initialize the parameters so that they contain information for January 1, 1999. he information stored in the parameters must be available in main() after the function call. #include <iostream> using namespace std; // Place the function prototype below this line int main() int day; string month; int year; // Place the function call statement below this line cout << month << " " << day << ", " << year << endl; return 0; // Place the function definition below this line Page 7 of 11

20. (8 pts) Rewrite the void function definition below as a value returning function definition such that the caller of the function still has access to the result (contained in the function parameter sum) that is being returned by the void function - Use two value parameters only with the value-returning function. void FindSum(float& sum, float value, int num) sum = 0.0; for (int x = 0; x < num; x++) sum = sum + value; 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. for (int i = 0 ; i < 5; i++) if (i > 2) continue; cout << - << i; for (int j = 0; j < 5; j++) if ( j > 2) break; cout << - << j; cout << endl; Page 8 of 11

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: 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 Sub(int); int main() Sub(1); Sub(2); Sub(3); Sub(4); return 0; void Sub(int sub) static int i = 10; static int j = 0; cout << i << << j << endl; j++; i = i - sub; Page 9 of 11

23. (10 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 for loop below, write an equivalent do-while loop. for(int loop = 10; loop >= 0; loop--) cout<< loop is: << loop << endl; Extra Credit #2 (4 pts) Write a value returning function definition that counts the number of times the word Hello appears in an input file, and returns this count to the caller of the function. his function requires a single parameter the input file stream (function assumes the file stream is open). Page 11 of 11