In either case, remember to delete each array that you allocate.

Size: px
Start display at page:

Download "In either case, remember to delete each array that you allocate."

Transcription

1 CS 103 Path-so-logical 1 Introduction In this programming assignment you will write a program to read a given maze (provided as an ASCII text file) and find the shortest path from start to finish. 2 Techniques Used 1. Using file streams to perform text file I/O 2. Performing dynamic memory allocation of arrays and understanding 2D arrays. 3. Applying the backtracking Breadth-First-Search algorithm. 4. Implement and utilize a simple queue. 3 Background Information and Notes The input maze file format is as follows. The first line of the file contains two integer numbers indicating the row and column size of the maze. The number of rows indicated will determine how many lines of text follow (1 row per line). On each line will be one character for each of the indicated number of columns followed by a newline character. The characters can be a period (.) indicating a space in the maze, a # sign indicating a wall in the maze, an S indicating the start location for your search, or an F for the desired finish location. You can t go outside the grid. (I.e., you may think that walls surround the maze perimeter.) Sample Input File 4 4..#...#S F.#.... General File Format rows cols <col characters>\n... <col characters>\n Character Meaning. (period) Free space in the maze # Wall in the maze S Start location in the maze F Finish location in the maze Your search algorithm will find a shortest path from the start cell to the finish. Indicate this path by filling in the character locations on the path with asterisks (*); then, write the resulting character maze to an output text file. E.g., Output File 4 4..#...#S F*#*.*** Sometimes, no path exists. In this case your program will just output No path could be found! to the screen instead. Last Revised: 10/19/2014 1

2 Breadth-First Search (BFS): Breadth First Search is a general technique with many uses including flood filling, shortest paths, and meet-in-the-middle search. The idea is to explore every possible valid location, beginning at the start location, using an ordering so that we always explore ALL locations at a shorter distance from the start/source before exploring any location at a longer distance from the start/source (i.e. all locations at a distance of i are explored before any location at a distance of i+1 from the source). This property ensures that when we do find the finish cell, we ve arrived there via a shortest-length path. As we search we mark cells that we've explored so that we don't explore them again and so the search doesn t run forever. How do we ensure the BFS property (underlined above)? We keep a list of locations in the maze. Initially, we only list the start location. In each iteration, we remove the list s first location from the list, and we add all of its new neighbors to the end of the list. It is not too hard to prove 1 that this simple algorithm successfully implements the BFS. We keep going until either we hit the finish cell (found the shortest path), or until the list becomes empty (no path exists). This behavior, of adding items only to the end of the list, while deleting items only from the start of the list, means that we are implementing a data structure known as a queue. File I/O: You will use an ifstream object to read the maze data in from the given file and an ofstream object to write your results to an output file. Remember you can use the ifstream object like you do cin to read data into variables; and like cin, the ifstream object skips whitespace (including newline characters). By reading the number of rows and columns into two integers initially, you can determine how much input needs to be read. 2-D Array Allocation: You will not know the size of the maze until runtime, when you read the maze data. Thus we will need to dynamically allocate an array to hold the maze data. Remember that new by default can only allocate a 1D array. You will need to allocate some 2D arrays in this assignment. This can be done in two ways. Using new[] once to allocate a 1D array of pointers, then using a loop containing new[] to allocate many 1D arrays. See for examples of that approach. (Click on View Reference Solution.) If the second array dimension is a constant that is known at compile time (like 2), you can use one line: int (*queue)[2] = new int[max_queue_size][2]; In either case, remember to delete each array that you allocate. 1 Each neighbor of a location at distance i from the start must be at distance i-1, i, or i+1 from the start. However, any new neighbor must be at distance i+1, since those at i-1 or i were already listed. And every location at distance i+1 has some neighbor at distance i. This is enough to finish the proof. 2 Last Revised: 10/19/2014

3 4 Requirements Your program shall meet the following requirements for features and approach: 1. Break your program into three files with the given structure: File Description / Function Definitions maze.cpp main(int argc, char *argv[]) Accepts the input filename and output filename as command line arguments Calls other functions int maze_search(char **maze, int rows, int cols) Performs the BFS search for a valid path, filling in the path with * characters if found Returns 1 if a valid path was found, 0 if no path was found, and -1 if an error occurred during the search. Possible errors include inability to find the start ( S ) cell or finish ( F ) cell. maze_io.h maze_io.cpp Prototypes for functions in maze_io.cpp Functions: char ** read_maze(char *filename, int *rows, int *cols ); Reads the maze from the given filename, allocates an array for the maze and returns it. The rows and cols arguments should point to variables that can be filled in with the dimensions of the maze read in from the file. void print_maze(char **maze, int rows, int cols); Prints the maze dimensions and maze contents to the screen in a two dimensional format void write_maze(char *filename, char **maze, int rows, int cols); Like print_maze, but writes to the given filename. 2. A valid path consists of steps north, south, east, and west but no diagonals. Thus we only need to explore neighbors of a cell in those 4 directions, not along diagonals. 3. You must dynamically allocate arrays to hold the maze data, the BFS array/queue, and any other needed arrays. 4. A queue is a data structure with the FIFO property (First-In, First-Out): items go in the back (or tail) but are removed from the front (head). It acts like a list where we write items at the bottom and cross them off as we do them from the top. It serves to help us remember what we have to do (until it is time to actually process it) and in what order the work arrived. To implement the queue s behavior let us allocate a large array (NROWS * NCOLS which is large enough to hold all items if we needed). We will also maintain two integer indices: head (the index of the front item) and tail (the index of the back item). Both should start at 0. When an item is added, it should be placed at the Last Revised: 10/19/2014 3

4 index specified by tail (i.e. 0 for the first item added) and then the tail index should be incremented (i.e. to 1). Another addition to the queue would cause the same behavior (placed at location specified by the tail index and then the tail index incremented). When an item is to be removed and processed, we should always take it from the front (head) index and then increment the head. Equivalently, you can think of tail as counting how many items were added so far, and head as counting how many items were removed. Note that when you delete from the queue, you do NOT move all the other items. You simply move the head counter forwards (leaving the old stuff sitting in its original location). Later in the course you ll learn how to optimize this. For example, here is a queue where, so far, two items were inserted and no items were removed: Head Tail Item Item Now, we must be careful not to try to remove an item if the list is empty. Notice that head and tail will be the same if everything that has been added has also been removed, and tail > head if it is nonempty. 5. Remember the earlier description of how to implement breadth-first search with a queue: BFS Algorithm add start location to BFSQ while BFSQ is not empty do front <- remove earliest item from BFSQ for each neighbor of front if neighbor is open square and unfound set predecessor of neighbor = front add neighbor to BFSQ Note that each item in the queue is a pair of numbers {row, col}. 6. You need to avoid adding any location to the queue more than once. Otherwise, your search can cycle infinitely or exceed the maximum queue size. Here is a bad way to solve this problem: before inserting a location into the queue, search the whole queue to see if it s already there. This is correct but has slow performance, O(NROWS 2 *NCOLS 2 ) worst-case time. Don t do this! Instead, maintain a data structure that remembers, for each grid cell, if it s already been added to the queue or not. Therefore, this data structure should let you look up, for a given pair of indices {row, col}, whether that cell has already 4 Last Revised: 10/19/2014

5 been visited, or not yet visited. What type of structure could you use for this? In your code, allocate and initialize this structure before you start the BFS algorithm. At what step of the BFS algorithm do you have to mark a cell as visited? 7. The final step is actually locating the optimal path and marking it with * characters. This requires a little more bookkeeping, like a trail of breadcrumbs that you can follow from the finish back to the start. In the BFS search, you should utilize a predecessor array (which is of the same size as the queue, and therefore dynamically allocated) to track, for each enqueued location L, the queue location (i.e. array ndex) of L s neighbor that caused L to be explored (the predecessor of L). The predecessor is utilized to find the actual path when your algorithm is complete: we trace it from the finish back to the start. I.e., the predecessor of the finish cell will tell us how to go back one step, then that cell s predecessor will tell us how to go back another step, etc: previous_cell = predecessor[current_cell] At what step of the algorithm will you fill a new entry in the predecessor array? 5 Prelab 1. BEFORE beginning, consider the sample maze shown below and put yourself in place of the BFS. Our examples will explore each cell s neighbors in the order {North, West, South, East}. Show the coordinates of each cell placed in the BFSQ in the appropriate order from the Start node and stopping as soon as the Finish node is entered into the queue. Then for each cell placed in the BFS queue, keep track of how the predecessor array would be updated. Show the predecessor array s FINAL value at the end of the BFS execution. We have started the example for you. Complete it on a separate page. Maze 0123 <- Col. Index Locations Row index -> 0..#. 0,0 0,1 0,2 0,3 1..#S 1,0 1,1 1,2 1,3 2 F.#. 2,0 2,1 2,2 2, ,0 3,1 3,2 3,3 BFSQ: (index) value {1, 3}, {0, 3}, {2, 3}, {3, 3} PRED: Next, do the backtracking on this example. Which BFSQ index did the F cell (finish) correspond to? If you backtrack from there, what indices do you pass through? What path through the maze does this correspond to? 3. Fill in the readme.txt file prelab, which asks you about your design of the structure that you use to remember which cells have been visited or not. 6 Procedure Perform the following. Last Revised: 10/19/2014 5

6 1. Create a maze directory in your VM (or wherever you prefer) $ mkdir ~/maze $ cd ~/maze 2. Download the sample mazes and skeleton code to your local directory: $ wget This will download the maze_io header file, Makefile, & 3 sample mazes: maze_io.h Prototypes for the maze file/display I/O maze_io.cpp Code for the I/O routines maze.cpp - Main program and maze_search() algorithm Makefile - Run make to compile your program maze1.in Sample 5 x 5 maze maze2.in Sample 10 x 12 maze maze3.in - Sample maze with no solution path maze4.in Sample maze with an error (no S cell) Checkpoint 1: Input/output: 3. Complete the maze_io.cpp code so that you can read/print/write mazes to and from files. In main() in maze.cpp, write a program that simply reads in the file specified on the command line, prints it to the screen, and writes it out to the specified filename (i.e. the output file should thus be a copy of the input file). 4. Compile and run your program: $ make $./maze maze1.in maze1.copy 5. Check that the printed output and output file look correct. It is okay if your program prints Path successfully found! to the screen. Did you remember to deallocate the dynamic memory? Fill in the ADD CODE HERE part. Checkpoint 2: Core BFS algorithm: 6. Now write the search code in maze_search() a. Find the Start and Finish cells b. Setup and initialize your BFSQ, Predecessor and any other arrays/data structures necessary. c. Perform the Breadth First Search until you find the finish cell or the BFSQ is empty. 7. Does your program successfully distinguish mazes where a path exists, from ones where a path does not? Try it on this input (maze3.in): 2 3 F#..#S If need be, print out the location of each item you add or remove to the queue for debugging purposes, and print out the r,c index of the Finish cell when found. Final Product: 1. Now add the code to walk the predecessor array backwards to the start location filling in the cells with * 2. Return the status code: 1=success, 0=no shortest path exists, -1=error 3. Make sure your code meets all the requirements given earlier in this handout. 4. Make sure all dynamically allocated memory is deallocated. 6 Last Revised: 10/19/2014

7 5. Comment your code as you write your program documenting what abstract operation a certain for, while, or if statement is performing as well as other decisions you make along the way that feel particular to your approach. 6. Compile your program: $ make 7. Run your program: $./maze maze1.in maze1.out 8. Verify your program s outputs and run the program again on the other sample cases. 9. Create your own sample input mymaze.txt that tests if the algorithm is actually returning a shortest path? So your test case should have multiple paths from start to finish, of different lengths. Once you ve verified that your program behaves as expected, upload it along with your submission. 7 Rubric 3 points: Readme completed; get it from 5 points: Follows required API and division of functionality into files, has correct return values 5 points: Opens files, reads input and prints output correctly 7 points: Allocates and deallocates memory correctly 10 points: BFS functionality: Finds start, uses queue insert-and-delete algorithm, checks all 4 neighbors, stays in bounds, updates predecessor array, correctness 4 points: Backtracks, draws asterisks through maze along shortest path 4 points: Style and documentation 2 points: Submitted mymaze.txt Last Revised: 10/19/2014 7

CS103L PA4. March 25, 2018

CS103L PA4. March 25, 2018 CS103L PA4 March 25, 2018 1 Introduction In this assignment you will implement a program to read an image and identify different objects in the image and label them using a method called Connected-component

More information

EE 352 Lab 3 The Search Is On

EE 352 Lab 3 The Search Is On EE 352 Lab 3 The Search Is On Introduction In this lab you will write a program to find a pathway through a maze using a simple (brute-force) recursive (depth-first) search algorithm. 2 What you will learn

More information

CS 103 The Social Network

CS 103 The Social Network CS 103 The Social Network 1 Introduction This assignment will be part 1 of 2 of the culmination of your C/C++ programming experience in this course. You will use C++ classes to model a social network,

More information

CS 103 Six Degrees of Kevin Bacon

CS 103 Six Degrees of Kevin Bacon CS 103 Six Degrees of Kevin Bacon 1 Introduction This is the second half of the previous assignment, and acts as the culmination of your C/C++ programming experience in this course. You will use certain

More information

CS201 - Assignment 7 Due: Wednesday April 16, at the beginning of class

CS201 - Assignment 7 Due: Wednesday April 16, at the beginning of class CS201 - Assignment 7 Due: Wednesday April 16, at the beginning of class http://xkcd.com/205/ For this assignment, we re going to be playing a bit with stacks and queues. Make sure you read through the

More information

CS 103 Unit 11. Linked Lists. Mark Redekopp

CS 103 Unit 11. Linked Lists. Mark Redekopp 1 CS 103 Unit 11 Linked Lists Mark Redekopp 2 NULL Pointer Just like there was a null character in ASCII = '\0' whose ue was 0 There is a NULL pointer whose ue is 0 NULL is "keyword" you can use in C/C++

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

EE 355 PA4 A* Is Born

EE 355 PA4 A* Is Born EE 355 PA4 A* Is Born 1 Introduction In this programming assignment you will implement the game AI for a sliding tile game. You will use an A* search algorithm to suggest a sequence of moves to solve the

More information

Lab 9: Pointers and arrays

Lab 9: Pointers and arrays CMSC160 Intro to Algorithmic Design Blaheta Lab 9: Pointers and arrays 3 Nov 2011 As promised, we ll spend today working on using pointers and arrays, leading up to a game you ll write that heavily involves

More information

Lab 12: Lijnenspel revisited

Lab 12: Lijnenspel revisited CMSC160 Intro to Algorithmic Design Blaheta Lab 12: Lijnenspel revisited 16 April 2015 Today s lab will revisit and rework the Lijnenspel game code from Lab 7, possibly using my version as a starting point.

More information

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014

CMPSCI 250: Introduction to Computation. Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014 CMPSCI 250: Introduction to Computation Lecture #24: General Search, DFS, and BFS David Mix Barrington 24 March 2014 General Search, DFS, and BFS Four Examples of Search Problems State Spaces, Search,

More information

CS 2704 Project 3 Spring 2000

CS 2704 Project 3 Spring 2000 Maze Crawler For this project, you will be designing and then implementing a prototype for a simple game. The moves in the game will be specified by a list of commands given in a text input file. There

More information

CS 103 Lab The Files are *In* the Computer

CS 103 Lab The Files are *In* the Computer CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn

More information

LAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

LAB #8. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: LAB #8 Each lab will begin with a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs will in the demo. It is

More information

Recitation 2/18/2012

Recitation 2/18/2012 15-213 Recitation 2/18/2012 Announcements Buflab due tomorrow Cachelab out tomorrow Any questions? Outline Cachelab preview Useful C functions for cachelab Cachelab Part 1: you have to create a cache simulator

More information

CS 103 Unit 11. Linked Lists. Mark Redekopp

CS 103 Unit 11. Linked Lists. Mark Redekopp 1 CS 103 Unit 11 Linked Lists Mark Redekopp 2 NULL Pointer Just like there was a null character in ASCII = '\0' whose ue was 0 There is a NULL pointer whose ue is 0 NULL is "keyword" you can use in C/C++

More information

EE 355 OCR PA You Better Recognize

EE 355 OCR PA You Better Recognize EE 355 OCR PA You Better Recognize Introduction In this programming assignment you will write a program to take a black and white (8-bit grayscale) image containing the bitmap representations of a set

More information

Carnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016

Carnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016 1 Cache Lab Recitation 7: Oct 11 th, 2016 2 Outline Memory organization Caching Different types of locality Cache organization Cache lab Part (a) Building Cache Simulator Part (b) Efficient Matrix Transpose

More information

CS 103 Chroma Key. 1 Introduction. 2 What you will learn. 3 Background Information and Notes

CS 103 Chroma Key. 1 Introduction. 2 What you will learn. 3 Background Information and Notes CS 103 Chroma Key 1 Introduction In this assignment you will perform a green-screen or chroma key operation. You will be given an input image (e.g. Stephen Colbert) with a green background. First, you

More information

Tutorial 1 C Tutorial: Pointers, Strings, Exec

Tutorial 1 C Tutorial: Pointers, Strings, Exec TCSS 422: Operating Systems Institute of Technology Spring 2017 University of Washington Tacoma http://faculty.washington.edu/wlloyd/courses/tcss422 Tutorial 1 C Tutorial: Pointers, Strings, Exec The purpose

More information

EE355 Lab 5 - The Files Are *In* the Computer

EE355 Lab 5 - The Files Are *In* the Computer 1 Introduction In this lab you will modify a working word scramble game that selects a word from a predefined word bank to support a user-defined word bank that is read in from a file. This is a peer evaluated

More information

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10;

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10; Solving a 2D Maze Let s use a 2D array to represent a maze. Let s start with a 10x10 array of char. The array of char can hold either X for a wall, for a blank, and E for the exit. Initially we can hard-code

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Java Review. Fundamentals of Computer Science

Java Review. Fundamentals of Computer Science Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions

More information

Data Types primitive, arrays, objects Java overview Primitive data types in Java

Data Types primitive, arrays, objects Java overview Primitive data types in Java Data Types primitive, arrays, objects Java overview Primitive data types in Java 46 Recap Day 2! Lessons Learned:! Sample run vs. pseudocode! Java program structure: set-up, then real statements, decent

More information

a f b e c d Figure 1 Figure 2 Figure 3

a f b e c d Figure 1 Figure 2 Figure 3 CS2604 Fall 2001 PROGRAMMING ASSIGNMENT #4: Maze Generator Due Wednesday, December 5 @ 11:00 PM for 125 points Early bonus date: Tuesday, December 4 @ 11:00 PM for 13 point bonus Late date: Thursday, December

More information

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.

CS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey. CS 1114: Implementing Search! Prof. Graeme Bailey http://cs1114.cs.cornell.edu (notes modified from Noah Snavely, Spring 2009) Last time! Graph traversal 1 1 2 10 9 2 3 6 3 5 6 8 5 4 7 9 4 7 8 10! Two

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 Due: Wednesday, October 18, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 In this week s lab, you will write a program that can solve

More information

LAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS.

LAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS. LAB #8 Each lab will begin with a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs will in the demo. It is

More information

Search in discrete and continuous spaces

Search in discrete and continuous spaces UNSW COMP3431: Robot Architectures S2 2006 1 Overview Assignment #1 Answer Sheet Search in discrete and continuous spaces Due: Start of Lab, Week 6 (1pm, 30 August 2006) The goal of this assignment is

More information

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7 CS 220: Introduction to Parallel Computing Input/Output Lecture 7 Input/Output Most useful programs will provide some type of input or output Thus far, we ve prompted the user to enter their input directly

More information

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 CS17 Integrated Introduction to Computer Science Klein Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 Contents 1 Reverse (Practice) 4 2 Main Diagonal (Practice) 5 3 Horizontal Flip 6 4 Vertical Flip

More information

Programming Assignment Multi-Threading and Debugging 2

Programming Assignment Multi-Threading and Debugging 2 Programming Assignment Multi-Threading and Debugging 2 Due Date: Friday, June 1 @ 11:59 pm PAMT2 Assignment Overview The purpose of this mini-assignment is to continue your introduction to parallel programming

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Autumn 2012 October 29 th, 2012 CS106X Midterm Examination Solution

Autumn 2012 October 29 th, 2012 CS106X Midterm Examination Solution CS106X Handout 25S Autumn 2012 October 29 th, 2012 CS106X Midterm Examination Solution Thanks to TA Ben Holtz and the gaggle of CS106X section leaders, your midterms are graded and are available for pickup.

More information

Homework 7: Sudoku. Preliminaries. Overview

Homework 7: Sudoku. Preliminaries. Overview Homework 7: Sudoku For this assignment, you will write a Sudoku solver. To do so, you will (1) use Scala collections extensively, (2) implement a backtracking search algorithm, and (3) implement constraint

More information

Blocky: A Game of Falling Blocks

Blocky: A Game of Falling Blocks ECE220: Computer Systems and Programming Machine Problem 6 Spring 2018 Honors Section due: Thursday 1 March, 11:59:59 p.m. Blocky: A Game of Falling Blocks Your task this week is to implement a game of

More information

Starting to Program in C++ (Basics & I/O)

Starting to Program in C++ (Basics & I/O) Copyright by Bruce A. Draper. 2017, All Rights Reserved. Starting to Program in C++ (Basics & I/O) On Tuesday of this week, we started learning C++ by example. We gave you both the Complex class code and

More information

HOT-Compilation: Garbage Collection

HOT-Compilation: Garbage Collection HOT-Compilation: Garbage Collection TA: Akiva Leffert aleffert@andrew.cmu.edu Out: Saturday, December 9th In: Tuesday, December 9th (Before midnight) Introduction It s time to take a step back and congratulate

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

More information

Warm-up sheet: Programming in C

Warm-up sheet: Programming in C Warm-up sheet: Programming in C Programming for Embedded Systems Uppsala University January 20, 2015 Introduction Here are some basic exercises in the programming language C. Hopefully you already have

More information

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis Handout written by Julie Zelenski with edits by Keith Schwarz. The Goal In the first programming project, you will get

More information

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019

CMSC162 Intro to Algorithmic Design II Blaheta. Lab March 2019 CMSC162 Intro to Algorithmic Design II Blaheta Lab 10 28 March 2019 This week we ll take a brief break from the Set library and revisit a class we saw way back in Lab 4: Card, representing playing cards.

More information

Operating Systems and Networks Assignment 2

Operating Systems and Networks Assignment 2 Spring Term 2014 Operating Systems and Networks Assignment 2 Assigned on: 27th February 2014 Due by: 6th March 2014 1 Scheduling The following table describes tasks to be scheduled. The table contains

More information

CS2255 HOMEWORK #1 Fall 2012

CS2255 HOMEWORK #1 Fall 2012 CS55 HOMEWORK #1 Fall 01 1.What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; a. 10 b. 7 c. The

More information

Lab 12 Lijnenspel revisited

Lab 12 Lijnenspel revisited CMSC160 Intro to Algorithmic Design Blaheta Lab 12 Lijnenspel revisited 24 November 2015 Reading the code The drill this week is to read, analyse, and answer questions about code. Regardless of how far

More information

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable Today in CS161 Lecture #12 Arrays Learning about arrays Being able to store more than one item using a variable Examples Tic Tac Toe board as an array Graphical User interaction for the tic tac toe program

More information

Project #1 Exceptions and Simple System Calls

Project #1 Exceptions and Simple System Calls Project #1 Exceptions and Simple System Calls Introduction to Operating Systems Assigned: January 21, 2004 CSE421 Due: February 17, 2004 11:59:59 PM The first project is designed to further your understanding

More information

The Maze Runner. Alexander Kirillov

The Maze Runner. Alexander Kirillov The Maze Runner URL: http://sigmacamp.org/mazerunner E-mail address: shurik179@gmail.com Alexander Kirillov This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License.

More information

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we have to talk about the way in which we represent the

More information

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them. Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs

More information

CS106X Handout 17 Winter 2015 January 28 th, 2015 CS106X Practice Exam

CS106X Handout 17 Winter 2015 January 28 th, 2015 CS106X Practice Exam CS106X Handout 17 Winter 2015 January 28 th, 2015 CS106X Practice Exam Exam Facts: When: Thursday, February 5 th from 7:00 10:00 p.m. Where: Cubberley Auditorium Coverage The exam is open-book, open-note,

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20.

CS355 Hw 4. Interface. Due by the end of day Tuesday, March 20. Due by the end of day Tuesday, March 20. CS355 Hw 4 User-level Threads You will write a library to support multiple threads within a single Linux process. This is a user-level thread library because the

More information

COP 3014: Spring 2019 Homework 6

COP 3014: Spring 2019 Homework 6 COP 3014: Spring 2019 Homework 6 Total Points: 200 (plus 50 points extra credit) Due: Thursday, 04/25/2018 11:59 PM 1 Objective The objective of this assignment is to make sure: You are familiar with dynamic

More information

Assignment #1: and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th due: 11:59pm on Sunday, October 6th

Assignment #1:  and Karel the Robot Karel problems due: 3:15pm on Friday, October 4th  due: 11:59pm on Sunday, October 6th Mehran Sahami Handout #7 CS 06A September, 0 Assignment #: Email and Karel the Robot Karel problems due: :pm on Friday, October th Email due: :9pm on Sunday, October 6th Part I Email Based on a handout

More information

Programming assignment A

Programming assignment A Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Pointers and References

Pointers and References Steven Zeil October 2, 2013 Contents 1 References 2 2 Pointers 8 21 Working with Pointers 8 211 Memory and C++ Programs 11 212 Allocating Data 15 22 Pointers Can Be Dangerous 17 3 The Secret World of Pointers

More information

15-122: Principles of Imperative Computation, Fall 2015

15-122: Principles of Imperative Computation, Fall 2015 15-122 Programming 5 Page 1 of 10 15-122: Principles of Imperative Computation, Fall 2015 Homework 5 Programming: Clac Due: Thursday, October 15, 2015 by 22:00 In this assignment, you will implement a

More information

Lecture Notes on Queues

Lecture Notes on Queues Lecture Notes on Queues 15-122: Principles of Imperative Computation Frank Pfenning Lecture 9 September 25, 2012 1 Introduction In this lecture we introduce queues as a data structure and linked lists

More information

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue Agenda hw4 being graded hw5 may be graded first, for feedback to be used on hw6 hw6 due next week Today hw6 BFS Debugging hashcode()

More information

CS102: Variables and Expressions

CS102: Variables and Expressions CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

More information

COP Programming Assignment #7

COP Programming Assignment #7 1 of 5 03/13/07 12:36 COP 3330 - Programming Assignment #7 Due: Mon, Nov 21 (revised) Objective: Upon completion of this program, you should gain experience with operator overloading, as well as further

More information

ENGR 40M Project 3c: Switch debouncing

ENGR 40M Project 3c: Switch debouncing ENGR 40M Project 3c: Switch debouncing For due dates, see the overview handout 1 Introduction This week, you will build on the previous two labs and program the Arduino to respond to an input from the

More information

APCS-AB: Java. Recursion in Java December 12, week14 1

APCS-AB: Java. Recursion in Java December 12, week14 1 APCS-AB: Java Recursion in Java December 12, 2005 week14 1 Check point Double Linked List - extra project grade Must turn in today MBCS - Chapter 1 Installation Exercises Analysis Questions week14 2 Scheme

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

Today in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1

Today in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1 Today in CS162 External Files What is an external file? How do we save data in a file? CS162 External Data Files 1 External Files So far, all of our programs have used main memory to temporarily store

More information

Programming Assignment HW4: CPU Scheduling v03/17/19 6 PM Deadline March 28th, 2019, 8 PM. Late deadline with penalty March 29th, 2019, 8 PM

Programming Assignment HW4: CPU Scheduling v03/17/19 6 PM Deadline March 28th, 2019, 8 PM. Late deadline with penalty March 29th, 2019, 8 PM CS 370: OPERATING SYSTEMS SPRING 2019 Department of Computer Science URL: http://www.cs.colostate.edu/~cs370 Colorado State University INSTRUCTOR: Yashwant Malaiya Programming Assignment HW4: CPU Scheduling

More information

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0. CSCI0330 Intro Computer Systems Doeppner Lab 02 - Tools Lab Due: Sunday, September 23, 2018 at 6:00 PM 1 Introduction 0 2 Assignment 0 3 gdb 1 3.1 Setting a Breakpoint 2 3.2 Setting a Watchpoint on Local

More information

Assignment #1: /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th

Assignment #1:  /Survey and Karel the Robot Karel problems due: 1:30pm on Friday, October 7th Mehran Sahami Handout #7 CS 06A September 8, 06 Assignment #: Email/Survey and Karel the Robot Karel problems due: :0pm on Friday, October 7th Email and online survey due: :9pm on Sunday, October 9th Part

More information

Grad AI Fall, 2007 Homework 1

Grad AI Fall, 2007 Homework 1 Grad AI. 15-780 Fall, 2007 Homework 1 Homework deadline: 10:30am on October 4 Please print your code and hand it in with the hard copy of your homework. Also send a copy of your code by e-mail to both

More information

Programming Assignment HW5: CPU Scheduling draft v04/02/18 4 PM Deadline April 7th, 2018, 5 PM. Late deadline with penalty April 9th, 2018, 5 PM

Programming Assignment HW5: CPU Scheduling draft v04/02/18 4 PM Deadline April 7th, 2018, 5 PM. Late deadline with penalty April 9th, 2018, 5 PM Programming Assignment HW5: CPU Scheduling draft v04/02/18 4 PM Deadline April 7th, 2018, 5 PM. Late deadline with penalty April 9th, 2018, 5 PM Purpose: The objective of this assignment is to become familiar

More information

CS4023 Week06 Lab Exercise

CS4023 Week06 Lab Exercise CS4023 Week06 Lab Exercise Lab Objective: In this week s lab we will look at writing a program that reads a large matrix of numbers and then reports all numbers that are equal to a reference value (or

More information

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY Pages 800 to 809 Anna Rakitianskaia, University of Pretoria STATIC ARRAYS So far, we have only used static arrays The size of a static array must

More information

Mehran Sahami Handout #7 CS 106A September 24, 2014

Mehran Sahami Handout #7 CS 106A September 24, 2014 Mehran Sahami Handout #7 CS 06A September, 0 Assignment #: Email/Survey and Karel the Robot Karel problems due: :pm on Friday, October rd Email and online survey due: :9pm on Sunday, October th Part I

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

CSCI 204 Introduction to Computer Science II

CSCI 204 Introduction to Computer Science II CSCI 204 Project 2 Maze Assigned: Wednesday 09/27/2017 First Phase (Recursion) Due Friday, 10/06/2017 Second Phase (Stack) Due Monday, 10/16/2017 1 Objective The purpose of this assignment is to give you

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

Pebbles Kernel Specification September 26, 2004

Pebbles Kernel Specification September 26, 2004 15-410, Operating System Design & Implementation Pebbles Kernel Specification September 26, 2004 Contents 1 Introduction 2 1.1 Overview...................................... 2 2 User Execution Environment

More information

University of Colorado at Colorado Springs CS4500/ Fall 2018 Operating Systems Project 1 - System Calls and Processes

University of Colorado at Colorado Springs CS4500/ Fall 2018 Operating Systems Project 1 - System Calls and Processes University of Colorado at Colorado Springs CS4500/5500 - Fall 2018 Operating Systems Project 1 - System Calls and Processes Instructor: Yanyan Zhuang Total Points: 100 Out: 8/29/2018 Due: 11:59 pm, Friday,

More information

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

CS 241 Data Organization using C Project 3: Tron Spring 2017

CS 241 Data Organization using C Project 3: Tron Spring 2017 CS 241 Data Organization using C Project 3: Tron Spring 2017 Instructor: Joel Castellanos e-mail: joel@unm.edu Web: http://cs.unm.edu/~joel/ 4/29/2017 Tron Spring 2017: Project Outline (1 of 3) 1) The

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Queues-based algorithms Asynchronous processes Simulations State-space search Version of March

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday)

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) CS 215 Fundamentals of Programming II Spring 2017 Programming Project 7 30 points Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) This project

More information

2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined):

2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined): 2-D Arrays We define 2-D arrays similar to 1-D arrays, except that we must specify the size of the second dimension. The following is how we can declare a 5x5 int array: int grid[5][5]; Essentially, this

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

CMPUT 396 Sliding Tile Puzzle

CMPUT 396 Sliding Tile Puzzle CMPUT 396 Sliding Tile Puzzle Sliding Tile Puzzle 2x2 Sliding Tile States Exactly half of the states are solvable, the other half are not. In the case of 2x2 puzzles, I can solve it if I start with a configuration

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Eat (we provide) link. Eater. Goal: Eater(Self) == Self()

Eat (we provide) link. Eater. Goal: Eater(Self) == Self() 15-251: Great Theoretical Ideas Guru: Yinmeng Zhang Assignment 12 Due: December 6, 2005 1 Reading Comprehension (0 points) Read the accompanying handout containing Ken Thompson s Turing Award Lecture,

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges

More information

Programming Assignment 1 (PA1) - Display Bowtie

Programming Assignment 1 (PA1) - Display Bowtie Programming Assignment 1 (PA1) - Display Bowtie Milestone Due: Final Due: Wednesday, April 18 @ 11:59 pm Wednesday, April 25 @ 11:59 pm Example Input Milestone Functions Unit Testing Extra Credit Detailed

More information

[2:3] Linked Lists, Stacks, Queues

[2:3] Linked Lists, Stacks, Queues [2:3] Linked Lists, Stacks, Queues Helpful Knowledge CS308 Abstract data structures vs concrete data types CS250 Memory management (stack) Pointers CS230 Modular Arithmetic !!!!! There s a lot of slides,

More information

Some major graph problems

Some major graph problems CS : Graphs and Blobs! Prof. Graeme Bailey http://cs.cs.cornell.edu (notes modified from Noah Snavely, Spring 009) Some major graph problems! Graph colouring Ensuring that radio stations don t clash! Graph

More information

LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS

LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS Questions are based on the Main and Savitch review questions for chapter 5 in the Exam Preparation section of the webct course page. In case you haven t observed

More information