------------------------------------------------------------------------------- CS99, Fall 2002: Homework 6 Due Monday 11/4 at BEGINNING of LECTURE (9:05am) ------------------------------------------------------------------------------- General guidelines: + For the following problems, write each program in a separate M-File. + Remember to follow the submission guidelines as specified in the syllabus! + I included a few more instructions this time, which are written below. Programming style: + Although you quickly recognize how useful arrays could be, you may NOT use them to solve any of the following problems. + I mean it...no arrays! Submission for lecture: + Print all files and the grading guide. + Staple the grading guide on top of your work. Electronic submission: + Zip all of your M-Files together in a file called _h6cs99.zip . + E-mail the zip file to cs99@cs.cornell.edu *before* the deadline. Late submissions: + We do not accept ate submissions in person or by e-mail. + If you miss the deadline, you will be required to perform extra work on the final project. ------------------------------------------------------------------------------- 1. Write a program that prints an empty triangle out of asterisks given a user-input size for the height. An example session follows: >> Please enter the height of the triangle: 5 * * * * * * * ********* To receive full credit, you must use a nested control structure. You may assume that the user enters a legal size. In a comment block before the code, write the full algorithm you used to develop your program. 2. Write a program that does the following: + Reads in a sequence of positive integers -- a non-positive integer terminates the sequence. + Prints the number of multiples of 5 found in the sequence. On your own, test your program with the following input sequences: 5, 21, 1, 21, 25, 32, -1 0, 5, -1 (Hint: What should the program do if the user enters zero? Beware of what positive means!) 150, -1 Note that "input sequence" means that the user is prompted to enter one value at a time. Input ends if the user enters an illegal value. As a block of comments, answer these questions: Are there other useful test cases you should try? What are the limitations of this program? 3. Write that does the following: + Reads in a sequence of integers between -100 and 100, inclusive -- an out-of-range number terminates the sequence + Prints the number of sign changes for the sequence. Recall that there are three different signs: +, 0, and -. On your own, test your program with the following input sequences: -99, -97, 12, -10, 1, -2, 101 1, -1, 0, 1, -1, 101 1, -101 2000 4. One of the best ways to learn something is to teach it. So, write an ORIGINAL question that involves a loop that contains at least one selection statement. Provide a solution to your problem. (Put the problem above the solution as a block of comments.) We will choose one (or more) of your submissions for your next prelim! -------------------------------------------------------------------------------