Decision Logic: if, if else, switch, Boolean conditions and variables



Similar documents
CSCI 1301: Introduction to Computing and Programming Summer 2015 Project 1: Credit Card Pay Off

How To Write a Technical Lab Report with Practical Examples

Introduction to Programming II Winter, 2014 Assignment 2

Introduction to Computer Programming (CS 1323) Project 9

Python Lists and Loops

PA2: Word Cloud (100 Points)

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

MICROSOFT ACCESS STEP BY STEP GUIDE

Best Robotics Sample Program Quick Start

Introduction to Python

College of Business Department of Accounting and Management Information Systems

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Getting Started with Excel Table of Contents

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Using Excel for Statistical Analysis

Visual Logic Instructions and Assignments

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

CS 241 Data Organization Coding Standards

Memory Systems. Static Random Access Memory (SRAM) Cell

Computer Science for San Francisco Youth

C A R I B B E A N E X A M I N A T I O N S REPORT ON CANDIDATES S WORK IN THE CARIBBEAN SECONDARY EDUCATION CERTIFICATE EXAMINATION MAY/JUNE 2012

Selection Statements

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Programming Assignment II Due Date: See online CISC 672 schedule Individual Assignment

Staten Island Technical High School Forensic Science

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

PL / SQL Basics. Chapter 3

Simplified Valuation Exercise & Ratio Analysis

Webforms on a Drupal 7 Website 3/20/15

COURSE SYLLABUS EDG 6931: Designing Integrated Media Environments 2 Educational Technology Program University of Florida

Computer Science 1 CSci 1100 Lecture 3 Python Functions

EMC Publishing. Ontario Curriculum Computer and Information Science Grade 11

Introduction to Python

So you want to create an a Friend action

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CSC 221: Computer Programming I. Fall 2011

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Assignment 4 CPSC 217 L02 Purpose. Important Note. Data visualization

Intro to Excel spreadsheets

COURSE SYLLABUS PHILOSOPHY 001 CRITICAL THINKING AND WRITING SPRING 2012

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

CS 306/491-3 Linux Programming Spring 2015

JavaScript: Control Statements I

Would You Like To Earn $1000 s With The Click Of A Button?

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

TAKING NOTES. II. Instructors usually give clues to what is important to take down:

While Loops and Animations

What is a database? The parts of an Access database

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

The little endl that couldn t

Informatica e Sistemi in Tempo Reale

Kids College Computer Game Programming Exploring Small Basic and Procedural Programming

Strategies for note taking

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

WSMC High School Competition The Pros and Cons Credit Cards Project Problem 2007

Programming Languages CIS 443

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Square Roots and Other Radicals

Microsoft Excel Tips & Tricks

Hypercosm. Studio.

Computer Science 217

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

ECE 122. Engineering Problem Solving with Java

INFSCI 0017 Fundamentals of Object- Oriented Programming

How To Proofread

BF Survey Plus User Guide

Main Effects and Interactions

Excel Formatting: Best Practices in Financial Models

Compiler Construction

Writer Guide. Chapter 15 Using Forms in Writer

Pepperdine University Graduate School of Education and Psychology Dissertation Format Requirements Manual. APA 6 th edition format

COLLEGE ALGEBRA. Paul Dawkins

How to Write a Good, if not Perfect Lab Notebook

Intellect Platform - The Workflow Engine Basic HelpDesk Troubleticket System - A102

A GUIDE TO LABORATORY REPORT WRITING ILLINOIS INSTITUTE OF TECHNOLOGY THE COLLEGE WRITING PROGRAM

If you know exactly how you want your business forms to look and don t mind detail

Chapter 15 Using Forms in Writer

1 Description of The Simpletron

App Inventor Tutorial 4 Cat & Mouse Game

The Factor Theorem and a corollary of the Fundamental Theorem of Algebra

C++ Input/Output: Streams

Product: DQ Order Manager Release Notes

Code Kingdoms Learning a Language

A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming

XPost: Excel Workbooks for the Post-estimation Interpretation of Regression Models for Categorical Dependent Variables

ISM 4113: SYSTEMS ANALYSIS & DESIGN

Moving from CS 61A Scheme to CS 61B Java

FREQUENTLY ASKED QUESTIONS: CTL.SC1X SUPPLY CHAIN FUNDAMENTALS

Student Guide and Syllabus for MAT100 Introductory Algebra

Course Content Concepts

Access 2007 Creating Forms Table of Contents

An Introduction to the WEB Style of Literate Programming

ECDL / ICDL Spreadsheets Syllabus Version 5.0

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

WAYNESBORO AREA SCHOOL DISTRICT CURRICULUM INTRODUCTION TO COMPUTER SCIENCE (June 2014)

An Innocent Investigation

Transcription:

CS 1044 roject 3 Fall 2009 Decision Logic: if, if else, switch, Boolean conditions and variables This programming assignment uses many of the ideas presented in sections 3 through 5 of the Dale/Weems text and the lecture notes covered through October 1, so you are advised to read those carefully. Read and follow the following program specification carefully. Your score on this project will be a weighted average of the score you receive for runtime testing and the score you receive for following the instructions in the rogramming Standards section below. The roblem: Cat and Mouse A cat and mouse are placed into a confined linear space that is divided into a sequence of N cells; for example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 N M C Each cell is labeled by an integer coordinates (a column number if you like). In the picture above, the mouse M is in cell 6 and the cat C is in cell 17. The cat and mouse will play a game. Each may move around, but may not leave the sequence of cells. If the cat and mouse reach the same cell after completing a move, then the mouse is caught and the game is over. You will write a program to track the movements of the cat and mouse, given information about the movements each makes and following the rules given in the rest of this specification. Each player (the cat or the mouse) moves among the cells in the sequence. A move is specified by giving a single signed integer, like 4 or -7, that specifies how many cells the player should move horizontally. For example, if the cat made the move -15 from its location shown above, it would wind up in cell 2. Note that the mouse would not be caught in this case, even though the cat appears to have passed through cell 6; think of it as if the cat and mouse simply jump to their next locations without passing through the intervening cells. Neither player is allowed to move to a location outside the sequence of cells. If such a move is attempted, the player will simply wrap around to the opposite end of the sequence. That s because the sequence of cells is really wrapped around into a circle. So, if the mouse made the move -7 from its position in cell 6, it will wind up in cell N-1. Given the initial positions shown above, the distance between the cat and mouse is 11. Distances are never negative. We can also measure the distance a player has moved since the beginning of the game. If the cat made the moves 3, -5 and 10, from its initial position shown above, it would have traveled a total distance of 18. Note that the initial position is not counted as a move. Input file description and sample: Your program must read its input from a file named ChaseData.txt use of another input file name will result in a score of zero. The first line of the input file specifies the number of columns in the grid used for this game. This value will be a positive integer and never more than 10000. Columns are numbered starting at 1. Each remaining line of the input file will fit exactly one of the following formats: M <integer> initial position or movement for the mouse C <integer> initial position or movement for the cat print current data, as specified below The values on each line will be separated by whitespace. You may assume that all the input values will be logically correct. For instance: 1

CS 1044 roject 3 Fall 2009 26 C 24 M 14 M -4 M 10 M -9 C -10 M 10 C -10 M -12 C 12 M 6 Note that you must not make any assumptions about the number of lines of data in the input file. Your program must be written so that it will detect when it's out of input and terminate correctly, just as in roject 2. What to calculate: You will write a program to read the input file and use the given values to: track the current location of the cat and the mouse track the distance currently separating them detect when (if) the cat catches the mouse compute the total distance traveled by each, as described above You must also watch for moves that would take the cat or mouse across one of the boundaries of the region. If such a move is attempted then the cat or mouse should wrap around the boundary as described on the first page of this specification. If the cat catches the mouse, then stop processing the input file immediately and generate the rest of the specified output. Output description and sample: The first line of the output file should include the title Cat and Mouse only; the second line should be blank; the third line should display the column labels shown below; the fourth line should consist of some delimiting symbol to separate the column labels from the body of the table. Next your output file will contain a table, with one line of output for each print command processed from the input file. Each line of the table should list the location of the cat and mouse at the time the print command was read, and the distance between them at that time (provided both are "in play"). If the cat or mouse is not "in play" yet, print "??" instead of a numeric value. There should be a line of delimiters immediately after the last line of the table body. The next two lines of the output file should be blank. The next line should contain the indicated labels, and the line after that should contain the total distances traveled by the cat and mouse. 2

CS 1044 roject 3 Fall 2009 Following that, there should be one blank line. If the cat caught the mouse in this game, then print the message Mouse caught at: followed by the location at which the capture occurred. If the cat didn t catch the mouse, then print the message Mouse evaded Cat. Your program must write output data to a file named ursuitlog.txt use of any other output file name will result in a score of zero. The sample output file shown below corresponds to the input data given above: Cat and Mouse Cat Mouse Distance -------------------- 24?? 24 10 14 24 11 13 4 21 17 4 9 5 16 9 7 16 15 1 -------------------- Distance traveled: Mouse Cat 51 32 Mouse evaded Cat You are not required to use this exact horizontal spacing, but your output must satisfy the following requirements: You must use variables of type int for all the locations, distances, etc. If you use decimal values, your answers may be incorrect due to numerical roundoff. You must use the specified header and column labels as shown. You must arrange your output in neatly aligned columns, with a label identifying the contents of each column. Note that while the Curator doesn t deduct points for horizontal alignment, the TA who grades your source code for programming standards may do so. You must use the same ordering of the columns as shown here. You must print a newline at the end of each line, including the last line. rogramming Standards: You'll be expected to observe good programming/documentation standards. All the discussions in class about formatting, structure, and commenting your code will be enforced. See the rogramming Standards page on the course website. Some specific requirements follow. Documentation: You must include header comments specifying the compiler and operating system used and the date completed. Your header comment must describe what your program does; don't just plagiarize language from this spec. You must include a comment explaining the purpose of every variable or named constant you use in your program. You must use meaningful identifier names that suggest the meaning or purpose of the constant, variable, function, etc. recede every major block of your code with a comment explaining its purpose. You don't have to describe how it works unless you do something so sneaky it deserves special recognition. If you write user-defined functions, each must have a valid C++ prototype and the definition of each must be preceded by a block comment, explaining in one sentence what the function does, and listing each parameter to the function and explaining its purpose. You must use indentation and blank lines to make control structures like loops and if-else statements more readable. The code from roject 1 is a good guide for how to handle some of the file I/O issues. 3

CS 1044 roject 3 Fall 2009 Implementation: Use named constants instead of variables where appropriate. Use at least one bool variable. Use at least one if statement, at least one if else statement, and at least one switch statement. Choose your control structures appropriately. Your submission that receives the highest score will be graded for adherence to these requirements, whether it is your last submission or not. If two or more of your submissions are tied for highest, the latest of those will be graded. Incremental Development: You ll find that it s easier and faster to produce a working program by practicing incremental development. In other words, don t try to solve the entire problem at once. First, develop your design. When the time comes to implement your design, do it piece by piece. Here s a suggested implementation strategy for this project. As usual, verify and correct as necessary after each addition to your implementation. First, write the code necessary to read the entire input file. This should apply the input-failure pattern discussed in class. To test your work, include code to write what you re reading (and nothing else) to the output file. Second, add the code to process the moves and print the locations after each move. Third, add the code to determine if the cat has caught the mouse and react accordingly. Fourth, write the code to compute the total distance traveled by each player and print that along with the locations. Finally, implement processing of print commands and print locations only when specified. Now you have a substantially complete program. At this point, you should clean up your code, eliminating any unnecessary instructions and fine-tuning the documentation you already wrote. Check your implementation and output again to be sure that you ve followed all the specifications given for this project, especially those in the rogramming Standards section above. At this point, you re ready to submit your solution to the Curator. Testing: At minimum, you should be certain that your program produces the output given above when you use the given input file. However, verifying that your program produces correct results on a single test case does not constitute a satisfactory testing regimen. Additional input/output file examples will be posted on the website. You may use those for additional testing. You should make up and try additional input files as well; of course, you'll have to determine by hand what the correct output would be. Submitting your program: You will submit this assignment to the Curator System (read the Student Guide), and it will be graded automatically. Instructions for submitting, and a description of how the grading is done, are contained in the Student Guide. You will be allowed up to ten submissions for this assignment. Use them wisely. Test your program thoroughly before submitting it. Make sure that your program produces correct results for every sample input file posted on the course website. If you do not get a perfect score, analyze the problem carefully and test your fix with the input file returned as part of the Curator e-mail message, before submitting again. The highest score you achieve will be counted. 4

CS 1044 roject 3 Fall 2009 The Student Guide and other pertinent information, such as the link to the proper submit page, can be found at: Honor Code: http:www.cs.vt.edu/curator/ In addition to the limits set in the posted course contract, students are expressly forbidden from providing the following information to the CS 1044 Forum, or by discussion or private e-mail to other students in this course: any explanation of how to calculate the position of a player any explanation of how to calculate the total distance traveled by a player It is permissible to post an input file and the corresponding output file to the listserv. Be advised that such postings may be incorrect. ledge: Each of your program submissions must be pledged to conform to the Honor Code requirements for this course. Specifically, you must include the following pledge statement in the header comment for your program: On my honor: - I have not discussed the C++ language code in my program with anyone other than my instructor or the teaching assistants assigned to this course. - I have not used C++ language code obtained from another student, or any other unauthorized source, either modified or unmodified. - If any C++ language code or documentation used in my program was obtained from another source, such as a text book or course notes, that has been clearly noted with a proper citation in the comments of my program. - I have not designed this program in such a way as to defeat or interfere with the normal operation of the Curator System. <Student Name> Failure to include this pledge in a submission is a violation of the Honor Code. 5