Midterm Exam. Sample Solutions

Similar documents
Midterm Practice Exam

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

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

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

Linked List using a Sentinel

Practice Midterm Sample Solutions

ComS 228 Exam 1. September 27, 2004

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

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

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

Review Questions for Final Exam

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

CMSC 202 Midterm Exam 1 Fall 2015

ENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Data Structures (CS301) LAB

Lab Instructor : Jean Lai

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

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

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

Lab 2: ADT Design & Implementation

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

CSCE Practice Midterm. Data Types

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

Module Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1

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

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

Object Oriented Design

Midterm Practice Exam Sample Solutions

Midterm Practice TA: Brian Choi Section Webpage:

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

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

Part I: Short Answer (12 questions, 65 points total)

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

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

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

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

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CS 141, Introduction to Computer Science Fall Midterm Exam

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

1. (25 pts) Short Answer. Provide brief (1-3 sentence) answers to the following:

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

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

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

CS Fall 2018 Homework Assignment 3 Due: 23:59, Dec 26, 2018

CS 115 Exam 3, Spring 2010

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

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

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

CSCE 110 PROGRAMMING FUNDAMENTALS

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

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

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

Spring 2008 Data Structures (CS301) LAB

CSCE121: Introduction to Program Design and Concepts Practice Questions for Midterm 1

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

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

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)

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

Introduction Of Classes ( OOPS )

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

Review Questions for Final Exam KEY

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010

Multiple Choice Questions (20 questions * 6 points per question = 120 points)

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

CS Spring 2018 Homework Assignment 3 Due: 23:59, May 7, 2018

Fast Introduction to Object Oriented Programming and C++

Largest Online Community of VU Students

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

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

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

by Pearson Education, Inc. All Rights Reserved. 2

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

More About Classes. Gaddis Ch. 14, CS 2308 :: Fall 2015 Molly O'Neil

CS 216 Exam 1 Fall SOLUTION

OBJECT ORIENTED PROGRAMMING

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CS 2604 Homework 1 C++ Review Summer I 2003

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

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

What does it mean by information hiding? What are the advantages of it? {5 Marks}

III. Classes (Chap. 3)

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

CSCE Practice Midterm. Data Types

CSci 1113 Final. Name: Student ID:

CS3157: Advanced Programming. Outline

Integer Data Types. Data Type. Data Types. int, short int, long int

Chapter 10 - Notes Applications of Arrays

CS 376b Computer Vision

Implementing an ADT with a Class

COSC 320 Exam 2 Key Spring Part 1: Hash Functions

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

Function Overloading

And Even More and More C++ Fundamentals of Computer Science

Short Notes of CS201

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

CSE 303 Final Exam. March 16, 2009

Transcription:

Name: CS 410 Introduction to Software Engineering Fall 2016 Instructor: Marc Pomplun Midterm Exam Sample Solutions No books, no notes, and no calculators are allowed. Question 1: out of points Question 2: out of points Question 3: out of points Question 4: out of points Total Score: Grade:

Question 1: Some Warm-Up Problems Tell whether each of the following statements is true or false by checking the appropriate box. Do not check any box if you do not know the right answer, because you will lose points for incorrect answers. Statement True False a) Every C++ program is object-oriented.. b) Every correct C program would also compile as a C++ program without any changes being necessary. c) Two of the main problems that we face in software engineering are complexity and change. d) C++ allows operator overloading. e) In C++, every function is a member of a class. f) Static class members do not belong to any particular object of their class. g) Const member functions cannot modify the values of their explicit inputs. h) Protected members are only visible to member functions of the same class. i) C++ programs require a main() function, which cannot be a member of any class. j) In order to instantiate an array of objects, the object class has to have a default constructor. 1 point for every correct answer, -1 point for every incorrect one.

Question 2: The Crazy Programmer The program on the following page was written by a crazy programmer. He or she produced some code that is not very elegant or robust but functional. Unfortunately, the choice of names for variables, functions, and classes is completely bizarre. (a) For each of the following items, suggest a better name for it and describe in one or two sentences what function the item has in the program: TuringsDog: better name: ListElement Holds one element (a string) of a singly-linked list and a pointer to the next element. porsche: better name: nextelement Pointer to the next element in the list. Bazinga: better name: OrderedList Class that can be used to build and output an ordered list of strings. encom: better name: firstelement Pointer to the first element in the list. kawoosh: better name: insertelement Inserts a new element (string s) into the list so that the list stays in ascending alphabetical order. evilprof: better name: deletefirstelement Deletes the first element in the list. If afterwards the list is empty, it returns true, otherwise false. glutenfree: better name: printlist Outputs the current list of strings in its alphabetical order to stdout. 1 point for every correct name + description

#include <cassert> #include <iostream> #include <string> using namespace std; struct TuringsDog string s; TuringsDog *porsche; ; class Bazinga public: Bazinga() encom = new TuringsDog; encom->s = "zzz", encom->porsche = NULL; ; ~Bazinga() while (encom!= NULL) evilprof(); ; void kawoosh(string s); bool evilprof(); void glutenfree(); private: TuringsDog *encom; ; void Bazinga::kawoosh(string s) TuringsDog *p = encom; while (p->s < s) p = p->porsche; TuringsDog *temp = new TuringsDog; temp->s = p->s; temp->porsche = p->porsche; p->s = s; p->porsche = temp; bool Bazinga::evilProf() TuringsDog *temp = encom->porsche; delete encom; encom = temp; return (encom == NULL); void Bazinga::glutenFree() TuringsDog *temp = encom; while (temp!= NULL) cout << temp->s << endl; temp = temp->porsche; int main() string list[] = "sometimes", "exam", "questions", "can", "be", "quite", "weird"; Bazinga b; for (int i = 0; i < 7; i++) b.kawoosh(list[i]); b.glutenfree(); return 0;

(b) What is the output of the program? be can exam questions quite sometimes weird zzz (The idea of using zzz as a dummy last element is very inelegant and imperfect, and also printing it is clearly a bug that the crazy programmer produced.) 2 points for correct output, and 1 bonus point if you additionally got the zzz right. Question 3: Prime Time On the following page you will find a C++ program that is supposed to output the first 100 prime numbers. It defines a class PrimeNumber that is initialized with an integer n. The data member number will be set to the smallest prime number greater or equal n. The ++ operator is overloaded to set number to the next greater prime number following the current one. Unfortunately, the program contains a lot of bugs. Sometimes there are some dots (...), indicating that you have to fill in some code there. But you may have to fill in code in other places, too. Good luck!

#include <iostream> using namespace std; class PrimeNumber public: private: ; int PrimeNumber(int n): number(n - 1) (*this)++; bool IsMultipleOf(int n) return (number%n == 0); PrimeNumber operator++() do number++; while (!IsPrime()); return *this; operator int() return number; bool IsPrime(); int number; void PrimeNumber::IsPrime() bool for (int i = 1; i <= number/2; i++) if (IsMultipleOf(i)) return true; delete return false; 2 int main() int n; delete PrimeNumber *p(2); for (int i = 1; i <= 100; i++) n = p; cout << n << " "; p++; cout << endl; return 0; 1 point for every bug you found. No penalty for marking bugs that actually are no bugs.

Question 4: Testing What is test-driven development? Why would a software company want to use it? Some of the main points to mention here: Write tests before writing the actual functions. Leads to short development/refactoring cycles and frequently tested code. These short cycles increase flexibility and productivity. Maximum of 5 points.