University of Utah School of Computing

Similar documents
1 Inheritance (8 minutes, 9 points)

JAVA MOCK TEST JAVA MOCK TEST II

Sample Examination Paper Programming and Software Development

McGill University School of Computer Science COMP-202A Introduction to Computing 1

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Project. C++: Inheritance III. Plan. Project. Before we begin. The final exam. Advanced Topics. Project. This week in the home stretch

CS260 Intro to Java & Android 03.Java Language Basics

ComS 228 Exam 1. September 27, 2004

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

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

1- Differentiate between extends and implements keywords in java? 2- What is wrong with this code:

VIRTUAL FUNCTIONS Chapter 10

Exam Duration: 2hrs and 30min Software Design

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

CS 162, Lecture 25: Exam II Review. 30 May 2018

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

Absolute C++ Walter Savitch

Administrivia. CMSC433, Fall 2001 Programming Language Technology and Paradigms. Administrivia (cont.) Project 1. Copy constructor.

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

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)

Introduction to Programming Using Java (98-388)

C++ (Non for C Programmer) (BT307) 40 Hours

C++ Inheritance and Encapsulation

Computer Sciences 302 Exam 2 Information & Sample Exam

9/10/2018 Programming Data Structures Inheritance

CSE351 Winter 2016, Final Examination March 16, 2016

Chapter-8 DATA TYPES. Introduction. Variable:

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

Lecture 5: Inheritance

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

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Use the scantron sheet to enter the answer to questions (pages 1-6)

CSCI 355 LAB #2 Spring 2004

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

EECE.3220: Data Structures Spring 2017

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

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

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

Instantiation of Template class

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

Object Oriented Programming. Solved MCQs - Part 2

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

Review Questions for Final Exam

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

MSO Exam November 7, 2016, 13:30 15:30, Educ-Gamma

CSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.

Classes, interfaces, & documentation. Review of basic building blocks

CS 1316 Exam 1 Summer 2009

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

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

Final Exam. Kenneth J. Goldman December 18, Name: Student ID Number: Signature:

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

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

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

Short Notes of CS201

CS 216 Exam 1 Fall SOLUTION

C++ Important Questions with Answers

CMSC202 Computer Science II for Majors

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

CS201 - Introduction to Programming Glossary By

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

CS 104 (Spring 2014) Final Exam 05/09/2014

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

CSE 113 A. Announcements - Lab

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Spring 2018

Arrays Classes & Methods, Inheritance

Lecture 15: Inheritance II

1 Method Signatures and Overloading (3 minutes, 2 points)

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

CS 112 Introduction to Programming

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

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

BASIC ELEMENTS OF A COMPUTER PROGRAM

CSC 1300 Exam 4 Comprehensive-ish and Structs

CSE 303: Concepts and Tools for Software Development

CS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun

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.

Midterm Exam (REGULAR SECTION)

2. The object-oriented paradigm!

Super-Classes and sub-classes

The Java language has a wide variety of modifiers, including the following:

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

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

Prelim 1. CS2110, October 2, 2014, 5:30 PM Extra Total Question TrueFalse Multiple Object Oriented

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

Inheritance and Interfaces

Student Performance Q&A:

Instructions for Crossword Assignment CS130

Total Score /1 /20 /41 /15 /23 Grader

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.

CS112 Lecture: Repetition Statements

Week 8: Operator overloading

Declarations and Access Control SCJP tips

Midterm Exam CS 251, Intermediate Programming October 8, 2014

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Midterm Exam CS 251, Intermediate Programming March 6, 2015

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

CS 10, Fall 2015, Professor Prasad Jayanti

Transcription:

University of Utah School of Computing CS 1410 / CS 2000 Study Notes December 10, 2011 This study guide is designed to help you prepare and study the appropriate material for the final exam. For the multiple choice questions, sample questions from previous exams are given (without answers). Additional study topics are given for additional questions. For the programming problems, questions similar to the problems below will appear on the exam. In studying to find the answers, you will learn (or make sure you know) the material that you need for the exam. Caution: I have not had time to fully proofread this practice exam. Some questions may have typos, others may have a bit of Java in them, and others may have no correct answer. I ll make sure the actual exam questions are more robustly checked. The final exam is a closed book/notes exam and you will have 120 minutes to complete it. No electronic devices, notes, textbooks, papers, partners, or other references will be allowed. (Bring only pencils and/or pens.) The exam will consist of about 20 multiple choice questions and two or three programming problems. Students will write exam answers on answer sheets. Illegible handwriting will be marked incorrect, so write neatly. (No overlapping or partially erased answers.) Students will be allowed to ask for clarifications during the exam. The exam is Thursday, December 15 at 1:00 PM in our classroom. If you need to reschedule the exam, you may take it early, but not late. Absolutely no late exams will be given! Email me at my personal address to reschedule.

(1) Consider the expression (int) 42.6, what value and type will be the result? (A) A double equal to 42 (B) A double equal to 43 (C) An int equal to 42 (D) An int equal to 43 (2) Consider the statement double d = a.compute(x); Which one of the following cannot be deduced from the statement: (A) The compute function exists in a. (B) The compute function takes one parameter. (C) The compute function is not void. (D) The compute function returns a double value. (3) Consider the looping statement for (int i = 0; i < 10; i = i * 2) Assuming the body of the loop does not not break the loop or change i, how many times would the body of the loop be executed? (A) 0 (B) 3 (C) 7 (D) 10 (E) (4) Consider the looping statement for (int i = x; i <= 10; i = i + 1) Assuming the body of the loop does not not break the loop or change i, how many times would the body of the loop be executed? (A) 0 (B) x (C) 10 - x (D) 11 - x (E) (5) Consider the Boolean expression ismoon() && (isblue() isfull()) Under what condition(s) will isfull() not be called when this expression is evaluated? (Select all that apply.) (A) ismoon() returns true (B) ismoon() returns false (C) isblue() returns true (D) isblue() returns false (6) Which one of the following is the best big-oh estimate of the complexity of (2tlgt)+(4t)+(3 t)+6000? (A) O(6000) (B) O(t) (C) O(tlgt) (D) O( t) 2

(7) WhichofthefollowingbestcompletesthedefinitionofBig-O?Afunctionf(n)issaidtobeO(g(n)) if for some non-negative constants C and K if: (A) f(n) C g(n) for all n K (B) f(n) C g(n) for all n K (C) f(n) = C g(n) for all n = K (D) f(n) C g(n) for all n K (E) f(n) C g(n) for all n K (8) Assume an object is named alpha and it is of type Greek. What will happen when it is passed to a function that is declared like this: int dotask(greek a) (A) A pointer to alpha is stored in a. (B) The variable a will refer to the same object as the object in alpha. (C) A Greek object is created in a that gets an exact copy of alpha. (D) The variable a is set to the keyword this. (9) Which one of the following is false: (A) A subclass inherits functions and variable declarations from a superclass. (B) A subclass object pointer (of some superclass) may be used any place the superclass object pointer is expected. (C) A superclass may override virtual functions written in the subclass. (D) A subclass may have functions that are not declared in the superclass. (10) Select the best definition for polymorphism. (A) Data and functions are grouped together in a class. (B) One class may extend, or specialize, another class. (C) The user must not rely on the implementation details of a class. (D) The behavior of an object is determined by its content, not its context. (E) If class Alpha extends class Gamma, Alpha isa Gamma. (11) In C++, which one of the following is required for polymorphic behavior? (A) Global functions (B) Destructors (C) Function overloading (D) Function overriding 3

(12) Consider the following four statements that make use of inheritance and polymorphism. Assume classes Alpha and Beta are subclasses of class Gamma. Alpha *a = new Alpha (); Beta *b = new Beta (); Gamma *g = new Gamma (); g = b; // Next (fifth) statement goes here. Consider the fourth statement g = b;. Which of the following best describes the effect of this statement? (A) g gets a copy of the Beta object in b. (B) g will point to the same object as b. (C) A new Gamma object is created from b and is stored in g. (D) A new Beta object is created from g and is stored in b. (E) The code will not compile. (13) Which one of the following statements, when viewed as the fifth statement, would be illegal at compile time? (A) a = new Gamma (); (B) g = new Alpha (); (C) g = a; (D) b = new Beta (); (14) Which one of the following is guaranteed to be true? (A) a.test(); is legal if Beta has a virtual void test() method. (B) g.test(); is legal if Alpha has a virtual void test() method. (C) a.test(); is legal if Gamma has a virtual void test() method. (D) g.test(); is legal if Beta has a virtual void test() method. (E) b.test(); is legal if Alpha has a virtual void test() method. (15) A method contract specifies preconditions and postconditions, true or false? (16) Testing is the least important of the stages of programming, true or false? 4

(17) What will min and max contain after the following optimization loop executes? (The code demonstrates several common programming errors - be careful.) int ages[] = 3, 7, 15, 21, 8, 3, 4, 56, 0, 1}; int min = ages[0]; int max = ages[0]; for(int i = 1; i < 10; i++) if(ages[i] < min) min = ages[i]; } } else max = ages[i]; } (A) Min: 0, Max: 56 (B) Min: 56, Max: 0 (C) Min: 56, Max: 1 (D) Min: 0, Max: 1 (E) Min: 1, Max: 0 I recommend studying these additional topics: The this keyword The NULL keyword The new keyword How and why destructors are used The purpose of copy constructors Bitwise ANDing of values: 6 & 2, etc. Bitwise ORing of values: 6 3, etc. Bitwise shifting of values: 1 2, etc. Characters, integers, and conversions The flow of an Arduino program Using Arduino Serial communications Timing an Arduino program Additional examples of reading and understanding code: Arrays, function calls, epressions and type, etc. Software engineering: Correct and incorrect ways to develop programs 5

Programming question: Use if statements, expressions, local variables, and return statements to complete the function below so that it satisfies the following description. The function below should compute and return a double that corresponds to the yearly salary for an employee. The method takes two parameters, an integer that corresponds to the employee s years of experience, and a double that contains a base salary. (See the method header below.) You should calculate and return the salary for an employee using these rules: If the employee has 5 years experience or less, their salary is just the base salary. If the employee has more than 5 years experience, they receive a bonus of 10% of their base salary for each year of experience past 5 years. Example: If an employee has eight years of experience, she receives her base salary plus 30% of the base salary for her three extra years of experience. No employee should receive more than twice the base salary. This is the maximum salary that should ever be returned. Example: If an employee has 20 years of experience, he should get his base salary plus a bonus of 150% of the base salary as a bonus for his extra 15 years of experience. This would add up to be 250% of the base salary. Unfortunately, he can receive at most twice the base salary, so his salary is limited to 200% of the base salary. Write statements inside the function below to complete the function. Your code will be graded for correctness, neatness, and proper syntax. A typical solution will be 6 to 10 lines of code. /* Computes and returns the salary for an employee. * * The paramter years contains the employee s number of years of experience. * The parameter base contains the base salary for the employee. */ double calculatesalary (int years, double base) } 6

Programming question: Assume you have a linked list of double values (similar to the example from class) represented by this linked list class: struct Node double data; Node *next; }; class LinkedListDouble private: int count; Node *head, *tail; public: int find (double v); }; // Other functions not shown -- assume you cannot use them Write a complete function definition (including a small function contract) for a find function (shown declared above). The find function should search the list for the data value v and return the position of the value v in the list. (The first data value in the list is poision 0, and the function should return -1 if v is not in the list.) The problem will be scored on the following: Correct algorithm, correct use of pointers, correct definition of a class function, correct syntax, and neatness of communication. You may assume the list is properly constructed, but you may not assume the list is non-empty. A correct solution will be about 15 lines, with only 5-6 actual statements. 7

Programming question: Assume you are working on an Arduino project with a few friends you and your friends are building a thermostat. Your friends have written these two classes that represent a way to control a furnace and an air conditioner: class Cooler class Heater public: public: void turnon(); void turnon(); void turnoff(); void turnoff(); bool ison(); bool ison(); } } Your friends have already written these classes and the Arduino setup and loop functions, but they need help creating a Thermostat class. For this problem you are to write a complete header file and.cpp file to declare and define a thermostat class. Your thermostat class will represent the behavior of a typical household thermostat: When the room temperature gets colder than some minimum temperature, your thermostat will turn on the furnace. When the room temperature gets warmer than some maximum temperature, your thermostat will turn on the air conditioning. When the temperature is between the minimum and maximum temperatures (inclusive), your thermostat will make sure the furnace and air conditioning are off. To rephrase, your thermostat can be in exactly one of three states: cooling is on, heat is on, or everything is off. The current state is determined by the current temperature. You won t need to do any timing, input/output code, or any other Ardunio-specific code. Instead, you will just write a class that provides support functions. Your friends code will call your class functions to set the temperatures, and your class will call pre-existing Cooler and Heater objects to turn on and off the cooler and heater. Continued on next page... 8

Continued from previous page... Your Thermostat class should have the following behaviors: Declare a few instance variables. You can determine what you need from the description of the functions below. Declare and define a constructor. Your constructor must require exactly five parameters: A Cooler object, a Heater object, a minimum temperature, a maximum temperature, and the current temperature (as integers). You may assume that the Cooler and Heater objects will be valid. You may assume that the minimum temperature is less than the maximum temperature. Store these values as appropriate and activate the correct thermostat state. (See the next function.) Write a settemprange function for changing the temperature range. This function must take two parameters: a minimum temperature and a maximum temperature. If the minimum temperature is greater than the maximum temperature, do nothing. Otherwise, store these values and activate the correct thermostat state based on the current temperature. Write a setcurrenttemp function for recording the current room temperature. Store the value (as appropriate for your class) and activate the correct thermostat state. Write a coolerison function that will return true if the air conditioner is on, false otherwise. Write a heaterison function that will return true if the furnace is on, false otherwise. Your code will be graded on completeness, correctness, conciseness, clarity, and syntax. Comments and contracts are not required, but helpful to your grade. Illegible and confusing solutions will be marked as wrong. All global variables, user I/O, Arduino functions, arrays, new object creation, and pointers are forbidden. 9