Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

Similar documents
Name: Username: I. 10. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

Name: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.

CS201 Latest Solved MCQs

CMSC 202 Midterm Exam 1 Fall 2015

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

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

COMP 524 Spring 2018 Midterm Thursday, March 1

IS0020 Program Design and Software Tools Midterm, Fall, 2004

Announcements. Lecture 05a Header Classes. Midterm Format. Midterm Questions. More Midterm Stuff 9/19/17. Memory Management Strategy #0 (Review)

CS201 Some Important Definitions

ComS 228 Exam 1. September 27, 2004

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

Common Misunderstandings from Exam 1 Material

CSE 333 Midterm Exam 5/10/13

CS201- Introduction to Programming Current Quizzes

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

Final CSE 131B Spring 2004

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

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

Introduction to Programming Using Java (98-388)

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

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

04-19 Discussion Notes

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

Pointers, Dynamic Data, and Reference Types

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Introduction to Computer Science Midterm 3 Fall, Points

CSC 210, Exam Two Section February 1999

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Largest Online Community of VU Students

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

Polymorphism Part 1 1

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

CSE 333 Midterm Exam 2/14/14

CMSC 202 Final May 19, Name: UserID: (Circle your section) Section: 101 Tuesday 11: Thursday 11:30

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Lecture 15a Persistent Memory & Shared Pointers

Exam 3 Chapters 7 & 9

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CSE 333 Midterm Exam Sample Solution 5/10/13

Lesson 13 - Vectors Dynamic Data Storage

Algorithms & Data Structures

PREPARING FOR PRELIM 1

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

Implementing Abstract Data Types (ADT) using Classes

Today s lecture. CS 314 fall 01 C++ 1, page 1

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CSE 333 Midterm Exam Nov. 3, 2017 Sample Solution

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

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

Chapter 1 Getting Started

Classes: Member functions // classes example #include <iostream> using namespace std; Objects : Reminder. Member functions: Methods.

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

Announcements. Lecture 04b Header Classes. Review (again) Comments on PA1 & PA2. Warning about Arrays. Arrays 9/15/17

CSE 333 Midterm Exam July 24, Name UW ID#

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

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)


CSE 333 Midterm Exam 7/25/16. Name UW ID#

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

CIS*2430 (Fall 2012) Miterm Exam (I) Solutions

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

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

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

C++ (classes) Hwansoo Han

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

Short Notes of CS201

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

Launchpad Lecture -10

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions

Section - Computer Science. int main() {! int a=10,b=20;! printf("a:%d B:%d\n",a,b);! a=(a+b)-(b=a);! printf("a:%d B:%d\n",a,b);!

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

CS 61B: Midterm Exam I

Memory Leak. C++: Memory Problems. Memory Leak. Memory Leak. Pointer Ownership. Memory Leak

CSE 333 Midterm Exam 7/29/13

Understanding Pointers

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination

C Pointers. 6th April 2017 Giulio Picierro

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

CS201 - Introduction to Programming Glossary By

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II

C++ For Science and Engineering Lecture 15

An Introduction to C++

CS 113 MIDTERM EXAM 2 SPRING 2013

Object Oriented Design

Implementing an ADT with a Class

Functions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

Transcription:

CMSC 202 Section 06 Fall 2015 Computer Science II Midterm Exam I Name: Username: Score Max Section: (check one) 07 - Sushant Athley, Tuesday 11:30am 08 - Aishwarya Bhide, Thursday 11:30am 09 - Phanindra Kumar, Tuesday 2:30pm 10 - Phanindra Kumar, Thursday 2:30pm 16 - Sudip Mittal, Tuesday 10:00am 17 - Sushant Athley, Thursday 4:00pm I. 20 II. p. 3 16 p. 4 16 p. 5 8 III. p. 6 10 p. 7 10 p. 8 10 p. 9 10 Total 100 Instructions: 1. This is a closed-book, closed-notes exam. 2. You have 75 minutes for the exam. 3. Calculators, cell phones and laptops must be put away. 4. Clearly indicate your final answer.

I. Multiple Choice (2 points each) For each question in this section, circle ONE answer. Choose the BEST answer. 1. C++ allows functions to be overloaded. This means (a) You can have two functions with the same name in the same scope. (b) You can call a function with more arguments than it has formal parameters. (c) You can call the function multiple times in parallel. (d) A function is allowed to call itself as long as its name is in the same namespace. 2. To store the string "avant-garde" in a C array of char, the array must have (a) exactly 11 entries (b) at least 11 entries (c) at least 12 entries (d) exactly 13 entries 3. Consider a program that contains the following statements: int A[5] = { 1, 2, 3, 4, 5} ; int B[5] = {101, 102, 103, 104, 105} ; A = B ; (a) This program would not compile. (b) After execution of these statements, the array A would hold 101, 102, 103, 104 and 105. (c) After execution of these statements, the array B would hold 1, 2, 3, 4 and 5. (d) After execution of these statements, the variable A becomes a pointer to int. 4. A private data member of an object can be modified by code in (a) the main() function. (b) the function where the object was declared. (c) member functions of the same class. (d) all of the above 5. A public data member of an object can be modified by code in (a) the main() function. (b) member functions of another class. (c) member functions of the same class. (d) all of the above 1

6. A function with return type void (a) does not return any values (b) returns 0 (c) returns \0 (d) returns the this pointer 7. Global variables of type int are stored in (a) the heap (b) the data segment (c) the stack (d) the operating system 8. Local variables of type int are stored in (a) the heap (b) the data segment (c) the stack (d) the operating system 9. The const keyword can be used to (a) define global const variables (b) declare const member functions (c) declare const parameters (d) all of the above 10. A constructor for a class Rover is invoked when (a) a local variable with type Rover is created. (b) a global variable with type Rover is created. (c) an array of Rover objects is defined. (d) all of the above 2

II. Short Answers (4 points each) 1. Where in memory is a dynamically allocated int array stored? 2. Write down the function prototype of a function named snap that takes two double parameters and returns a char: 3. Write down the function prototype of a function named crackle that takes an array of int for its first parameter and a char for its second parameter and does not return any values. 4. What information is part of a function s signature? 3

5. Describe one use of the scope resolution operator ::. 6. Describe one difference between a const member function and a non-const member function. 7. After the following code fragment, what are the values of x, y and z? int x = 87, y = 92 ; int &z = x ; z = y ; z = y - x ; 8. C header files usually begin with something like: #ifndef _MONGOOSE_H #define _MONGOOSE_H Describe one purpose of these lines in the header file. 4

9. Consider the following function: int bmw (int *ptr1, int *ptr2) { int k = 7 ; } *ptr1 = k - *ptr2 ; *ptr2 = k + *ptr1 ; k = *ptr1 + *ptr2 ; return k ; Suppose we call bmw() as follows: int a = 12, b = 9, c = 4 ; c = bmw(&a, &b) ; What are the values of a, b and c at the end of this program fragment? 10. Write down the contents of the array A after the following statements: int A[5] = { 77, 92, 31, 46, 18} ; int *ptr ; ptr = A ; ptr = ptr + 2 ; *ptr = 999 ; 5

III. Coding (8 points each) 1. Assume that the int variable n contains a positive value. Write a syntactically correct C++ program fragment, which must include a for loop, that prints out the first n odd numbers followed by the sum of the first n odd numbers. For example, if n has the value 3, your program should print out: 1 + 3 + 5 = 9 If n is 9, then your program should print out: 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 = 81 You do have to pay attention to C++ syntax. Declare all variables. 6

2. Write a syntactically correct while loop in C/C++ that repeatedly asks the user for a number as input until the user enters a number that is divisible by 3. You do not have to worry about the user entering non-numerical or badly formatted input. You do have to pay attention to C++ syntax. Declare all variables. 7

3. Write a syntactically correct C++ function called space2plus that takes a char array as a parameter and returns an int value. Your function should expect the char array to be a null-terminated C string. The function space2plus must replace every space character found in the parameter and with a plus symbol. The function should return the number of replacements performed. For example, after the sequence of statements: int n ; char str[] = "The referee s gun starts to roar" ; n = space2plus(str) ; the variable n should be 5 and str should hold the string "The+referee s+gun+starts+to+roar". You do have to pay attention to C++ syntax. You must not use any global variables. 8

4. Write a syntactically correct C++ function called sort that takes two parameters. After calling sort with two int variables, the first variable should hold the larger of the two arguments, and the second variable should have the smaller of the two arguments. The function sort should not return any values. For example, after the sequence of statements: int a = 5, b = 9 ; sort(a, b) ; the variable a should be 9 and the variable b should be 5. On the other hand, after: int c = 15, d = 9 ; sort(c, d) ; the variable c is still 15 and the variable d is still 9. You do have to pay attention to C++ syntax. You must not use any global variables. 9