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

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

Homework #3 CS2255 Fall 2012

CS2255 HOMEWORK #1 Fall 2012

Exam 3 Chapters 7 & 9

CS 161 Exam II Winter 2018 FORM 1

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

CSC 1300 Exam 4 Comprehensive-ish and Structs

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

CS201- Introduction to Programming Current Quizzes

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

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

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)

Introduction to Computer Science Midterm 3 Fall, Points

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

CSCE 206: Structured Programming in C++

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

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

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

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

Algorithms & Data Structures

COMPUTER APPLICATION

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

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

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

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

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

Variables, Memory and Pointers

CS 115 Exam 3, Spring 2010

Introduction to Programming Using Java (98-388)

Procedural programming with C

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

True or False (15 Points)

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

CSc Introduction to Computing

Pointers, Dynamic Data, and Reference Types

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

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Input And Output of C++

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

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.

CS111: PROGRAMMING LANGUAGE II

CSCE 2014 Final Exam Spring Version A

For example, let s say we define an array of char of size six:

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

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

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

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

First Name: Last: ID# 1. Hexadecimal uses the symbols 1, 2, 3, 4, 5, 6, 7 8, 9, A, B, C, D, E, F,G.

APSC 160 Review Part 2

CHAPTER 4 FUNCTIONS. 4.1 Introduction

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

7.1. Chapter 7: Arrays Hold Multiple Values. Array - Memory Layout. A single variable can only hold one value. Declared using [] operator:

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

CSI33 Data Structures

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:

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

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

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

C++ Final Exam 2017/2018

Pointer Data Type and Pointer Variables

CS201 Latest Solved MCQs

CSCE Practice Midterm. Data Types

! The address operator (&) returns the address of a. ! Pointer: a variable that stores the address of another

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

NOTE: Answer ANY FOUR of the following 6 sections:

Pace University. Fundamental Concepts of CS121 1

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Implementing Subprograms

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

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

EECS402 Lecture 02. Functions. Function Prototype

Functions. Arizona State University 1

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

Chapter 9: Pointers Co C pyr py igh i t gh Pear ea so s n n E ducat ca io i n, n Inc. n c.

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. Introduction :

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

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

CS302: Self Check Quiz 2

Linked Memory. Pointers Linked Lists. September 21, 2017 Cinda Heeren / Geoffrey Tien 1

1) You want to determine whether time has run out. The following code correctly implements this:

! A pointer variable (or pointer): ! An asterisk is used to define a pointer variable. ! ptr is a pointer to an int or

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

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

Introduction to C Language (M3-R )

Chapter 2: Using Data

Arrays. Arizona State University 1

Linked Memory. Pointers Linked Lists. January 19, 2018 Cinda Heeren / Geoffrey Tien 1

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

Fundamentals of Programming Session 13

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++


CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

Transcription:

CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function can have local variables. 3. Each recursion causes a new frame to be placed on the stack. 4. When you pass an array as an argument to a function, the function can modify the contents of the array. 5. To assign the entire contents of one array to another, you can use the assignment operator. 6. The amount of memory used by an array depends solely on the number of elements the array can hold. 7. If a C++ program contains the following array definition int score[10]; the following statement would store 100 in the first array element: score[1] = 100; 8. To declare a C-string, you should use the type expression string *. 9. Memory cannot be allocated after a program is already running. 10. A static array name is a pointer constant because the address it represents cannot be changed during run-time. 11. A one-dimensional array can only store elements of a single data type, but a two-dimensional array can hold data of two different data types. 12. An element of a two-dimensional array is referenced to by the array name and two subscripts, first the element row number and then the element column number. 13. If a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached. 14. It is possible for a function to have some parameters with default arguments and some without.

Multiple Choice (3 pts each) 15. An array of characters ending with the null terminator is called a. a C++ String. b. a string class object. c. a C-string. d. a string literal. 16. Given the following function definition void calc (int a, int& b) int c; c = a + 2; a = a * 3; b = c + a; What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; calc(x, y); cout << x << " " << y << endl; a. 1 2 b. 1 6 c. 3 6 d. 1 14 e. None of these 17. Assuming that arr is an array identifier, the statement sum += *arr; a. will always result in a compiler error. b. adds the value stored in arr[0] to sum. c. is illegal in C++. d. adds the address of the pointer arr to sum. 18. The delete operator should only be used on pointers that a. point to storage allocated by the new operator. b. have not yet been used. c. have been correctly initialized. d. are appropriately dereferenced.

19. Which of the following statements is not valid C++ code? a. float num1 = &ptr2; b. int ptr = &num1; c. int ptr = int *num1; d. All of the above are valid. e. All of the above are invalid. 20. A recursive function that does not correctly handle its base case may a. cause a continuous chain of recursive calls. b. return FALSE and stop. c. reach the NULL terminator and stop. d. return 0 and stop. 21. When an array is passed to a function, it is actually the array that is passed. a. the data type and size of b. the value stored in the first element of c. the starting memory address of d. the data type and name of e. a copy of all the values in 22. The null terminator stands for the ASCII code a. 100. b. 1000. c. 57. d. 0. 23. The function int fact(int k) return k*fact(k-1); if (k==0) return 1; a. does not correctly handle its base case. b. computes the factorial on an integer k passed to it as parameter. c. returns the value 1 if it is passed a value of 0 for the parameter k. d. works for all non-negative values of k, but not for negative numbers. 24. If you leave out the size declarator in an array declaration a. you must furnish an initialization list. b. the value of each array element is set to a default value of 0. c. the array size defaults to 100 elements. d. the array will contain no elements. e. the array cannot be created

25. The, also known as the address operator, returns the memory address of a variable. a. exclamation point (! ) b. asterisk ( * ) c. percent sign (%) d. ampersand ( & ) 26. The statement double *num; a. initializes a variable called *num. b. defines a variable of type double called num. c. defines and initializes a pointer variable called num. d. defines a pointer variable called num. 27. The statement causes a function to end and the flow of control to move back to the point where the function call was made. a. exit b. end c. return d. break e. continue 28. What will the following code output? int number = 22; int *var = &number; cout << var << endl; a. The address of the number variable b. 22 c. An asterisk followed by 22 d. An asterisk followed by the address of the number variable 29. Unlike regular variables, arrays can hold multiple a. values. b. named constants. c. variables. d. data types. e. operators. 30. A function can have zero to many parameters, and it can have return value(s). a. a maximum of ten b. no c. either zero or one d. either one or two e. zero to many

31. In a function prototype, in addition to the name of the function, you are required to furnish a. the data type of the return value. b. an identifier name for each parameter. c. a data type for each parameter. d. all of the above. e. A and C, but not B. 32. A variable is defined inside the body of a function and is not accessible outside that function. a. global b. counter c. local d. reference e. constant 33. When a function just needs to use a copy of an argument passed to it, the argument should normally be passed a. as a default argument. b. by variable. c. by value. d. as a string. e. by reference. 34. When used as a parameter, a variable allows a function to access and modify the original argument passed to it. a. default value b. value c. static d. reference e. floating-point 35. When more than one function has the same name they are called functions. a. sister b. overloaded c. renamed d. parallel e. identical 36. Which of the following statements correctly deletes a dynamically-allocated array pointed to by p? a. delete p; b. delete array p; c. delete [ ] p; d. p delete[ ];

37. If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to a. arr + k. b. arr + *k. c. *(arr + k). d. &arr[k]. 38. What would be the result of the call dotask (5, 4), given the following definition? int dotask (int a, int b) if (a <= 2) return 5; else return dotask(a-1, b-1) + a + b; a. 5 b. 10 c. 17 d. 26 Extra Credit (2 pts each): 39. An array called alist contains integers 5, 3, 7, 2, 8. What are the contents of alist after the function call workonarray (alist, 4), if and the definition of workonarray is: int workonarray (int a[], int n) if (n == 1) return a[0] + 3; else a[n] = workonarray (a, n-1); return 7; a. 5, 3, 8, 8, 8 b. 5, 6, 10, 5, 11 c. 5, 3, 8, 7, 7 d. 8, 6, 10, 5, 11

40. The statement int grades[ ] = 100, 90, 99, 80 ; is an example of a. default arguments. b. implicit array sizing. c. data encapsulation. d. an illegal array declaration. e. an illegal array initialization. 41. The expression strcmp("ab", "ab") returns a. the value equivalent to false. b. a non-zero positive integer c. a negative integer. d. the boolean value true. 42. The of recursion is the number of times a recursive function calls itself. a. depth b. level c. type d. breadth 43. True (A) / False (B): C++ arrays check for out-of-range index values.