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

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

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

Midterm Examination. Instructor: Gary Chan Date: Saturday, 23 October 2010 Time: 2:30pm 4:00pm Venue: LTC

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

C:\Temp\Templates. Download This PDF From The Web Site

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

EECS168 Exam 3 Review

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

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

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.

Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

CS201- Introduction to Programming Current Quizzes

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

Introduction to Programming using C++

CSCE 206: Structured Programming in C++

2 2

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

ComS 228 Exam 1. September 27, 2004

CMSC 202 Midterm Exam 1 Fall 2015

CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Exam 3 Chapters 7 & 9

Common Misunderstandings from Exam 1 Material

Introduction to Computer Science Midterm 3 Fall, Points

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

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


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

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

14.1. Chapter 14: static member variable. Instance and Static Members 8/23/2014. Instance and Static Members

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

Lecture 7. Log into Linux New documents posted to course webpage

CS 115 Exam 3, Spring 2010

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

CE221 Programming in C++ Part 1 Introduction

Lecture 2, September 4

CSCI 102 Fall 2010 Exam #1

CS 376b Computer Vision

PIC 10A. Final Review: Part I

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

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

University of Toronto

Short Notes of CS201

Ministry of Higher Education Colleges of Applied Sciences Final Exam Academic Year 2009/2010. Student s Name

CSC 210, Exam Two Section February 1999

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

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Intermediate Programming & Design (C++) Classes in C++

Chapter 8. Operator Overloading, Friends, and References. Copyright 2010 Pearson Addison-Wesley. All rights reserved

CS201 - Introduction to Programming Glossary By

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

Midterm Practice Exam

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

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

Arrays. Arizona State University 1

Grades. Notes (by question) Score Num Students Approx Grade A 90s 7 A 80s 20 B 70s 9 C 60s 9 C

CSCE Practice Midterm. Data Types

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

a data type is Types

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Fundamentals of Programming Session 23

CMSC 341 Lecture 7 Lists

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

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

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

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:

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

CS250 Final Review Questions

BASIC ELEMENTS OF A COMPUTER PROGRAM

This test is OPEN Textbook and CLOSED notes. The use of computing and/or communicating devices is NOT permitted.

Increment and the While. Class 15

Object Oriented Programming in C#

Abstract Data Types (ADT) and C++ Classes

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

This examination has 11 pages. Check that you have a complete paper.

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

Object Oriented Design

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

Programming, numerics and optimization

CS 142 Style Guide Grading and Details

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE Fall 20l2, Second Exam

CSCE 2004 Final Exam Spring Version A

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

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

CIS 130 Exam #2 Review Suggestions

Linked List using a Sentinel

CPSC 427: Object-Oriented Programming

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

III. Classes (Chap. 3)

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

CSE 333 Midterm Exam 5/10/13

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

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)

CS250 Final Review Questions

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

CSc 328, Spring 2004 Final Examination May 12, 2004

Circle all of the following which would make sense as the function prototype.

CSCE 206: Structured Programming in C++

Transcription:

University of Maryland Baltimore County CMSC 202 Computer Science II Fall 2004 Mid-Term Exam Sections 0201 0206 Lecture Hours: Monday Wednesday 5:30 PM 6:45 PM Exam Date: Wednesday 10/20/2004 Exam Duration: 5:30 PM 6:45 PM Instructor: Sa ad Raouf Name: SSN: Score: Section: (Circle your Section Number below) Section TA Day Time Room 0201 Patrick & Carrie Monday 7:30-8:20pm ECS 104 A 0202 Patrick & Carrie Wednesday 7:30-8:20pm ECS 104 A 0203 Patrick & Ryan Monday 2:00-2:50pm ECS 104 A 0204 Patrick & Ryan Wed 2:00-2:50pm ECS 104 A 0205 Patrick & Carrie Monday 11:00-11:50am ECS 104 A 0206 Patrick & Carrie Wed 11:00-11:50am ECS 104 A Notes: 1. This exam is a closed book, and a closed notes exam. 2. All answers are to be written on the enclosed exam sheets. Scratch sheets are not allowed. If necessary, you can use the back of the exam sheets. 3. You will need to present your Photo ID when handing in the exam. No exceptions. 4. Please hand in your exam with your section number circled. If your section number is not circled, your exam will not be graded.

1) (2 points each) Write True or False in the TRUE/FALSE column: a) argv[1] is always the name of the executable program TRUE/FALSE b) Class mutator methods can only be declared as const methods c) If a mutator method receives invalid data, then the mutator should terminate the program. d) The following vector declaration causes the constructor for the Student class to be invoked: vector <Student> mystudents; e) In the method for the post increment operator for the Money class: Money operator++( int dummy); the value of the dummy parameter is zero. f) In C++, the stream extraction operator is defined as operator>>. g) endl and \n are the same, there is no difference between using endl and \n in a cout statement h) A static data member of a class is considered a global data member for all instances of the class i) Class methods cannot be declared as static methods. j) Mr. Raouf mentioned in the lecture that operator overloading is an example of Syntactic Sugar Instructor: Sa'ad Raouf 10/18/2005 1

2. (6 points) List 3 issues where vectors are superior to arrays. Give an example for each issue. Use the array declaration int myarray[10]; for your examples. 1. The size of the array must be declared at compile time and cannot be changed (without using dynamic memory allocation). 2. We must use a separate variable to keep track of the number of elements in the array that are actually used. 3. If we use an array index that's out-of-bounds, our program crashes. 4. The name of an array is like a pointer which can be very confusing (e.g. when passed to a function). 5. Elements of an array are not automatically initialized. 6. We can't assign one array to another unless we write code to do so. 3. (4 points) Show the output from the following code snippet: vector < int > integers (5); for (unsigned int i = 0; i < integers.size( ); i++) cout << integers.at( i ) << endl; integers.push_back(i); What will the value of i be after the for loop has completed? What will the size of the vector be after the for loop has completed? Infinite loop Instructor: Sa'ad Raouf 10/18/2005 2

4. (4 points) Rewrite the following code to use call by reference parameters instead of pointers. // function prototype void add1 (int * pmyinteger); //function definition void add1 (int * pmyinteger) (* pmyinteger)++; void add1 (int & MyInteger); void add1(int & MyInteger) MyInteger++; 5. (6 points) Write the C++ statements for the following: Create a vector of Bicycle objects called mybicycles Create an instance of a Bicycle class called somebicycle, using the default constructor. Insert the somebicycle object at the end of the mybicycles vector. vector <Bicycle> mybicycles; Bicycle somebicycle; mybicycles.push_back(somebicycle); Instructor: Sa'ad Raouf 10/18/2005 3

6. (5 points) Given that Circle is a class that contains a Point class, and you noticed the following constructor for the Circle class during your visit to the C++ Country Club: Circle (Point center, float radius); Explain if you should speak out, or remain silent, and why? ANSWER: I would speak out and suggest that passing Point by value is inefficient. I would suggest that the following be used Circle (const Point & center); 7. (5 points) Given the following function header for a class accessor called GetDayOfYear, explain the significance of each const listed below: const DayOfYear & Vacation::GetDayOfYear ( ) const answer: const DayOfYear & returns a const reference const ensures that the method does not alter any of the data members of the class. Instructor: Sa'ad Raouf 10/18/2005 4

8. (6 points) What will the following declarations do: a. vector <Tractor * > machineshed; b. vector < vector < string> > Words; c. vector <char> WordsInAlphabet(26); a. b. c 9. (4 points) Given the following class definition, write the statement to initialize static data member m_turn to 0; class Server public: private: ; static int m_turn; int Server::m_turn = 0; Instructor: Sa'ad Raouf 10/18/2005 5

10. (5 points) Rewrite the following constructor to use a member initialization list someclass::someclass( string somename, float somemoney ) m_name = somename; m_money= somemoney; someclass::someclass( string somename, float somemoney ): m_name (somename), m_money(somemoney) 11. (5 points) Since there is no way to prevent the user of a class from passing invalid parameter values to a constructor, define a mechanism that can indicate to the user of the class if invalid parameters were passed to the constructor. ANSWER: Create a private Boolean data member that is set to true if the parameter data is correct, and set to false otherwise. Create a public accessor method to return the value of the Boolean data member 12. (5 points) Given that Toy is a user defined data type, explain each of the following statements: Toy mytoy(); Toy mytoy; ANSWER: Toy mytoy(); is a function prototype for a function that returns a Toy object, and is not passed any parameters (void) Toy mytoy; calls the default constructor for the Toy class to create an object called mytoy Instructor: Sa'ad Raouf 10/18/2005 6

13. During one of the lectures where object oriented concepts were first introduced to you, we discussed a conceptual design for a Command Line class. The following is a class definition for CCommandLine class: class CCommandLine public: CCommandLine(); CCommandLine(int argc, char * argv[]); CCommandLine(int argc, const vector <string> & argv); string getparameter(unsigned int index); bool findparameter(string parameter); unsigned int getparametercount(); vector <string> getallparameters(); const CCommandLine operator+(const string & LHS); private: int m_argc; vector <string> m_argv; ; The class CCommandLine is used to model argc, and argv as defined in main(). The class designer has decided to use 2 private data members: int m_argc: used to represent the number of arguments, same as the argc in main vector < string > m_argv: used to store the command line parameters, where each parameter is a string, same as the char * argv[] in main. Given the above class definition, write the code for the following methods: (5 points) CCommandLine(): default constructor, use a member initialization list where applicable CCommandLine::CCommandLine() : m_argc(0) (5 points) CCommandLine(int argc, char * argv[]): constructor, use a member initialization list where applicable CCommandLine::CCommandLine(int argc, char * argv[]) : m_argc(argc) for (int i = 0; i < m_argc; i++) m_argv.push_back(argv[i]); Instructor: Sa'ad Raouf 10/18/2005 7

(5 points) CCommandLine(int argc, const vector <string> & argv): constructor, use a member initialization list where applicable CCommandLine::CCommandLine(int argc, const vector <string> & char argv) : m_argc(argc) for (int i = 0; i < m_argc; i++) m_argv.push_back(argv[i]); (5 points) bool findparameter(string parameter): a method that returns true if the parameter is found in the parameter list, else returns false bool CCommandLine::findParameter(string parameter) unsigned int i = 0; unsigned int size = m_argv.size(); while (i < size) if (parameter == m_argv[i]) return true; i++; return false; (5 points) const CCommandLine operator+(const string & LHS): overloaded + operator to add a string to the m_argv, and to increment m_argc; const CCommandLine CCommandLine::operator+(const string & LHS) m_argc++; m_argv.push_back(lhs); return CCommandLine(m_argc, m_argv); Instructor: Sa'ad Raouf 10/18/2005 8