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

Similar documents
Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

An Incomplete C++ Primer. University of Wyoming MA 5310

C++FA 5.1 PRACTICE MID-TERM EXAM

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Passing 1D arrays to functions.

Answers to Review Questions Chapter 7

The C Programming Language course syllabus associate level

5 Arrays and Pointers

arrays C Programming Language - Arrays

Stacks. Linear data structures

Chapter 13 Storage classes

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

Chapter 5 Names, Bindings, Type Checking, and Scopes

Sources: On the Web: Slides will be available on:

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Arrays in Java. Working with Arrays

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Object Oriented Software Design II

Introduction to Java

13 Classes & Objects with Constructors/Destructors

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

One Dimension Array: Declaring a fixed-array, if array-name is the name of an array

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

El Dorado Union High School District Educational Services

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Comp151. Definitions & Declarations

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

C Interview Questions

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Introduction to Object-Oriented Programming

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

DATA STRUCTURES USING C

J a v a Quiz (Unit 3, Test 0 Practice)

Chapter 5 Functions. Introducing Functions

Chapter 5. Recursion. Data Structures and Algorithms in Java

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Introduction to Java. CS 3: Computer Programming in Java

Two-Dimensional Arrays Summer 2010 Margaret Reid-Miller

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Basics of I/O Streams and File I/O

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

Lecture 11 Array of Linked Lists

Introduction to Data Structures

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

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

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Data Structures using OOP C++ Lecture 1

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=

Project 2: Bejeweled

Java Interview Questions and Answers

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Illustration 1: Diagram of program function and data flow

Tutorial on C Language Programming

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

C++ INTERVIEW QUESTIONS

AP Computer Science Java Mr. Clausen Program 9A, 9B

CS 111 Classes I 1. Software Organization View to this point:

Compiler Construction

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

Curriculum Map. Discipline: Computer Science Course: C++

AP Computer Science Java Subset

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Parallel and Distributed Computing Programming Assignment 1

MISRA-C:2012 Standards Model Summary for C / C++

Moving from CS 61A Scheme to CS 61B Java

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

PIC 10A. Lecture 7: Graphics II and intro to the if statement

CMSC 202H. ArrayList, Multidimensional Arrays

Glossary of Object Oriented Terms

Chapter 7: Additional Topics

Computer Programming I

Iteration CHAPTER 6. Topic Summary

C Programming Structure of a C18 Program

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Stack Allocation. Run-Time Data Structures. Static Structures

Transcription:

CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. The amount of memory used by an array depends upon the array's data type and how many elements in the array currently have data stored in them. 2. In C++, if you attempt to store more data in an array than it can hold, the compiler will issue an error. 3. You may use the exit() function to return the flow of control from a function back to main(), regardless of where the function was called from. 4. To account for the null terminator stored at the end of each C-string, the strlen function returns the number of characters in its argument, plus one. 5. Any algorithm that can be coded with recursion can also be coded using a loop. 6. A one-dimensional array can be initialized at the time it is defined, but a two-dimensional array cannot be. 7. An individual array element can be processed or passed to a function just like a regular C++ variable. 8. The following array definition is legal because C++ allows arrays to be implicitly sized. int grades[ ]; 9. C++ allows arrays to have more than two dimensions. 10. The following statement is a valid C++ array definition. double money[25.00]; 11. A pointer can be passed as an argument to a function. 12. The ampersand (&) is used to dereference a pointer variable in C++. 13. C-string can be assigned to an variable whose type is the string class. 14. C++ does not perform array bounds checking.

Multiple Choice (3 pts each) 15. The type of the literal string "Hello" is best described as a) *char[]. b) *string. c) char *. d) string *. 16. The statement cout << &num1; will output a) the value stored in the variable called num1. b) the string "&num1". c) the number 1. d) the memory address of the variable called num1. 17. To declare an array that will store students' last names of up to 25 characters in length, which is an appropriate statement? a) char lastname[25]; b) string lastname[25]; c) string lastname[24]; d) char lastname[26]; 18. An array can store a group of values, but the values must be a) constants. b) all the same data type. c) numeric, not characters or strings. d) declared at the time the array is created. e) none of the above. 19. What are the values in the array after execution of the following code? int a[4] = 3, 7, 6, 2; int i = 2; a[i] = i + 1; a[i + 1] = a[ i 1]; a[1] = 5; a) 5, 3, 3, 6 b) 3, 5, 3, 7 c) 5, 7, 3, 7 d) 5, 7, 2, 1

20. To use the strlen function in a program, you must #include a) <iostring>. b) <stringlib>. c) <strlen>. d) <cstring>. 21. Dynamic memory allocation occurs a) when a pointer fails to dereference the right variable. b) when a variable is created by the compiler. c) when a pointer is assigned an incorrect address. d) when a variable is created at run-time. 22. The statement int *ptr = new int; acquires memory to hold an integer and then a) assigns an integer value to the variable called ptr. b) initializes the allocated memory to 0. c) creates a new pointer called int. d) sets ptr to point to the allocated memory. 23. The statement cout << *ptr; will output a) the address of the variable stored in ptr. b) the value stored in the address contained in ptr. c) the string "*ptr". d) the address of the variable whose address is stored in ptr. 24. If dynamically allocated memory is not freed, a) a run-time error informs your user that the program did not free memory space. b) the source code will not link correctly. c) the system may run out of memory. d) it results in a compiler error. 25. An overloaded function is one a) that has too many parameters. b) that does different things depending on who calls it. c) that attempts to do too much in a single function. d) that call other functions. e) that has the same name as another function.

26. What is the value of pointer p after the following assignment? p = new char; a) 0 b) c) stack address d) heap address 27. When should a parameter be a reference parameter? a) When the parameter is carrying information into the function that does not have to be returned b) When the parameter is carrying information into the function that may be changed and the new value should be returned c) When the information is to be returned from the function using the parameter. d) Both b and c 28. What is the output of this code, given the following function definition? int x =5, y = 2; y = mixup (x, y); cout << x; int mixup (int &p, int t) p = p * t; return p + 1; //function definition a) 5 b) 6 c) 10 d) 11 29. Given the function prototype and variable declarations, which of the following is a valid function call? void compute (int, float, char&, int& ); // function prototype int x, y; float p, q; char r, s; //variable declarations a) compute (x, 7.3, c, y); b) compute (y, p, s, x + y); c) compute (5, p + q, r, y); d) compute (x, s, r, 8);

30. A(n) argument is one that is automatically passed to a parameter when the argument is left out of the function call. a) actual b) default c) floating-point d) null e) static 31. A recursive function should be designed to stop making recursive calls when it reaches its a) return statement. b) closing curly brace. c) last parameter. d) base case. 32. If the array defined as int myarray[20][10] is being passed to a function named displayarray, along with information on the number of rows and number of columns, which of the following function calls is correct? a) displayarray(int myarray, 20, 10); b) displayarray(myarray, 20, 10); c) displayarray(myarray[20][10]); d) displayarray(myarray[ ][ ], 20, 10); e) none of the above 33. The statement int *ptr; means a) the variable called *ptr will store an asterisk and an integer value. b) ptr is a pointer variable that will store the address of an integer. c) the variable called ptr will store an integer value. d) All of the above 34. Suppose that a recursive function with integer parameter n has a base case of 0, and for each non-base case, the function makes a recursive call with argument n+1. If the function is initially called with an actual argument of n = 3, the function call will a) return after a chain of 4 recursive calls. b) return after a chain of 2 recursive calls. c) return after a chain of 3 recursive calls. d) cause an infinite chain of recursive calls. 35. The correct reference for the element in the third row and fifth column of a matrix called mymatrix represented by a two dimensional array is: a) mymatrix [3] [5] b) mymatrix [2] [4] c) mymatrix [2, 4] d) mymatrix [5]

36. What is the output of the following segment of code? int *p; p = new int; *p = 7; cout << *p; a) 0 b) 7 c) there will be an error message d) we cannot tell because we do not know what memory address will be assigned to p 37. What is the value of b after the following function call? int b = 3; mystery (b); // function call a) 2 b) 3 c) 13 d) 15 void mystery (int &val) //function definition for (int c = 0; c < 5; c++) val += 2; 38. What is the output of the following function call, given the function definition below? cout << tester (4); // function call a) 3 b) 6 c) 12 d) 24 int tester (int n) // function definition if (n == 1) return 3; else return 2 * tester ( n 1); Extra Credit (2 pts each): 39. True(A)/False(B) Storage is allocated for a pointer and the data that it points to at the same time.

40. 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 41. Which of the following is a valid assignment, given the following declarations? float *s; float *t; a) s = 50.0; b) t = 2000; c) s = s * 2; d) s = t; 42. What is the output of the following code given the function definition below? string word = Hello ; mystery (word); cout << word; void mystery (string p) // function definition int size = p.length (); for (int c = 0; c < size; c++) p.insert(0, * ); a) Hello b) *Hello c) Hello***** d) *****Hello 43. You are passing a two dimensional array, defined as below, to a function. What would be a correct function prototype? (ROWS and COLS are global constants.) int table [ROWS] [COLS]; a) float calculate (int matrix [ ] [ COLS], int rows); b) float calculate (int matrix [ROWS ] [ ], int rows); c) float calculate (matrix [ ROWS] [ COLS], int rows); d) float calculate (int matrix [ROWS ] [ ], int cols);