4 Pages

hwII

Course: CIS 15, Fall 2009
School: CUNY Baruch
Rating:
 
 
 
 
 

Word Count: 1616

Document Preview

assignment cis15-fall2008-azhar, II instructions This is assignment for unit II. It is worth 10 points. It is due on Wednesday October 15 and must be submitted by email (as below). Follow these emailing instructions: 1. Create a mail message addressed to mqazhar@gmail.com with the subject line cis15 hw2. 2. Attach ONLY the .cpp source code file created below. 3. Failure to follow these instructions will result...

Register Now

Unformatted Document Excerpt

Coursehero >> New York >> CUNY Baruch >> CIS 15

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
assignment cis15-fall2008-azhar, II instructions This is assignment for unit II. It is worth 10 points. It is due on Wednesday October 15 and must be submitted by email (as below). Follow these emailing instructions: 1. Create a mail message addressed to mqazhar@gmail.com with the subject line cis15 hw2. 2. Attach ONLY the .cpp source code file created below. 3. Failure to follow these instructions will result in points being taken away from your grade. The number of points will be in proportion to the extent to which you did not follow instructions... (which can make it a lot harder for me to grade your work -- grrrr!) program description For this assignment, you will develop a program that simulates a robot moving around in a 2-dimensional world, looking for coins. The robot's current location is represented by an (x, y) point in space. Imagine that the robot has a controller that receives commands one at a time. Each command will tell it to move forward or turn 90 degrees, either clockwise or anti-clockwise. The program will have a broad control loop, and for each iteration of the loop, the robot must decide what to do (i.e., which command to execute). The goal is for the robot to locate all the coins hidden in its world. The robot's world is 10 10 units in size, and the x and y coordinates are in the range [0, 9] (i.e., from 0 to 9, inclusive). You will create 3 classes, each with multiple data and function members, and a main(). Each class is described in detail below, with step-by-step instructions for developing the various components of each class and testing the components individually. In the end, you'll write the main() and put all the pieces together--and this final product is what you'll submit. The intermediary test programs are for your benefit as a developer and should not be submitted. Incidentally, these are called unit tests and are created to let you test and debug the individual units of a complex program. By the end of the semester, you should have gained the skills and experience to devise and construct your own unit tests, without me giving you step-by-step instructions. A. read and store command-line input The program will be named "look-for". It will receive input from the command line indicating the locations of the coins to look for, in the following form: unix$ look-for <coin1-x> <coin1-y> <coin2-x> <coin2-y> <coin3-x> <coin3-y> In other words, the program will take 6 input values, which are pairs of (x, y) coordinates for three coins hidden in the robot's world. 1. Create a point class, as we did in lecture on Wednesday Sep 24. The class should have two int data members: x and y. The class should have four function members: void print() const; This function prints out the values of the data members x and y. 1 void set( int x, int y ); This function sets the values of the data members x and y. Note that since the function arguments are also called x and y, you should use the this-> pointer to disambiguate between the class's data members and the function arguments. int getX() This function returns the value of the x data member. int getY() This function returns the value of the y data member. 2. Create a main() for testing that reads two command-line arguments: x and y; validates, stores and prints them. Check that the user has entered 2 command-line arguments (remember that argc contains the number of command-line arguments, including the name of the C++ program you are running). If not, print an error message and exit the program. Convert the command-line arguments to integers. Hint: use the atoi() function. If you are not familiar with this function, type man atoi at the Unix prompt. Check that the arguments are within the range [0, 9]. If not, print an error message and exit the program. Instantiate a point object (i.e., declare a variable of type point) and store the values of the commandline arguments in that object. Echo the arguments (i.e., display them back to the user). 3. Modify your main() that you created above to read in 6 arguments from the command-line instead of two. Validate them, store each in a point variable and print them all. Again, this main() is also for unit testing. B. establish the robot's world 1. Create a class called world that has one data member and two function members: the data member is an array of three point objects, each one storing the location of one of the 3 coins the robot is looking for void print() const; This function prints out the locations of the three coins. void set( int i, int x, int y ); This function sets the location of the i-th coin in the data member array to (x, y). 2. Modify your main() that you created in part A to instantiate a world object and store the validated and converted arguments command-line in the point array within the world object. Then call the world object's print() function to echo the input. Again, this main() is for unit testing. C. define the robot 1. Create a robot class that has the following data and function members: a point object to store the robot's current location in the world an enumerated data type, called orientation_type, that defines the four directions that the robot could be facing (north, south, east or west), i.e., its "orientation" a variable to store the robot's current orientation void init(); This function initializes the robot's current location to (0, 0) and its current orientation to east. 2 void print() const; This function prints the robot's current location and orientation in a pretty format, such as: I am at (0,0) and I am facing east. void setOrientation( orientation_type orientation ); This function sets the value of the robot's orientation data member. bool forward(); This function simulates the robot moving forward one step in the direction that it is facing. It checks to make sure that the robot is not at the edge of its world. It returns true if the robot moves forward successfully and false if the robot is at the edge of its world and cannot move forward. void turnCW(); This function changes the robot's orientation, simulating a turn in the clockwise direction. void turnAntiCW(); This function changes the robot's orientation, simulating a turn in the anti-clockwise direction. bool eastEnd(); This function returns true if the robot has reached the east edge of its world. bool westEnd(); This function returns true if the robot has reached the west edge of its world. bool northEnd(); This function returns true if the robot has reached the north edge of its world. bool southEnd(); This function returns true if the robot has reached the south edge of its world. bool zag(); This function is called when the robot has been moving east and has reached the east edge of its world, in which case it should turn clockwise, go forward one step south and turn clockwise again (where it will be heading west for its next move). bool zig(); This function is called when the robot has been moving west and has reached the west edge of its world, in which case it should turn anti-clockwise, go forward one step south and turn anti-clockwise again (where it will be heading east for its next move).* 2. Now modify the main() from the previous step to instantiate a world object. Define and perform some unit tests on each of the function members in the world class. For example, first call init() and then call print() to make sure the robot's position and orientation are correctly initialized. Or, call init(); forward(); print(); to verify that forward() works as you expect. Do the same with turnCW(), turnAntiCW(), zig() and zag(). Again, this main() is for y...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

CUNY Baruch - CIS - 1
cis1.5/robotics-spring2008-azhar robotics.edu-agents lab Brooklyn College, CUNY c 2008cis1.5-spring2008-azhar, lab IV, part 3instructions This is the third part of the lab/homework assignment for unit IV. The third part is worth 4 points and opt
CUNY Baruch - CIS - 1
cis1.5/robotics-spring2008-azhar robotics.edu-agents lab Brooklyn College, CUNY c 2008cis1.5-spring2008-azhar, lab IV, part 2instructions This is the second part of the lab/homework assignment for unit IV. The entire assignment will be worth 9 p
CUNY Baruch - CIS - 1
cis1.5-spring2008-azhar, lab V, part 1instructions This is the rst part of the lab/homework assignment for unit V. The entire assignment will be worth 9 points. The rst part is worth 6 points and will be distributed and worked on in class on Mond
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ fall 2007 lecture # IV.1 topics: inheritance composition of classes resources: Pohl, chapters 8 and 11an example consider the program robot.cpp (posted on the class web page) this program models
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ fall 2008 lecture # II.2 topics: ctors and dtors polymorphism and overloading friend classes, composition and derivation resources: Pohl, chapter 5 (mostly sections 5.1-5.3, 5.7, 5.10)ctors and dt
CUNY Baruch - CIS - 1
cis1.5-spring2008-azhar, lab II, part 1instructions This is the first part of the lab/homework assignment for unit II. The entire assignment will be worth 9 points. The first part is worth 4 points and will be distributed and worked on in class o
CUNY Baruch - CIS - 1
today our first c+ program output the software development cycle variables data types data storage binary numbers ASCII assignment and mathematical operators &quot;hello world&quot;our first c+ program. typical first program in any language outpu
CUNY Baruch - CIS - 1
cis1.5 introduction to computing using c+ (robotics applications) spring 2008 lecture # I.1 introduction(0) introduction to the course about this course introduction to computer programming using the C+ language uses robotics as a context (i.e.,
CUNY Baruch - CIS - 1
today: loops and le operations loops le operationsloops looping, or iteration, means doing something more than once, perhaps doing something over and over and over and . and over again there are times when you want your program to do something
CUNY Baruch - CIS - 1
today: new topics: two-dimensional arrays switch statement review topics: constants string functions (see lecture IV.2 and textbook chapter 8) cctype functions (see lecture IV.2 and textbook chapter 8) In class, we followed a comprehensive ex
CUNY Baruch - CIS - 1
cis1.5-spring2008-azhar, lab IV, part 1instructions This is the rst part of the lab/homework assignment for unit IV. The entire assignment will be worth 9 points. The rst part is worth 4 points and will be distributed and worked on in class on Th
CUNY Baruch - CIS - 1
today: simple classes FINAL EXAM: will be on MONDAY MAY 21, 1.00pm3.00pm (room to be announced.)simple classes classes are ways of organizing programs to provide structure a class is a special kind of compound data type classes are compound be
CUNY Baruch - CIS - 1
today: strings what are strings and why to use them reading: textbook chapter 8what are strings a string in C+ is one of a special kind of data type called a class we will talk more about classes in detail at the end of the term but note that
CUNY Baruch - CIS - 1
today: math operations and function arguments random numbers math operators data type conversion function argumentsrandom numbers computers can generate random numbers, which is like picking a number by rolling dice there are two steps necess
CUNY Baruch - CIS - 1
today: functions what are functions and why to use them library and programmer-defined functions parameters and return values reading: textbook chapter 5, sections 1-4 modularityadvantages of functions we can divide up a program into small,
CUNY Baruch - CIS - 1
today: arrays what are arrays and why to use them integer arrays reading: textbook chapter 7, sections 3-4arrays arrays are used to hold sets of related types of data the data could be integers or doubles or booleans the data could also be ch
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ fall 2008 lecture # I.2 topics: unix fundamentalswhat is UNIX? Unix is an operating system (like Windows) which means it is a program that runs on a computer that makes it possible for you to use t
CUNY Baruch - CIS - 1
cis1.5-spring2008-azhar, lab IIIinstructions This assignment will be worth 9 points. Both parts together are due on Wednesday March 26 and must be submitted by email (as below). Follow these emailing instructions: 1. Create a mail message address
CUNY Baruch - CIS - 1
today: sorting algorithms blort sort selection sort insertion sort bubble sort FINAL EXAM: Thursday, May 22nd (1pm - 3pm) (place to be announced.)sorting sorting is one of the classic tasks done in computer programming the basic idea with s
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ fall 2008 lecture # V.1 topics: arrays pointers arrays of objects resources: some of this lecture is covered in parts of Pohl, chapter 3arrays and pointers overview arrays and pointers are strong
CUNY Baruch - CIS - 10
Philosophy of Artificial Intelligence Paper 2 Due Tuesday, May 1 In this paper you will work out some ideas from section 6 of Daniel Dennett's &quot;Quining Qualia.&quot; Below I give you some very strong suggestions about how to proceed. (If you want to appro
CUNY Baruch - CIS - 15
cis15/summer2008/ozgelenC+ ReviewWrite a complete C+ program, including at least one comment for the main program and one for each function, as follows. Your program will emulate some aspects of a card game based on the game of Hearts. Its okay if
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment IIinstructions This is assignment for unit II. It is worth 10 points. It must be submitted by email (as below). Follow these emailing instructions: 1. Create a mail message addressed to ozgelen@sci.brooklyn.c
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment IVinstructions This is assignment for unit IV. It is worth 10 points. It must be submitted by email (as below). Follow these emailing instructions: 1. Create a mail message addressed to ozgelen@sci.brooklyn.c
CUNY Baruch - CIS - 15
Quick and Dirty EMACSNote that any ordinary character goes into the buffer (no insert is needed). For a more detailed emacs manual, check out the GNU emacs manual on-line at: http:/www.gnu.org/software/emacs/manual/Some necessary abbreviations:CM
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment III, part 2instructions This is the second part of the assignment for Unit III. It is worth 5 points. Follow these emailing instructions: 1. Create a mail message addressed to ozgelen@sci.brooklyn.cuny.edu with
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment III, part 1instructions This is the rst part of the assignment for Unit III. It is worth 5 points. Follow these emailing instructions: 1. Create a mail message addressed to ozgelen@sci.brooklyn.cuny.edu with th
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment I, part 1instructions This is the rst part of the assignment for unit I. The entire assignment will be worth 5 points. The rst part is worth 2 points. The second part is worth 3 points. Both parts must be su
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # VI.1 topics: recursion searchingrecursion recursion is defining something in terms of itself there are many examples in nature and in mathematics and in computer graphics,
CUNY Baruch - CIS - 15
cis15-summer2008 ozgelen, assignment I, part 2instructions This is the rst part of the assignment for unit I. The entire assignment will be worth 5 points. The rst part is worth 2 points. The second part is worth 3 points. Both parts must be su
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # V.2 topics: functions: parameters and arguments call by value vs call by reference namespaces generic pointers dynamic memory allocation resources: Pohl, chapter 3functions
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # V.1 topics: arrays pointers arrays of objects resources: some of this lecture is covered in parts of Pohl, chapter 3arrays review a data structure consisting of related elem
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # II.2 topics: ctors and dtors polymorphism and overloading friend classes, composition and derivation resources: Pohl, chapter 5 (mostly sections 5.1-5.3, 5.7, 5.10)ctors and
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ spring 2008 lecture # VII.1 topics: generic programming templates STL (standard template library) on-line reference: http:/www.cppreference.com/index.htmlgeneric programming methodology for enhan
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # I.1 introduction topics: (0) introduction to the course (1) to do (2) review of c+ instructor: Arif Tuna Ozgelen, ozgelen@sci.brooklyn.cuny.edu course web page: http:/www.sci.bro
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # IV.1 topics: inheritance composition of classes resources: Pohl, chapters 8 and 11an example consider the program patrol.cpp (posted on the class web page) this program mode
CUNY Baruch - CIS - 15
cis15-summer2008-ozgelen, assignment I, part 3 (optional)instructions This is an optional third part of the assignment for unit I. This part is worth 1 point of extra credit and can be submitted along with parts 1 and 2.1. enumerated data types
CUNY Baruch - CIS - 1
cis1.5-fall2008-ozgelen, lab Vinstructions This lab must be submitted by email (as below): 1. Create a mail message addressed to ozgelen@sci.brooklyn.cuny.edu with the subject line cis1.5. 2. Attach ONLY the .cpp files for each part, as outlined be
CUNY Baruch - CIS - 1
today: math operations and function arguments random numbers math operators data type conversion function arguments file operationsrandom numbers computers can generate &quot;random&quot; numbers, which is like picking a number by rolling dice there a
CUNY Baruch - CIS - 1
today: sorting algorithms blort sort selection sort insertion sort bubble sortsorting sorting is one of the classic tasks done in computer programming the basic idea with sorting is to rearrange the elements in an array so that they are in a
CUNY Baruch - CIS - 1
cis1.5-fall2008-ozgelen, lab II, part 2instructions This part of the lab is worth 5 points. Both parts must be submitted by email (as below): 1. Create a mail message addressed to ozgelen@sci.brooklyn.cuny.edu with the subject line cis1.5. 2. Atta
CUNY Baruch - CIS - 1
cis1.5 introduction to computing using c+ (legal applications) fall 2008 lecture # I.1 introductionintroduction to the course about this course introduction to computer programming using the C+ language uses legal applications as a context (i.e.
CUNY Baruch - CIS - 1
today: new topics: two-dimensional arrays switch statement review topics: constants string functions (see lecture IV.2 and textbook chapter 8) cctype functions (see lecture IV.2 and textbook chapter 8) In class, we followed a comprehensive ex
CUNY Baruch - CIS - 1
today: logical operations and control structures the if statement relational operators logical operators truth tables loops: the while and for statementsthe if branching statement we have already been using the if statement: void decreaseRais
CUNY Baruch - CIS - 1
today: strings what are strings and why to use them reading: textbook chapter 8what are strings a string in C+ is one of a special kind of data type called a class we will talk more about classes in detail at the end of the term but note that
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # I.2 topics: unix fundamentalswhat is UNIX? Unix is an operating system (like Windows). OS? - A program that coordinates and oversees the resources of a computer and provides a
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # III.1 topics: C-style strings input and output resources: Pohl, chapter 9C-style strings (1). storing multiple characters in a single variable data type is still char BUT i
CUNY Baruch - CIS - 15
cis15 advanced programming techniques, using c+ summer 2008 lecture # II.1 topics: objects and class design command line arguments resources: Pohl, chapter 4aggregate data types class and struct struct comes from C class is new in C++ both a
CUNY Baruch - CIS - 1
today: functions what are functions and why to use them library and programmer-dened functions parameters and return values reading: textbook chapter 5, sections 1-4 modularityadvantages of functions we can divide up a program into small, un
CUNY Baruch - CIS - 1
today: arrays what are arrays and why to use them integer arrays reading: textbook chapter 7, sections 3-4arrays arrays are used to hold sets of related types of data the data could be integers or doubles or booleans the data could also be ch
CUNY Baruch - CS - 3157
MAKE(1L)LOCAL USER COMMANDSMAKE(1L)NAME make - GNU make utility to maintain groups of programs SYNOPSIS make [ -f _ a_ e_ i_ e ] [ option ] . target . m_ k_ f_ l_ WARNING This man page is an extract of the documentation of _ N_ _ a_ e G_ U m_ k
CUNY Baruch - CS - 1007
CS1007 lecture #4 notesthu 12 sep 2002 news data types and storage variables and assignment binary numbers and arithmetic ASCII Strings math operators increment and decrement operators reading: ch 2.5,2.7-2.12cs1007-fall2002-sklar-lect04
CUNY Baruch - CS - 1007
CS1007 lecture #21 notesthu 21 nov 2002 news vectors linear searching reading: ch 12.1-12.6cs1007-fall2002-sklar-lect21 1vectors (1).Java has a nice class which handles arrays dynamically: java.util.Vector the elements of a Vector can be
CUNY Baruch - CS - 1007
CS1007 lecture #6 notesthu 19 sep 2002 news homework #2 will be posted by midnight tonight homework #1 should be returned in recitation next week the while and for loops break and continue statements switch statement reading: ch 3.5-3.10 cs10
CUNY Baruch - CS - 3157
fork(2)fork(2)NAMEfork, fork1 - create a new processSYNOPSIS#include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; pid_t fork(void); pid_t fork1(void);MT-LEVELfork( ) is Async-Signal-SafeDESCRIPTIONfork( ) and fork1( ) cause creation of a new proce
CUNY Baruch - CS - 1007
CS1007 lecture #10 notestue 8 oct 2002 NEWS error quiz # 1, question 1d if you got the question WRONG, bring the quiz to class on thu 10 oct for a one-time regrade arrays (one-dimensional) nding array minimum and maximum sorting big-Oh 2-dimension
CUNY Baruch - CS - 1007
CS1007 lecture #15 notestue 29 oct 2002 news networks applets GUIs reading: ch 8.1-8.4cs1007-fall2002-sklar-lect15 1networks (1).two or more computers connected to each other networked computers can share information and resources, e.g.:
CUNY Baruch - CS - 3157
SED(1)User CommandsSED(1)NAME sed - a Stream EDitor SYNOPSIS sed [-n] [-V] [-quiet] [-silent] [-version] [-help] [-e script] [-expression=script] [-f script-file] [-file=script-file] [script-if-no-other-script] [file.] DESCRIPTION _ e_ is a str
CUNY Baruch - CS - 3157
C for Java Programmerslecture notes credits: Advanced Programming (cs3995, Spring 2002, Prof Schulzrinne) Software Construction (J. Shepherd) Operating Systems at Cornell (Indranil Gupta) today: Why learn C after Java? A brief background on C
CUNY Baruch - CS - 1007
CS1007 lecture #7 notestue 24 sep 2002 news homework #2 due tue oct 1 homework #1 should be returned in recitation this week short quiz #1 (5 points) in class on thu sep 26 bring one page of notes no computers, calculators, phones, etc. for, whil
CUNY Baruch - CS - 3157
lecture #16 mon oct 28, 2002news homework #3 due today homework #4 out today replacing quiz #3 see web page for updates. today programming tools overview conguration management sources: some slides from H. Schulzrinne, cs3995, spring 2002