ECSE 321 Assignment 2

Similar documents
Excel Functions & Tables

CS Programming I: Arrays

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Lecture 10: Boolean Expressions

DATE OF BIRTH SORTING (DBSORT)

CMIS 102 Hands-On Lab

CS 455 Midterm 2 Spring 2018 [Bono] Apr. 3, 2018

Section 1.2: What is a Function? y = 4x

Lecture 6. Drinking. Nested if. Nested if s reprise. The boolean data type. More complex selection statements: switch. Examples.

CSE 341 Section Handout #6 Cheat Sheet

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

CSE P 501 Exam 8/5/04

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

STUDENT LESSON A12 Iterations

CS 367: Introduction to Data Structures Midterm Sample Questions

CS 211 Programming Practicum Spring 2017

This report is based on sampled data. Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec 28 Feb 1 Mar 8 Apr 12 May 17 Ju

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

CSE 142, Autumn 2007 Midterm Exam, Friday, November 2, 2007

Contract-based Programming in Ada 2012 A Tutorial

Syntax and Variables

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values

Essentials. Week by. Week. All About Data. Algebra Alley

High Performance Computing

4. ENCOUNTER DATA PROCESSING PROCEDURES A. General Information

COMP322 - Introduction to C++ Lecture 01 - Introduction

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

Exam 2 ITEC 120 Principles of Computer Science I Spring: 2017

CS111: PROGRAMMING LANGUAGE II

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Topics. Chapter 5. Equality Operators

Programming Languages. Function-Closure Idioms. Adapted from Dan Grossman's PL class, U. of Washington

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

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

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

BANGLADESH UNIVERSITY OF PROFESSIONALS ACADEMIC CALENDAR FOR MPhil AND PHD PROGRAM 2014 (4 TH BATCH) PART I (COURSE WORK)

CSE 247 Data Structures and Algorithms Fall Exam I

Computer Science II Data Structures

CMPE/SE 135 Object-Oriented Analysis and Design

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

CS 1110 Prelim 1 March 7th, 2013

CS 323 Lecture 1. Design and Analysis of Algorithms. Hoeteck Wee

CSE 143, Winter 2010 Midterm Exam Wednesday February 17, 2010

ADVANCED SPREADSHEET APPLICATIONS (07)

Asks for clarification of whether a GOP must communicate to a TOP that a generator is in manual mode (no AVR) during start up or shut down.

Software and Programming 1

Lecture Notes: ESC 101

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Midterm Exam 2 CS 455, Spring 2011

CS 211 Programming Practicum Fall 2018

Administrivia. Last modified: Fri Aug 25 10:59: CS61B: Lecture #2 1

Ohad Barzilay and Oranit Dror

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004

CSE 331 Midterm Exam 2/13/12

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

Dictionaries. Looking up English words in the dictionary. Python sequences and collections. Properties of sequences and collections

CompSci 105 S2 C - ASSIGNMENT TWO -

typedef int Array[10]; String name; Array ages;

EE 352 Lab 3 The Search Is On

CS 455 Midterm 2 Fall 2017 [Bono] Nov. 7, 2017

( &% class MyClass { }

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

Functional Programming. Lecture 2: Algebra

ESC101 : Fundamental of Computing

CMPS115 Winter 2004 Exam #2 OPEN BOOK/NOTE WORK ALONE (NO TEAMS) COVERS: Lectures 6 17

CSE 143 SAMPLE MIDTERM

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

CS 211 Programming Practicum Spring 2018

Introduction to Computer Science II (ITI 1121) Midterm Examination

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

3. EXCEL FORMULAS & TABLES

Project 1: Implementation of the Stack ADT and Its Application

UAE PUBLIC TRAINING CALENDAR

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

Lecture 1 Getting Started with SAS

YOU ARE ALLOWED TO HAVE ONLY THE FOLLOWING ON YOUR DESK OR WORKTABLE:

Lecture 14. Dynamic Memory Allocation

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

Math 180 Written Homework Solutions Assignment #1 Due Thursday, September 4th at the beginning of your discussion class.

Announcements. 1. Forms to return today after class:

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

CS 314 Exam 2 Spring 2018

Question 1. tmp = Stack() # Transfer every item from stk onto tmp. while not stk.is_empty(): tmp.push(stk.pop())

Claremont McKenna College Computer Science

Data Structures. BSc in Computer Science University of New York, Tirana. Assoc. Prof. Marenglen Biba 1-1

CSE 131 Introduction to Computer Science Fall Exam II

How It All Stacks Up - or - Bar Charts with Plotly. ISC1057 Janet Peterson and John Burkardt Computational Thinking Fall Semester 2016

CS61BL: Data Structures & Programming Methodology Summer 2014

CIMA Asia. Interactive Timetable Live Online

Problem Set 5 Due: Friday, November 2

Introduction to Computer Science II (CSI 1101)

COS 226 Midterm Exam, Spring 2009

Midterm Exam 2 CS 455, Spring 2015

Data Structure and Algorithm Homework #1 Due: 1:20pm, Tuesday, March 21, 2017 TA === Homework submission instructions ===

MIDTERM REVIEW. midterminformation.htm

CSIS 10B Lab 2 Bags and Stacks

Types, Operators and Expressions

Transcription:

ECSE 321 Assignment 2 Instructions: This assignment is worth a total of 40 marks. The assignment is due by noon (12pm) on Friday, April 5th 2013. The preferred method of submission is to submit a written hardcopy of your answers to the assignment box located at the second floor of Trottier building. The assignment is to be completed individually. You may discuss solutions with classmates, but the final work you submit must be written by you in your own words. Late assignments are subject to a penalty of 5% of the maximum available marks per day late. All late assignments are to be submitted in the instructor s mailbox, located in McConnell 633, and a message should also be sent to instructor and TA that the assignment is there. Question 1 Designing by Contract (9 Marks) Based on the following description of the class Stack, write out some skeleton Java code using Contract4J syntax to define invariant, precondition, and postcondition rules. Recall that Contract4J uses the annotations @Contract, @Pre, @Post, and @Invar, and it also uses the variable $return to denote the value returned by a method. In Contract4J, you can also use the variable $old in a postcondition to refer to a value before the method is called, you can use the variable $this to refer to the current instance of a class, and you can use the variable $args[i] to refer to the ith argument of a method. For example, a postcondition for a method incrementby(int amount) could be @Post ( $this.value = $old($this.value) + $args[0] ). A Stack is a datastructure for last-in first-out storage of Items. Stack has five public methods: isempty() returns a boolean that is true if the stack is empty and false otherwise count() returns an integer with the number of items in the stack top() returns the topmost Item on the stack without removing it push(item) pushes a new Item onto the top of the stack pop() returns the topmost Item on the stack and removes it Write a skeleton for class Stack that has two invariants (hint: the value returned by isempty() should always be consistent with count(); also, what is the value range of count()?), and isempty() has one postcondition, top() has one precondition, push() has three postconditions, and pop() has one precondition and one postcondition. Solution: @Contract public class Stack { @Invar ( (isempty()) == (count() == 0) ) @Invar ( count() >= 0 ) @Post ( $return == (count() == 0) ) public boolean isempty() {... public int count() { 1/6

@Pre ( count() > 0 ) // could also be!isempty() public Item top() { @Post ( count() = $old(count()) + 1 ) @Post ( top() = $args[0] ) @Post (!isempty() ) public void push(item newitem) { @Pre ( count() > 0 ) @Post ( count() = $old(count()) - 1 ) public Item pop() { Question 2: Black-box Testing (14 Marks) We have a new marking system that takes a.in file as an argument and produces a sorted.out file as specified below. Input File: The input file format is as follows. Each line will contain the data for a single student. The input will contain the following fields. A semicolon separates each field. Input fields: Student number (9 digit number) Month of Birth (As a 3 character case insensitive string e.g. Jan, FEB, mar,... Dec) Date of Birth (1-31, but must be valid for the month) First name (String of letters without numbers) First letter of surname (Letter) Number of missed lectures (0-26) Slept during one or more lectures (true/false, written as T or F) Example: Student number: 199226129 Month of Birth: May Date of Birth: 26 First name: Kevin First letter of surname: C Number of missed lectures: 0 Never slept during lectures. Input line corresponding to the example: 199226129;May;26;Kevin;C;0;F If any input row is invalid, the program should print a warning message and continue with the next record. If the program encounters a more serious problem (e.g., unable to open input file), it will print an error message and exit gracefully. Output File: The output file format is as follows. Each line will contain the data for a single student. The output will contain the following fields. Each field is separated by a semicolon. 2/6

Output fields: Student number (9 digit number) Assignment 1 mark: (0-5) Assignment 2 mark: (0-25) Assignment 3 mark: (0-10) Exam mark: (0-60) Final grade: [F, D, C, B-, B, B+, A-, A] Comment: (String of arbitrary length) Example: Student number: 199226129 Assignment 1 mark: 5 Assignment 2 mark: 25 Assignment 3 mark: 10 Exam mark: 60 Final grade: A Comment: Excellent. Output line corresponding to the example: 199226129;5;25;10;60;A;Excellent Questions: 1) What is the range of possible legitimate inputs for this system? (7 marks) Solution: - Student number: integers 000000000 to 999999999 - Month of birth: strings Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec (not case sensitive) - Date of birth: 1 to 31 (valid for the month) - First name: all possible combination of strings [A, Z] [a, z] of any size - First letter of surname: exactly one character from [A, Z] [a, z] - Number of missed lectures: integer 0 to 26 - Slept during one or more lectures: string T or F 2) Derive input test-cases for the program using boundary value analysis. (7 marks) Solution: Test studentid: - (blank); May; 26; Kevin; C; 0; T - tt; May; 26; Kevin; C; 0; T - 998; May; 26; Kevin; C; 0; T - -111; May; 26; Kevin; C; 0; T - 1000000000; May; 26; Kevin; C; 0; T Test month: - 111111111; (blank); 26; Kevin; C; 0; T - 111111111; 05; 26; Kevin; C; 0; T - 111111111; TTT; 26; Kevin; C; 0; T - 111111111; February; 26; Kevin; C; 0; T - 111111111; Feb; 26; Kevin; C; 0; T 3/6

Test day: - 111111111; Jan; (blank); Kevin; C; 0; T - 111111111; Jan; 0; Kevin; C; 0; T - 111111111; Jan; -1; Kevin; C; 0; T - 111111111; Feb; 30; Kevin; C; 0; T - 111111111; Feb; 31; Kevin; C; 0; T - 111111111; Apr; 31; Kevin; C; 0; T - 111111111; Jun; 31; Kevin; C; 0; T - 111111111; Sep; 31; Kevin; C; 0; T - 111111111; Nov; 31; Kevin; C; 0; T - 111111111; Dec; 32; Kevin; C; 0; T - 111111111; Jan; o; Kevin; C; 0; T Test firstname: - 111111111; Feb; 26; (blank); C; 0; T - 111111111; Feb; 26; Kevin7; C; 0; T - 111111111; Feb; 26; Kevin#; C; 0; T - 111111111; Feb; 26; 999; C; 0; T Test first letter of last name: - 111111111; Feb; 26; Kevin; (blank); 0; T - 111111111; Feb; 26; Kevin; 9; 0; T - 111111111; Feb; 26; Kevin; #; 0; T - 111111111; Feb; 26; Kevin; w ; 0; T - 111111111; Feb; 26; Kevin; TT; 0; T Test number of missed lectures: - 111111111; Feb; 26; Kevin; C; (blank); T - 111111111; Feb; 26; Kevin; C; -1; T - 111111111; Feb; 26; Kevin; C; e; T - 111111111; Feb; 26; Kevin; C; 27; T Test slept during lecture: - 111111111; Feb; 26; Kevin; C; 0; (blank) - 111111111; Feb; 26; Kevin; C; 0; 0-111111111; Feb; 26; Kevin; C; 0; L - 111111111; Feb; 26; Kevin; C; 0; false - 111111111; Feb; 26; Kevin; C; 0;, Problem 3 White-Box Testing (17 marks) Consider the following pseudo-code for a method that reads from a file that contains one floating-point value on each line, computes the maximum and minimum values encountered, and then displays information about the range. void findmaxmin(list scorelist) { int numberofscores = 0; float maxscore = NegativeInfinity; float minscore = PositiveInfinity; 1 float nextscore; Iterator iterator = scorelist.iterator(); 4/6

2 while (iterator.hasnext()) { nextscore = scorelist.next(); 3 4 6 if (nextscore > maxscore) { maxscore = nextscore; if (nextscore < minscore) { minscore = nextscore; 5 7 numberofscores++; 8 9 if (numberofscores < 1) { System.out.println( No scores found in score list ); else { System.out.println(numberOfScores + total scores found in score list ); System.out.println( The maximum score is + maxscore); System.out.println( The minimum score is + minscore); 10 11 a. Identify and label each conditional statement and each contiguous block of code (sequence of statements that always execute together). You may mark these directly on the code above [5 marks] Solution: see above b. Draw a logic flow diagram (flow chart) for this method in the space below. [6 marks] Solution: see diagram in the next page c. What is the smallest number of test cases that must be specified in order to test each path through this method? Justify your answer by describing each test in the space provided. [6 marks] Solution: 5 tests are sufficient. File is empty; for the path 1->2->9->10 File with one score (e.g. 50); for the path 1->2->3->4->5->6->7->8->9->11 File with two scores in increasing order (e.g. 50, 100), for the path 1->2->3->4->5->6->8- >9->11 File with two scores in decreasing order (e.g. 50, 20), for the path 1->2->3->4->6->7->8- >9->11 File with three scores where the last score is the median (e.g. 50, 20, 30), for the path 1- >2->3->4->6->8->9->11 Note that the paths 1->2->3.->9->10 are infeasible, i.e. you cannot at the same time enter the while loop (block 2) and make the if statement of block 9 be true. 5/6

Start 1 2 3 4 5 6 7 8 9 10 11 End 6/6