Chapter 4 Computer Science with C++ Name: Review Worksheet A Mr. Ferwerda

Similar documents
Programming Language. Functions. Eng. Anis Nazer First Semester

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

6. C++ Subprograms David Keil CS I slides 7/03 1

BITG 1113: Function (Part 2) LECTURE 5

Honors Computer Science C++ Mr. Clausen Program 6A, 6B, 6C, & 6G

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Outline. Functions. Functions. Predefined Functions. Example. Example. Predefined functions User-defined functions Actual parameters Formal parameters

Lab # 02. Basic Elements of C++ _ Part1

Chapter 6: Functions

Understanding main() function Input/Output Streams

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Input And Output of C++

LECTURE 02 INTRODUCTION TO C++

Pointers, Dynamic Data, and Reference Types

WARM UP LESSONS BARE BASICS

LECTURE 06 FUNCTIONS

Memory and Pointers written by Cathy Saxton

Chapter 7 User-Defined Methods. Chapter Objectives

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Boolean Algebra Boolean Algebra

Test Bank for Problem Solving with C++: The Object of Programming, 8/e Chapter 2 C++ Basics

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

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

Probably the best way to start learning a programming language is with a program. So here is our first program:

Exceptions, Case Study-Exception handling in C++.

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

Chapter 7 - Notes User-Defined Functions II

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

Learning Objectives. Introduction to Arrays. Arrays in Functions. Programming with Arrays. Multidimensional Arrays

Chapter 4: Subprograms Functions for Problem Solving. Mr. Dave Clausen La Cañada High School

Chapter 3 Function Overloading

Variables, Memory and Pointers

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

Computer Programming : C++

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

Binding and Variables

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]

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

Arrays 2 CS 16: Solving Problems with Computers I Lecture #12

Objectives. In this chapter, you will:

CS Spring 05 - MidTerm

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

CHAPTER 3 BASIC INSTRUCTION OF C++

EECS402 Lecture 02. Functions. Function Prototype

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

Chapter 1: Object-Oriented Programming Using C++

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

6.096 Introduction to C++

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

Chapter 3 - Functions

Introduction to Programming. Lecture 6: Functions & Program Structure

CS 115 Exam 2, Fall 2009

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

What Is a Function? Illustration of Program Flow

University of Toronto

Separate Compilation Model

The C++ Language. Arizona State University 1

Topics. Functions. Functions

6.096 Introduction to C++ January (IAP) 2009

What we will learn about this week: Declaring and referencing arrays. arrays as function arguments. Arrays

Do not start the test until instructed to do so!

Function with default arguments

2. [20] Suppose we start declaring a Rectangle class as follows:

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

Programming. C++ Basics

Introduction to C++ (Extensions to C)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Functions, Pointers, and the Basics of C++ Classes

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

CS536 Spring 2011 FINAL ID: Page 2 of 11

Chapter 6 - Notes User-Defined Functions I

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

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

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

CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

DELHI PUBLIC SCHOOL TAPI

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

C++ Programming: Functions

CS349/SE382 A1 C Programming Tutorial

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

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.

CSI33 Data Structures

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

Constants, References

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

Advanced Computer Programming

Topics: Material through example 19 (types, operators, expressions, functions, selection, loops, arrays)

C++ Quick Guide. Advertisements

Pointers. Developed By Ms. K.M.Sanghavi

Functions and Recursion

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

Chapter 1 INTRODUCTION

C++ for Java Programmers

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

Transcription:

Chapter 4 Computer Science with C++ Name: Review Worksheet A Mr. Ferwerda Answer the following: 1. The? parameters appear in a function call. 2. The? parameters appear in a function declaration. 3. Formal parameters that are reference parameters must have actual parameters that are?. 4. Formal parameters that are reference parameters must have actual parameters that are of the? data type. 5. Formal parameters that are value parameters must have actual parameters that are?. 6.? parameters make local copies of the actual parameters, and therefore protect the actual parameters from unwanted changes. 7.? parameters make create aliases for the actual parameters, and therefore any changes made to them change the values of the actual parameters. 8.? parameters make create aliases for the actual parameters, but the compiler will not allow any changes to be made to the actual parameters. 9. Which is used to test a function, a driver or a stub? 10. Which type of testing is the process given in the previous problem, top-down testing or bottom-up testing? 11. Which is used to test main program flow, a driver or a stub? 12. Which type of testing is the process given in the previous problem, top-down testing or bottom-up testing? 13. Variables declared within a function are said to be? variables. 14. Variables that can be used anywhere in the main function or in any functions are called? variables. 15. Where are global identifiers declared in a program? 16. A(n)? occurs when a function makes an unwanted change in a global variable. 17. The? of an identifier refers to the largest block in which the identifier is visible (i.e. when it can be referenced). 18. When a problem is broken into smaller subproblems, the process is called?.

Computer Science with C++ - Chapter 4 Review Worksheet A: page 2 19. Local variables cannot be referenced outside of the function in which they are declared. (True / False ) 20. The use of local variables and formal parameters enhances the portability of a function. (True / False ) 21. A function that does not return a value using a return statement is called a? function. 22. A void function never has any parameters. (True / False ) 23. Name the four parts of any function declaration 24. Function declarations should be located? (before / after) the main function in a program. 25. Function implementations should be located? (before / after) the main function in a program. 26. A local variable in a function can have the same name as a program global variable. (True / False ) 27. The facts that a function can assume to be true on entry are called the?. 28. The conditions that must be true after a function's execution are called the?., 29. When doing software engineering with teams, it is more important that the teams know? another team is doing instead of? they are doing it. 30. List all of the data types can be returned as the value of a user-defined function. i. int iii. char v. functions don't return ii. double iv. apstring values of any type 31. A constant declared within a function is global to the entire program. (True /False ) 32. Name the two parts of a programmer-defined library, and give the customary extension given to each. 33. Name the three preprocessor directives that must occur in the library header file.

Computer Science with C++ - Chapter 4 Review Worksheet A: page 3 In 34-41, indicate whether the statement is a VALID or INVALID function declaration; if invalid, explain why: 34. int example ( double x ); 35. int example; 36. int example ( ); 37. void example ( int &a ); 38. double example ( x ); 39. char example ( int a, double &b ); 40. void example ( char a, b ); 41. apstring example ( double &a, double &b, int c ); In problems 42-50, use the following declarations made in the program to indicate whether the function call is a VALID or INVALID if made in the main function; if invalid, explain why: void sample ( int a, double &b, char c ); double r; int j; char c; 42. sample ( j, r, c ); 43. sample; 44. sample ( j, &r, c ); 45. sample ( a, b, c ); 46. sample ( c, j, r ); 47. sample ( 3, 5.0, 'X' ); 48. sample ( 3, r, 'X' ); 49. sample ( j * 3, r - 7, c ); 50. sample ( j, r );

Computer Science with C++ - Chapter 4 Review Worksheet A: page 4 In questions 51-60, use the program skeleton below to answer TRUE or FALSE; if false, explain why: #include <iostream.h> int x, y, z; void one ( int q, int r ); void two ( int t ); void three ( int &r ); void four ( int t ); void one ( int q, int r ) int v; void two ( int t ) void three ( int &r ) int x; void four ( int t ) int z; 51. q is local to one and global to two and three. 52. Global variable y can be accessed by all parts of the program. 53. t can be accessed by one. 54. r can be accessed by two. 55. z is a global variable that is visible to, and can be accessed by, all parts of the program. 56. The statement q = r * x; would be legal if it appeared in the body of three. 57. The statement y = r * x; would be legal if it appeared in the body of three. 58. r is the only reference parameter in the program. 59. three could be called in two. 60. two could be called in four.

Computer Science with C++ - Chapter 4 Review Worksheet A: page 5 In problems 61-65, write function declarations (without the supporting documentation) for the following: 61. Write a function declaration for a function displayinstructions that is passed nothing and returns nothing 62. Write a function declaration for a function getreal that has no parameters and returns a real (double) number. 63. Write a function declaration for a function getstuff that is passed two characters ch1 and ch2, and returns a real number (not through the parameter list). 64. Write a function declaration for a function newvalue that is passed one real number number1 and returns a real number number1 (through the parameter list). 65. Write a function declaration for a function funny that is passed two real numbers v1 and v2, and returns two integer numbers n1 and n2. In 66-68, write the exact output given by the following programs: 66. #include <iostream.h> Output double dostuff ( int p, int q ); int x, y; double a, b; x = 4; y = 7; cout << x = << x << a = dostuff ( x, y ); b = dostuff ( y, x ); cout << a = << a << y = << y << endl; b = << b << endl; double dostuff ( int p, int q ) return ( p 10 ) * q;

Computer Science with C++ - Chapter 4 Review Worksheet A: page 6 67. #include <iostream.h> Output void mixup ( int a, int &b, int &c ); int x, y, z; x = 30; y = 40; z = 50; mixup ( x, y, z ); x = 30; y = 40; z = 50; mixup ( z, y, x ); x = 30; y = 40; z = 50; mixup ( x, x, z ); void mixup ( int a, int &b, int &c ) a = a + 100; b = b + 60; c = c + 70; cout << a << << b << << c << endl; 68. #include <iostream.h> Output void unusual ( int &who, int what ); int who, where; who = 8; where = 2; cout << who << << where << endl; unusual ( who, where ); cout << who << << where << endl; unusual ( where, who ); cout << who << << where << endl; void unusual ( int &who, int what ) who = 5 * what; what = 10 - who; cout << who << << what << endl;

Computer Science with C++ - Chapter 4 Review Worksheet A: page 7 Program Coding: in 69-71, write code for the problem: 69. Write a syntactically correct library header file for a library called geometry.h. Include in the file the declaration for 2 functions called rectarea and rectperimeter. Each function will take two real parameters (length and width) and return, respectively, the area and perimeter of the rectangle with the given length and width. Don t forget to include the necessary preprocessor directives! Be sure to use proper documentation, including all supporting documentation that normally goes with a function declaration. 70. Write the library implementation file that corresponds to the header file described in the previous problem. Only put in the #include statements that are absolutely necessary for the implementation of the functions. 71. On the back of this sheet, write a simple driver program that tests the corresponding library files described in the previous two problems. Only put in the #include statements that are absolutely necessary for the implementation of the functions.