Extra Credit 2: Box in Box

Due: Friday May 11, 2012

Note: This extra credit assignment is worth 2 points (same as homework). Recall that extra credit can only boost your homework and classwork scores and not your quiz and final exam scores. Also, extra credit will only be given for submissions that are mostly correct. For example, a submission that would receive 5/10 on homework would not receive any points for extra credit. Please consult the syllabus: Syllabus: Extra Credit.


Objectives

more practice with nested for loops.

The Assignment


Write a program that asks the user for the length and height of a rectangle. Your program draws a rectangle of that size and a smaller rectangle inside it. The smaller rectangle has half the size of the larger rectangle. Sample runs of your program might look like:

PT[274]% ./a.out
Enter # of rows: 12
Enter length of each row: 12
 *  *  *  *  *  *  *  *  *  *  *  * 
 *                                * 
 *                                * 
 *        *  *  *  *  *  *        * 
 *        *              *        * 
 *        *              *        * 
 *        *              *        * 
 *        *              *        * 
 *        *  *  *  *  *  *        * 
 *                                * 
 *                                * 
 *  *  *  *  *  *  *  *  *  *  *  * 
PT[275]% 

PT[275]% ./a.out
Enter # of rows: 8
Enter length of each row: 16
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * 
 *                                            * 
 *           *  *  *  *  *  *  *  *           * 
 *           *                    *           * 
 *           *                    *           * 
 *           *  *  *  *  *  *  *  *           * 
 *                                            * 
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * 
PT[276]% ./a.out

Notes

Submit

Use the script command to record several sample runs of your program. Demonstrate that your program works for different size rectangles as well as non-square rectangles. Don't forget to exit from script. Then, submit your program and sample run as usual:

submit cs104_chang ec2 boxes.c typescript