True or False (12 Points)

Similar documents
True or False (15 Points)

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

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

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

True or False (15 Points)

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)

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

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

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

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

Definition Matching (10 Points)

CSCE Practice Midterm. Data Types

Name Section: M/W T/TH Number 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 (!

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

Functions, Arrays & Structs

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

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

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.

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

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

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

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

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

CS242 COMPUTER PROGRAMMING

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

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

EECS402 Lecture 02. Functions. Function Prototype

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

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

CSCE Practice Midterm. Data Types

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

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

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSCE 110 PROGRAMMING FUNDAMENTALS

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

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

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

Topics. Functions. Functions

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

Programming. C++ Basics

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

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

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

Lecture 23: Pointer Arithmetic

Functions, Arrays & Structs

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

CS 115 Midterm 2 Solutions

CMPS 221 Sample Final

WARM UP LESSONS BARE BASICS

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

BITG 1233: Introduction to C++

The C++ Language. Arizona State University 1

Introduction to Programming EC-105. Lecture 2

Use the template below and fill in the areas in Red to complete it.

Fundamentals of Programming CS-110. Lecture 2

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

Lab Instructor : Jean Lai

Chapter 1 INTRODUCTION

Exam 3 Chapters 7 & 9

Objectives. In this chapter, you will:

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Introduction to Programming


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

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

Summary of basic C++-commands

Functions. A function is a subprogram that performs a specific task. Functions you know: cout << Hi ; cin >> number;

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

Your first C++ program

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

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Homework #3 CS2255 Fall 2012

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

4. C++ functions. 1. Library Function 2. User-defined Function

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

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.

CSCE 110 PROGRAMMING FUNDAMENTALS

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

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:

Functions and Recursion

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

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

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

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:

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++

CSCI 102 Fall 2010 Exam #1

Scientific Computing

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

Constructor - example

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

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

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

A First Program - Greeting.cpp

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

Transcription:

Name True or False (12 Points) 1. (12 pts) Circle T for true and F for false: T F a) A void function call occurs as part of an expression. T F b) Value Returning Functions cannot have reference parameters. T F c) Void functions must have the statement return expression; Number T F d) Arguments corresponding to value parameters can be variables. T F e) Reference parameters receive a copy of an arguments value T F f) Arguments corresponding to value parameters must be variables T F g) The names of members in a structure must be unique for that structure T F h) Members of a structure can be of different DataTypes. T F i) The expression name.first could be used to access the first member of the structure variable name. T F j) The lifetime of a static variable is for the duration of the program T F k) Local identifiers have name precedence over global identifiers. T F l) Static variables in a function are initialized to their starting value every time the function is called. Page 1 of 11

Multiple choice (20 points) Questions 2 11 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. 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 4. Which operations below ARE ALLOWABLE aggregate operations on structures? A) Assignment B) Arithmetic C) Return value of a value returning function D) Input/Output E) Pass by reference in a function call F) Comparison 5. Which of the following can be used as a switch expression? A) integer variable B) string variable C) string constant D) floating point variable E) structure variable F) None of Them 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. Reference parameters (passing by reference) are used if a parameters data flow is: A) two-way, into and out of the function B) one-way, into the function C) one-way, out of the function D) None of these Page 2 of 11

8. 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 9. What are the value 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 10. The void function named GetNums has two parameters A pass-by-value parameter named x of type float A pass-by-value parameter named num of type int. Which of the following choices are correct function prototypes for the description of the parameters for the function GetNums? A) void GetNums( float&, int& ); B) void GetNums( float& x, int& num ); C) void GetNums( float, int num ); D) void GetNums(float, int); E) none of the above 11. 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&, int& ) B) void GetNums( float& x, int num ) C) void GetNums( float x, int& num) D) void GetNums(float, int) E) none of the above Page 3 of 11

Short Answer (68 points) Questions 12 21 12. (6 pts) Given the following definitions/declarations. const int SIZE = 10; int sum; float average; string name; void square(float); // function prototype consider the following list of expressions to be considered for arguments in a function call: a) average*float(sum) b) average c) B d) Word e) square(average) f) SIZE g) name h) sum A) List all expressions above that are valid for use as arguments with reference parameters? B) List all expressions above that are valid for use as arguments with value parameters? 13. (6 pts) There are four functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code and that the code compiles. 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)?. Page 4 of 11

14. (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 (contained in the function parameter sub) that is being returned by the void function. The value returning function is to have one less parameter than the void function. void FindSub(string& sub, string prompt) string line; cout << prompt; getline(cin, line, \n ); sub = line.substr(line.size()/2, line.size()); 15. (4 pts) Consider the following function definition: void Square( int& x) x = x * x; return x; Assuming an appropriate prototype has been included previously, will the function Square above compile correctly? (circle yes or no) Yes No If your answer was no, explain why it will not compile. Page 5 of 11

16. (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 buydate; ; a) Write a statement that declares the identifier payday as a variable of DataType Date. b) Write a output 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 DataType Purchase. d) Write a statement that assigns a value of Car to the name member of item. e) Write an output statement that will output the value of year of the buydate member of item. 17. (5 pts) Write the type declaration for a struct DataType 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 Time variable indicating the time of the appointment where Time is a structure already defined Page 6 of 11

18. (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 = 4; // global variable declaration of number int main() int number = 5; function_a(number); cout << number in main is: << number << endl; return 0; void function_a(int number) number = number - 2; cout << number in function A is: << number << endl; function_b(number); void function_b(int& sum) cout << number in function B is: << number << endl; sum = sum - 1; cout << sum in function B is: << sum << endl; 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). The 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 7 of 11

19. (8 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. Do not add any variable declarations. The name of the void function is InitStruct. The function has one parameter of the struct DataType Time. The function is to initialize the structure parameter with a time of 12:00:00 AM.(form is HH:MM:SS) The information stored in the parameter must be available in main() after the function call. #include <iostream> using namespace std; struct Time // format of the time is HH:MM:SS designator // where HH is for hours, MM for minutes and SS for seconds int hour; int minute; int second; string designator; // for AM or PM ; // Place the function prototype below this line int main() Time appt; // appt is a structure variable of data type Time // Place the initialization function call below this line return 0; // Place the function definition below this line Page 8 of 11

20. (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(4); return 0; void Test(int value) static int i = 0; static int j = 0; cout << i << - << j << endl; i = i + value; j++; Page 9 of 11

21. (12 pts) Write a void function that is described below: The name of the void function is OpenInput. The function has one parameter an input file stream. The function is to: a) Prompt the user for the name of an input 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 input stream variable (code to do this is infile.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 (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. The following program is executed. What is the output to the screen? #include <iostream> using namespace std; void Sum(int&, int ); int main() int num = 5, sum = -1 ; Sum(num,sum); cout << Num: << num << Sum: << sum << endl; return 0; void Sum(int& num, int sum) do sum=sum+num; cout << Sum: << sum << endl; num=num-1; while(num>=1); Page 11 of 11