CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

Similar documents
6. User Defined Functions I

Chapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

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

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

Objectives. In this chapter, you will:

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

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

Lab Instructor : Jean Lai

Objectives. Chapter 8 Arrays and Strings. Objectives (cont d.) Introduction 12/14/2014. In this chapter, you will:

Programming Language. Functions. Eng. Anis Nazer First Semester

Chapter 2 Basic Elements of C++

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

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

CSCE 110 PROGRAMMING FUNDAMENTALS

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

Introduction to Computer Science Midterm 3 Fall, Points

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc Introduction to Computing

BITG 1233: Introduction to C++

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

UEE1302 (1102) F10: Introduction to Computers and Programming

Engineering Problem Solving with C++, Etter/Ingber

CS201 Latest Solved MCQs

Chapter 7 - Notes User-Defined Functions II

Introduction to C++ Introduction to C++ 1

Pace University. Fundamental Concepts of CS121 1

Chapter 6 - Notes User-Defined Functions I

CSI33 Data Structures

CS242 COMPUTER PROGRAMMING

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

Computer Programming : C++

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

UNIT- 3 Introduction to C++

2 nd Week Lecture Notes

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

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

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

CS201 Some Important Definitions

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Technical Questions. Q 1) What are the key features in C programming language?

Lecture 3 The character, string data Types Files

Chapter 2: Introduction to C++

C++ PROGRAMMING SKILLS Part 4: Arrays

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

Using Free Functions

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Introduction to C++ Systems Programming

CS2255 HOMEWORK #1 Fall 2012

C++ Programming: Functions

Chapter 10 - Notes Applications of Arrays

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 6: One Dimensional Array

Review of the C Programming Language for Principles of Operating Systems

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

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6

PIC10B/1 Winter 2014 Exam I Study Guide

Exam 3 Chapters 7 & 9

Introduction to C Final Review Chapters 1-6 & 13

C++ Support Classes (Data and Variables)

1 Lexical Considerations

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

Arrays. Week 4. Assylbek Jumagaliyev

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS242 ARRAYS

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

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

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Introduction. What is function? Multiple functions form a larger program Modular programming

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

Chapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program)

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

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

C++ Programming Chapter 7 Pointers

C++ basics Getting started with, and Data Types.

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Chapter 3. Numeric Types, Expressions, and Output

Full file at

Lexical Considerations

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Arrays. Chapter 7 (Done right after 4 arrays and loops go together, especially for loops)

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Computer Programming C++ (wg) CCOs

CSC Web Programming. Introduction to JavaScript

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

BITG 1113: Array (Part 1) LECTURE 8

Getting started with C++ (Part 2)

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

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

Chapter Two MULTIPLE CHOICE

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

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Transcription:

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011 Date: 01/18/2011 (Due date: 01/20/2011) Name and ID (print): CHAPTER 6 USER-DEFINED FUNCTIONS I 1. The C++ function pow has parameters. A: zero B: one C: two D: three 2. To avoid compilation errors, function are typically placed before any function definition, including the definition of main. A: headers B: prototypes C: declarations D: bodies 3. A call to a value-returning function with an empty formal parameter list has the form. A: functionname B: void functionname C: functionname() D: functionname(void) 4. The code required to accomplish the task of a function is called the function. A: definition B: body C: header D: prototype 5. Which of the following functions has one parameter of type int? A: exp B: cos

C: fabs D: abs 6. To remove the first or last digit of an integer, you can use the operator. A: digit B: rem C: mod D: div 7. A(n) declaration is one in which a variable is declared inside a block to be used only within that block. A: actual B: limited C: function D: local 8. The statements of a function enclosed within curly braces form the of a function. A: body B: definition C: prototype D: header 9. Which of the following statements will output the character 'A'? A: cout << (toupper('a'); B: cout << toupper(a); C: cout << static_cast<char> (toupper('a')); D: cout << static_cast <string>(toupper('a')); 10. In the C++ function sqrt(x), x is called a of the function sqrt. A: value B: function C: return type D: parameter 11. The general syntax of a function prototype of a value-returning function is. A: functiontype functionname (parameter list); B: functiontype functionname (parameter list)

C: functiontype functionname (); D: functionname (parameter list); 12. Which of the following is true of the relationship between actual and formal parameters? A: The number of actual and formal parameters may differ. B: The data types of corresponding actual and formal parameters must match. C: Corresponding actual and formal parameters do not have to be listed in the same order. D: All of the above. 13. The function definition consists of the function. A: header and body B: header and prototype C: header D: prototype and body 14. The ceil function is defined in the header file. A: iostream B: cmath C: iomanip D: cstdlib 15. In what order does a compiler translate a program? A: It translates the program sequentially from beginning to end. B: It compiles all functions except main, and then compiles the main function. C: It compiles the main function first, then compiles the remaining functions in order. D: It compiles functions in the order that they are called in the main function. 16. Given the function header double larger(double x, double y), which of the following would be a valid function call to larger? A: larger(5, 6) B: larger() C: larger(double 5, double 6) D: double larger(double 5, double 6) 17. What is the syntax of a formal parameter list (brackets indicate optional elements)? A: datatype (identifier) [, datatype (identifier)...] B: datatype identifier [; datatype identifier...]

C: identifier (datatype) [, identifier (datatype)...] D: (datatype identifier) [, (datatype identifier)...] 18. functions are functions that have a return type. A: Value-returning B: Void C: Predefined D: Concrete 19. The C++ function calculates the largest whole number that is less than or equal to x. A: floor(x) B: ceil(x) C: abs(x) D: eqwhole(x) 20. Which of the following elements do NOT have to be included in a function prototype? A: The variable names of the parameters. B: The data types of the parameters. C: The return type of the function. D: The parentheses enclosing the parameter list (if the parameter list is empty). CHAPTER 7 USER-DEFINED FUNCTIONS II 1. The of an identifier refers to where in the program an identifier is accessible. A: function B: scope C: parameters D: reference 2. With the reserved word extern, a function can access a global variable. A: even when the global variable is declared after the function definition. B: only if the function has no local variables C: even if the function has an identifier with the same name D: only if it is declared directly before the function heading 3. If a function's name is overloaded, the determines which function to execute. A: actual parameter list

B: main function C: formal parameter list D: return type 4. The actual parameter list of a void function has the following syntax:. A: void variable [, variable...] B: datatype[&] variable [, datatype[&] variable...] C: (void) D: expression or variable [, expression or variable...] 5. When using a reference parameter, a constant value or an expression can only be passed to parameter. A: a nonconstant reference parameter B: a nonconstant value parameter C: a constant reference D: none of the above 6. A identifier is declared within a function or block. A: local B: global C: block D: default 7. To declare an external variable inside a function, you use the syntax. A: extern::identifier; B: extern identifier (datatype); C: extern datatype identifier; D: external datatype identifier; 8. C++ relaxes the rule of one-to-one correspondence between formal and actual parameters with the use of parameters. A: global B: reference C: actual D: default 9. The formal parameter list of a void function has the following syntax:.

A: void variable [, variable...] B: datatype[&] variable [, datatype[&] variable...] C: (void) D: expression or variable [, expression or variable...] 10. variables in a function have memory allocated in the function data area. A: External B: Reference C: Global D: Local 11. A identifier is declared outside any function definition. A: local B: global C: block D: default 12. Global variables should be used primarily for. A: value parameters B: named constants C: reference parameters D: all of the above 13. Default values for default parameters can be. A: constants B: global variables C: function calls D: all of the above 14. C++ functions that do not have a data type are called functions. A: void B: parameterized C: reference D: value-returning 15. A parameter receives a copy of the content of the corresponding actual parameter.

A: value B: static C: reference D: global 16. When using a reference parameter, the content of the formal parameter is. A: the address of the calling function B: the name of the actual parameter C: the address of the actual parameter D: the value of the actual parameter 17. Which of the following can be true for a global identifier to be accessible by a function or block? A: A local variable of the function has the same name as the global identifier. B: The function name is the same as the name of the global identifier. C: A parameter of the function has the same name as the global identifier. D: The global identifier is declared before the function definition. 18. A variable for which memory is allocated at block entry and deallocated at block exit is called a(n) variable. A: function B: global C: automatic D: static 19. Program execution always begins with the first statement in the. A: first void function B: function main C: program D: first function 20. A parameter receives the location of the corresponding actual parameter. A: value B: static C: reference D: global

CHAPTER 8 USER-DEFINED SIMPLE DATA TYPES, NAMESPACES, AND THE STRING TYPE 1. Many compiler vendors begin their global identifier names with a(n). A: pound sign B: underscore C: ampersand D: asterisk 2. The length function. A: specifies the maximum possible length of a string B: returns the number of characters currently in the string C: returns the maximum number of characters the string can hold D: returns the length of the longest word in the string 3. Which of the following is a valid enumeration type definition? A: enum grades {'A', 'B', 'C', 'D', 'E'}; B: enum colors {BROWN, BLUE, RED, GREEN}; C: enum rank {1ST, 2ND, 3RD, 4TH}; D: enum array {[0], [1], [2], [3]}; 4. The mechanism helps solve the problem of overlapping global identifier names. A: include B: enum C: namespace D: typedef 5. The syntax of the length function is. A: strvar.length B: strvar (length) C: strvar.length() D: strvar.length (numchars) 6. The syntax for declaring variables of an enumeration type is. A: enum identifier, identifier... ; B: datatype identifier, identifier... ; C: enum datatype, datatype... ;

D: datatype enum; 7. Which of the following can be a namespace member? A: named constant B: variable declaration C: another namespace D: All of the above 8. The length function returns a value of type. A: signed long B: string::int_type C: string::size_type D: char 9. Which of the following operators can be used with enumeration types? A: = B: + C: * D: All of the above 10. The scope of a namespace is. A: global to the C++ library B: undefined C: local to the namespace D: global to all namespaces in the same directory 11. The find function returns a value of type. A: signed long B: string::int_type C: string::size_type D: char 12. Which of the following operators can be used with enumeration types? A: / B: ++ C: <=

D: All of the above 13. The general syntax for accessing a namespace member is. A: identifier::namespace::name B: namespace_name.identifier C: namespace_name (identifier) D: namespace_name::identifier 14. The function returns the same value as the length function. A: min B: substr C: max D: size 15. The enumeration type is a(n) type. A: Boolean B: character C: string D: integral 16. You can simplify the accessing of namespace members with the statement. A: using B: include C: typedef D: define 17. The function searches a string to find the first occurrence of a particular substring. A: swap B: length C: substr D: find 18. You can use the operator to increment or decrement the value of an enumeration type. A: scope resolution B: stream C: cast

D: assignment 19. A using statement is typically placed. A: in the function in which the namespace members are used B: with the variable declarations in main C: directly before the namespace declaration D: directly after the namespace declaration 20. Which of the following functions has two forms? A: size B: find C: substr D: swap CHAPTER 9 ARRAYS AND STRINGS 1. The of an array is the address of the first array component. A: formal parameter B: subscript C: base address D: index location 2. C++ does not allow. A: arrays to be copied B: component-wise operations on an array C: aggregate operations on an array D: any of the above 3. A array is a collection of a fixed number of components arranged in rows and columns, wherein all components are of the same data type. A: parallel B: two-dimensional C: tabular D: composite 4. You typically step through the elements of an array using a(n). A: switch statement

B: named constant C: additional array D: loop 5. C-strings are. A: enclosed in single quotation marks B: enclosed in double quotation marks C: not enclosed in quotes D: are stored in computer memory without a null termination character 6. The of an array specifies the position of a component in an array. A: index value B: data type C: element value D: dimension 7. The last character in a C-string is always. A: the last element of the input string B: the null character C: the integer zero D: the newline character 8. An array is a data type. A: structured B: simple C: constant D: primitive 9. Given an array mylist, what is the result of the statement cout << mylist? A: The compiler generates an error. B: The base address of mylist is output. C: The value of the first element in mylist is output. D: All of the values of mylist are output. 10. A(n) operation on an array is any operation that manipulates the array as an entire unit. A: aggregate

B: component C: legal D: composite 11. In the declaration of a two-dimensional array, the value inside the second set of brackets indicates. A: the base address of the array B: the size of the array C: the number of columns in the array D: the number of rows in the array 12. Which of the following will input data into a ten element array named sales? A: for (index = 0; index < 10; index++) cin > > sales[index]; B: cin > > sales; C: for (index = 0; index <= 10; index++) cin > > sales[index]; D: cin > > index; 13. Which of the following aggregate operations can be performed on C-strings? A: comparison B: assignment C: input/output D: none of the above 14. The value inside the brackets of an array declaration specifies the. A: maximum value that can be held by any item in the array B: value of the first element of the array C: number of components in the array D: the number of bytes set aside in memory for the array 15. A C-string can contain any of the following characters anywhere within the string except the character. A: blank B: null C: backslash D: concatenation operator 16. Which of the following is true of an array?

A: Each element can be of a different data type. B: The number of elements can be modified at any time. C: It is not part of the C++ language. D: It can have one or more dimensions. 17. When you pass an array as a parameter, the of the actual array is/are passed to the formal parameter. A: exact size B: number of elements C: first element D: base address 18. In C++, arrays. A: cannot be passed to a function B: can be passed by reference or by value C: are passed by value only D: are passed by reference only 19. A(n) is typically used to process an entire two-dimensional array. A: additional array B: a nested switch structure C: single loop D: nested for loop 20. The index of an array is in bounds if. A: index > = 0 and index < = ARRAY_SIZE B: index > = 0 and index < = ARRAY_SIZE + 1 C: index = 0 or index < = ARRAY_SIZE D: index > = 0 and index < = ARRAY_SIZE - 1 CHAPTER 10 APPLICATIONS OF ARRAYS AND THE VECTOR TYPE 1. For a list of length n, on average, the insertion sort makes about item assignments. A: n (n - 1) / 2 B: + 3n - 4 / 4 C: n - 1 / 2

D: n (n - 1) / 4 2. A binary search can be performed. A: on sorted or unsorted lists B: only on sorted lists C: only on unsorted lists D: on sorted or partially sorted lists 3. The binary search function presented in this chapter returns to indicate an unsuccessful search. A: -1 B: 0 C: 1 D: false 4. The statement creates a vector object named veclist without any elements. A: vector<elemtype> veclist; B: vectorveclist; C: veclist; D: vector veclist(elemtype); 5. The function size(). A: initializes a vector object to hold zero elements B: returns the maximum number of elements that can be inserted into a vector object C: initializes a vector object to hold a specified number of elements D: returns the number of elements currently held in a vector object 6. The array you use to store a list should be declared with the size of the list. A: minimum B: maximum C: exact D: initial 7. A(n) search sequentially searches an array starting with the first component, and continues until the item is found or when no more data is left in the list. A: linear B: binary

C: random D: elemental 8. On average, the number of key comparisons made by a sequential search is equal to. A: half the size of the list B: the size of the list C: the number of unique elements in the list D: the size of the array containing the list 9. The temp variable used in the "swap" code for the bubble sort in this chapter is used to hold the. A: index value of the element to be swapped B: element with the larger value in the swap C: element with the smaller value in the swap D: return value of the function 10. For a list of length n, on average, the selection sort makes key comparisons. A: n (n - 1) / 2 B: n (n -1) / 4 C: n - 1 / 2 D: n / 4 11. Which of the following sorts, on average, makes the least number of key comparisons? A: bubble B: selection C: insertion D: binary 12. A binary search uses a technique to search the list. A: linear B: sequential C: divide and conquer D: search and remove 13. The binary search function presented in this chapter returns to indicate a successful search. A: the integer 0 B: the value of the element

C: the location of the item D: a true value 14. The statement creates a vector object, veclist, with size elements and initialized with default values. A: vector veclist(size); B: vector veclist(size, value); C: vector veclist(value); D: vectorvec<elemtype> List(size); 15. The function can be used to increase the size of a vector object. A: resize() B: size() C: push() D: max_size() 16. To search a list, you need. A: the data structure containing the list B: the length of the list C: the item for which you are searching D: all of the above 17. A sequential search function. A: requires a Boolean variable to exit the search loop B: must return a Boolean value indicating success or failure C: may be implemented with or without a Boolean variable to exit the search loop D: must include the return value inside the search loop 18. The sequential search algorithm. A: assumes that the list is sorted B: does not assume the list is sorted C: always sorts the list before searching D: cannot be performed on a sorted list 19. The code to perform a "swap" for the sorts presented in this chapter requires assignment statements. A: one

B: two C: three D: four 20. For a list of length n, on average, the selection sort makes item assignments. A: n (n - 1) / 2 B: n (n - 1) / 4 C: n - 1 / 2 D: 3 (n - 1)