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

Similar documents
True or False (12 Points)

True or False (15 Points)

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)

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)

True or False (14 Points)

Multiple Choice (Questions 1 13) 26 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 (15 Points)

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

Name Section: M/W T/TH Number Definition Matching (8 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.

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

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

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

Definition Matching (10 Points)

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

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

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

CSCE Practice Midterm. Data Types

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

Programming. C++ Basics

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

Functions, Arrays & Structs

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

Lecture 23: Pointer Arithmetic

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

CSCE Practice Midterm. Data Types


! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Test 2: CPS Owen Astrachan. November 17, Name: Honor code acknowledgement (signature)

Introduction to Programming

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

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

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

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

CMSC 202 Midterm Exam 1 Fall 2015

M1-R4: Programing and Problem Solving using C (JAN 2019)

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

Functions, Arrays & Structs

Objectives. In this chapter, you will:

Local and Global Variables

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

Integer Data Types. Data Type. Data Types. int, short int, long int

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Why Is Repetition Needed?

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Name. CPTR246 Spring '17 (100 total points) Exam 2

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Topics. Functions. Functions

Introduction to Programming EC-105. Lecture 2

EECS402 Lecture 02. Functions. Function Prototype

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

CS242 COMPUTER PROGRAMMING

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

LECTURE 02 INTRODUCTION TO C++

Fundamentals of Programming CS-110. Lecture 2

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

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.

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

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

Looping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html

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

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


Looping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Your first C++ program

BITG 1233: Introduction to C++

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

CSCE 110 PROGRAMMING FUNDAMENTALS

CMPS 221 Sample Final

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)

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

CSCE 110 PROGRAMMING FUNDAMENTALS

Computer Science II Lecture 1 Introduction and Background

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

CS 251 Practice Final Exam R. Brown May 1, 2015 SHOW YOUR WORK No work may mean no credit Point totals will be adjusted to a 120 point scale later

2. It is possible for a structure variable to be a member of another structure variable.

Functions that Return a Value. Approximate completion time Pre-lab Reading Assignment 20 min. 92

Pointers, Dynamic Data, and Reference Types

The University Of Michigan. EECS402 Lecture 02. Andrew M. Morgan. Savitch Ch. 3-4 Functions Value and Reference Parameters.

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

Input And Output of C++

Lab Instructor : Jean Lai

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

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

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

Short Notes of CS201

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

CSCE 110 PROGRAMMING FUNDAMENTALS

PIC 10A. Review for Midterm I

CS201 - Introduction to Programming Glossary By

CS 115 Exam 3, Spring 2010

CS 1428 Review. CS 2308 :: Spring 2016 Molly O Neil

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

Transcription:

Name Section: M/W or T/TH True or False (14 Points) 1. (14 pts) Circle T for true and F for false: T F a) In C++, a function definition should not be nested within another function definition. T F b) Static variables retain their value from function call to function call. T F c) The use of the statement: return; is valid in a value returning function. T F d) Arguments corresponding to value parameters can be literal values. T F e) value parameters receive a copy of an arguments value T F f) Arguments corresponding to reference parameters can be literal values. T F g) Members of a structure must have unique names T F h) Members of a structure must all be of the same DataType. T F i) The expression first.name could be used to access the name member of a structure variable first. T F j) Hierarchical structures are structures where at least one member is a structure T F k) All members in a Union can hold a valid value at the same time. T F l) Void functions must use return expression; to transfer control back to the caller of the function. T F m) The lifetime of a local variable is from the point of declaration to the end of the block in which it is declared. T F n) Local identifiers have name precedence over global identifiers. Page 1 of 11

Multiple choice (8 points) Questions 2 9 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) 4 B) 2 C) As many as necessary D) 1 E) 3 F) None of these 3. Which operations below ARE ALLOWABLE aggregate operations on structures? A) Return as a functions return value B) Arithmetic C) Input/Output D) Pass by value in a function call E) Assignment F) Comparison 4. A function that does not return a function value is known as what kind of function? A) Value returning function B) Reference Parameter C) Empty D) Void function E) Expression less F) None of these 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) A and C E) B and C F) None of these 6. What are the reference parameters in the following function heading? void DoSomething(string& date, int& num, float& average, float& sum, string& name) A) date B) num C) average D) sum E) name F) None of them 7. What are the value parameters in the following function heading? void DoSomething(string year, int value, float avg, float per, string city) A) year B) value C) avg D) per E) city F) None of them Page 2 of 11

8. The void function named GetNums has two parameters A pass-by-reference parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices is a valid function prototype given the description of the parameters for the function GetNums? A) void GetNums( float&, int ); B) void GetNums( float&, int& ); C) void GetNums( float, int ); D) void GetNums( float, int& ); E) none of the above 9. The void function named GetNums has two parameters A pass-by-reference parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices is a valid function heading given the description of the parameters for the function GetNums? A) void GetNums( float& x, int ) B) void GetNums( float&, int& num ) C) void GetNums( float& x, int num) D) A, B and C E) none of the above Short Answer (78 points) Questions 10 19 10. (4 pts) Write a structure declaration for a structure named Car containing the following members: - an integer variable representing the number of doors - a string variable representing the maker of the car - a string variable representing the model of the car - a string variable representing the color of the car Page 3 of 11

11. (10 pts) Consider the following structure declarations when answering the questions below. struct Date int day; int month; int year; ; struct Customer string item; string custname; Date purchdate; ; a) Write a statement that declares the identifier birthday as a variable of DataType Date. b) Write a cout statement that will output the value of the month member of the variable birthday. c) Write a statement that declares the identifier johndoe as a variable of DataType Customer. d) Write a statement that assigns a value of Coat to the item member of johndoe. e) Write a cout statement that will output the value of the year member of the purchdate member of johndoe. Page 4 of 11

12. (6 pts) Given the following constant and variable definitions/declarations. const string NAME = Ron ; int value; float sum; string city; void cube(int); // function prototype consider the following list of possible expressions for use as arguments in a function call: a) NAME b) value c) city d) sum e) 13 f) cube(value) g) Ron h) X A) List all expressions above that are valid for use as arguments with value parameters? B) List all expressions above that are valid for use as arguments with reference parameters? 13. (6 pts) There are three functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code. status = Average(sum); WriteInfo(outFile, Add(sum)); 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. Page 5 of 11

14. (6 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 result (contained in the variable sub) that is being returned by the value returning function. (Hint: need to add a reference parameter for the void function) string FindSub(string line, string name) string sub; sub = line.substr(line.find(name),line.size()); return sub; 15. (6 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 that is being returned by the void function. - Do not use any reference parameters with the value returning function. - Use two parameters only with the value returning function only void Calculate (float& num1, float num2, float num3) num3 = num2*num3; num1 = num2*num2 + num3; Page 6 of 11

16. (8 pts) When the program shown below is executed, what is the output to the screen? This 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 = 2; int main() int number = 4; function_b(number); cout << number in main is: << number << endl; return 0; void function_a(int& num) int number = 1; num = num - 2; cout << number in function A is: << number << endl; void function_b(int& sum) cout << sum in function B is: << sum << endl; function_a(sum); cout << number in function B is: << number << endl; sum = sum + 1; The 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). In The blank at the end of the line, put in the output value. number in main is: number in function A is: sum in function B is: number in function B is: Page 7 of 11

17. (12 pts) Write a void function definition that counts the number of non-empty lines in an input file. The number of non-empty lines contained in the input file is returned to the caller using a reference parameter. This function requires two parameters the input file stream and a line count. When an empty line is read with the getline function, the string variable holding the line read contains a null string (represented by ). The function assumes that the input file stream passed into the function is already open and associated with a file on the hard drive. Write the function definition only. This is not a complete program. Page 8 of 11

18. (12 pts) Finish the program below by adding a void function as specified below. Add only a function prototype, function call statement and function definition to the following program. The name of the void function is InitStruct. The function has one parameter of the struct DataType Date. The function is to initialize the structure parameter with a date of November 22, 2012. The information stored in the structure must be available in main() after the function call. #include <iostream> using namespace std; struct Date string month; int day; int year; ; // Place the function prototype below this line int main() Date turkey; // variable to hold the date of Thanksgiving // Place the function call statement below this line return 0; // Place the function definition below this line write the definition // This function initializes a structure variable // with the date November 22, 2012 Page 9 of 11

19. (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 Test(int); int main() Test(1); Test(2); Test(3); Test(2); Test(1); return 0; void Test(int value) static int j = 0; cout << j << - << value << endl; j = j + value; Page 10 of 11

Extra Credit (5 pts) For this problem show precisely the displayed output 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. What is the output for the following segment of code? All variables are integers for (int i = 0 ; i < 10; i++) if ( i > 4) continue; for (int j = i; j < 10; j++) cout << j; // output value of j if (j < 5) cout << A ; else break; // output of letter A cout << - << i << endl; // output a dash and value of i Page 11 of 11