HW 1

HW 1.

Due Saturday, Feb 14, by 11:59pm (Midnight).

All programs should be submitted through Blackboard (Course Materials > HW1).

Each program should start with a comment that contains your name and a short program description, for example:

/*
  Author: Your Name 
  Description: HW 1. Task 1. Printing a rectangle
  .. you may add a more detailed description if it's necessary ..
*/

If a program does not do what it’s supposed to do (e.g. there are some bugs, it behaves differently, or maybe even does not compile), then its “incomplete” status must be clearly mentioned in the comment to the program. In this case, please briefly describe what is implemented, and what is not.

Task 1. Printing a rectangle

Write a program that asks the user to input two positive integers, call them “width” and “height”. After that, the program should print out a rectangle of dot '.' characters with the requested width and height.

If some input numbers happened to be non-positive, don’t print anything.

Example:

Please, enter the width = 12
Please, enter the height = 7
............
............
............
............
............
............
............

Task 2. Printing a grid

A modification of the previous task. Again, the program asks the user to input two positive integers.

Then it should print a rectangle of '.', but now every 5th row and every 5th column should be printed with the hash '#' character instead of '.'.

For this problem, you may make use of the modulo operator (%).

Example:

Please, enter the width = 19
Please, enter the height = 13
###################
#....#....#....#...
#....#....#....#...
#....#....#....#...
#....#....#....#...
###################
#....#....#....#...
#....#....#....#...
#....#....#....#...
#....#....#....#...
###################
#....#....#....#...
#....#....#....#...

Task 3. Graph paper

The same as the previous task, but the horizontal lines should be drawn with dashes '-', the vertical lines should be drawn with the vertical bars '|', and their intersections drawn with pluses '+'.

Also, instead of the dots, print whitespace characters ' '.

Example:

Please, enter the width = 19
Please, enter the height = 13
+----+----+----+---
|    |    |    |   
|    |    |    |   
|    |    |    |   
|    |    |    |   
+----+----+----+---
|    |    |    |   
|    |    |    |   
|    |    |    |   
|    |    |    |   
+----+----+----+---
|    |    |    |   
|    |    |    |   

Task 4. Diamond

Ask the user to input a positive odd integer.

The program should keep asking until the input integer is indeed odd and positive.

Assuming that the input number is N, print a diamond that has the height N and the width N.

Example:

Please, enter a positive odd number: 10
Please, enter a positive odd number: -3
Please, enter a positive odd number: 7
   *
  ***
 *****
*******
 *****
  ***
   *