Practice Midterm Sample Solutions

Similar documents
Midterm Practice Exam

Midterm Exam. Sample Solutions

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

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

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

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

CS 106B Lecture 2: C++ Functions

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

Lecture 12. Monday, February 7 CS 215 Fundamentals of Programming II - Lecture 12 1

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

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

CISC2000/ of 6

VARIABLES & ASSIGNMENTS

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

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

PIC 10A. Final Review: Part I

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

Computer Programming. Dr. Fahad Computer Science Deptt.

Describing and Implementing Algorithms

IDE: Integrated Development Environment

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

CS 103 Unit 13 Slides

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Computer Programming. Basic Control Flow - Decisions. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Sol. Sol. a. void remove_items_less_than(int arr[], int size, int value) #include <iostream> #include <ctime> using namespace std;

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

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

G52CPP C++ Programming Lecture 17

6. Pointers, Structs, and Arrays. 1. Juli 2011

Sequential Program Execution

CS 61B Discussion Quiz 1. Questions

CS2255 HOMEWORK #1 Fall 2012

Algorithms for Arrays Vectors Pointers CS 16: Solving Problems with Computers I Lecture #14

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

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

Review Questions I Spring 2010

Midterm Practice Exam Sample Solutions

Lesson 13 - Vectors Dynamic Data Storage

IS 0020 Program Design and Software Tools

Practice Problems CS2620 Advanced Programming, Spring 2003

Computer Programming

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

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

Due Date: See Blackboard

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

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

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

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

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

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

Exam I Review Questions Fall 2010

Review Questions II KEY

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

CS220/MATH320 Applied Discrete Mathematics Instructor: Marc Pomplun Practice Exam. Sample Solutions

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

Patterns: Working with Arrays

Security Coding Module - Buffer Overflow Data Gone Wild CS1

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

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

Review. Relational Operators. The if Statement. CS 151 Review #4

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:

2 nd Week Lecture Notes

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

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

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

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

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

Introducing C++ to Java Programmers

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

EECS 183, Week 5. General. Variables I/O. 0. At which location do you have to take the exam? 1. Source code vs. object code? 2. What s a library?

Fast Introduction to Object Oriented Programming and C++

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.5. for loop and do-while loop

Due Date: See Blackboard

Chapter 10 - Notes Applications of Arrays

Lab # 02. Basic Elements of C++ _ Part1

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Lab Instructor : Jean Lai

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

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

Name SECTION: 12:45 2:20. True or False (12 Points)

CSci 1113 Lab Exercise 6 (Week 7): Arrays & Strings

Concurrent Data Structures in C++ CSInParallel Project

Lab 7 (50 pts) Due Sunday, May 20)

Examination Questions Time allowed: 1 hour 15 minutes

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists

(the bubble footer is automatically inserted into this space)

Review Questions for Final Exam

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

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;

pointers + memory double x; string a; int x; main overhead int y; main overhead

CSCE Practice Midterm. Data Types

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Transcription:

CS 410 Introduction to Software Engineering Fall 2016 Instructor: Marc Pomplun Practice Midterm Sample Solutions Question 1: A Mysterious Program When the Visual Attention Lab at UMB moved to its new place, the lab team discovered an ancient C++ program written on an old, torn sheet of paper (see next page). Can you help the lab team to find out what each of the following functions/variables of the program does and what the program s output looks like? Use English words for your descriptions; you can also draw a schematic sketch of the output if you cannot describe it (but do not draw the entire output!). Mystery::char a[size][size]: (3 points) This 50 50 character array serves as a canvas for the program to draw on. Initially it is blank (filled with dots), then the program draws Xs on it and finally prints the array on the screen. Mystery::int x, y: (3 points) (x, y) indicates the current position of the drawing cursor on the canvas. It is updated whenever an X is drawn. Mystery::Mystery(int x0, int y0): (4 points) This is the constructor for the Mystery class. It initializes the canvas by completely filling it with dots. Moreover, it sets the initial cursor position to (x0, y0). Mystery::Draw(direction d, int length): (4 points) Starting at position (x, y), this function draws a straight line of Xs on the canvas. Direction d specifies the direction (up, down, left, or right) and int length specifies the maximum length of the line. The line drawing also terminates if the cursor leaves the canvas. In that case, the function returns false, otherwise it returns true. Mystery::GenerateOutput(): (4 points) This function draws a sequence of lines in the cyclic order of directions left, up, right, and down. The first line is of length one, and each following line is one X longer than the preceding one. The function terminates as soon as the drawing cursor leaves the canvas. What does the output look like? (6 points)

It looks like a spiral of Xs starting in the center of the canvas, as shown below, but extending to size 50 50:....XXXXXXXX..X...X..X.XXXX.X..X.X..X.X..X.XX.X.X..X...X.X..XXXXXX.X....X. Question 2: Chase the Bugs! For his latest research project, Professor P. wants to write a program that sorts an integer array containing ten elements. Going for the simplest solution, he decides to implement a bubble sort algorithm. The basic idea of bubble sort is that you first compare the first two elements in the list (elements 1 and 2). If element 1 is greater than element 2, you swap the values of the two elements, that is, element 1 receives the value of element 2 and vice versa. If element 1 is less than or equal to element 2, nothing happens. You then do the same thing with elements 2 and 3, then elements 3 and 4, and so on, until elements 9 and 10. This way the greatest element in the list will be carried to the end of the list. You repeat the whole procedure, but this time you can stop after comparing elements 8 and 9, because you know that element 10 is in the desired position already. Next time you can stop after elements 7 and 8, and so on, until the whole list is sorted in ascending order. As usual, Professor P. is in a hurry and seriously confused, so the first version of his program contains a lot of bugs. Please help him correct all the bugs so that the program creates the following desired output: -3000-54 0 1 16 22 34 512 1432 13245 Please indicate and correct all bugs in the program listing on the next page. Try to use as few changes as possible to make the program compile and run correctly. You may also insert and delete lines if you like to. Do not rewrite entire lines of code but use C++ syntax to keep the changes small. (Of course this task is difficult to do without using a compiler. Try to find as many bugs as possible; you will receive bonus points if you actually manage to correct all the bugs.)

#include <iostream> insert: #include <vector> using namespace std; void SwapIntegers(int a, int b) int temp = a; &a &b a = b; temp = b; b = temp; } void BubbleSort(vector &intvector) insert: <int> for (int i = intvector.size() - 1; i > 0; i++) i-- for (j = 0; j < i; j++) > if (intvector[j] < intvector[j + 1]) int j SwapIntegers(intVector[j], intvector[j + 1]); } int main() int intarray[] = 34, 1432, 1, -54, 16, 22, 13245, 512, -3000, 0}; vector<int> intvector(intarray, intarray + 9); delete: & BubbleSort(&intVector); 10 < for (int i = 0; i <= intvector.size(); i++) cout >> intvector[i] >> endl; return 0; } << << 2 points for every identified bug, and -1 point for every newly introduced bug.

Question 3: Being Agile Please describe what Agile software development is. From Wikipedia: Agile software development describes a set of principles for software development under which requirements and solutions evolve through the collaborative effort of self-organizing crossfunctional teams. It advocates adaptive planning, evolutionary development, early delivery, and continuous improvement, and it encourages rapid and flexible response to change.

Question 4: Technical Debt In software development, what is technical debt and what problems can it cause? From Wikipedia: Technical debt (also known as design debt or code debt) is "a concept in programming that reflects the extra development work that arises when code that is easy to implement in the short run is used instead of applying the best overall solution". Technical debt can be compared to monetary debt. If technical debt is not repaid, it can accumulate 'interest', making it harder to implement changes later on. Unaddressed technical debt increases software entropy. Technical debt is not necessarily a bad thing, and sometimes (e.g., as a proof-ofconcept) technical debt is required to move projects forward. On the other hand, some experts claim that the "technical debt" metaphor tends to minimize the impact, which results in insufficient prioritization of the necessary work to correct it. As a change is started on a codebase, there is often the need to make other coordinated changes at the same time in other parts of the codebase or documentation. The other required, but uncompleted changes, are considered debt that must be paid at some point in the future. Just like financial debt, these uncompleted changes incur interest on top of interest, making it cumbersome to build a project. Although the term is used in software development primarily, it can also be applied to other professions.