CIS071
Lab06 Plotting a Square Using for
Objectives:
Use of loops, Use of functions. Problem solving!
Task:
Document and write a program to display a variable-sized square (see example
below). The user supplies the square size and
the square consists of * characters.
Square of size 7 will look like:
******** ** ** ** ** ********
Detailed instructions:
Write functions to perform the following activities:
1. getSquareSize queries the user and
returns the desired square size. The size must be an integer greater than
two. If the user fails to enter a valid integer, return the value 0
(which will cause the main program to terminate). The function prototype is:
int getSquareSize(void);
2. printNchars
prints N consecutive characters of the desired type. The function prototype is:
void printNchars(int n, char chartype);
Hint1:
this function should use a single for loop
Hint2: %c is the placeholder for char variable. For example, the following code
with display This is $:
char chartype;
chartype = $
printf(This is %c, chartype);
3. printSquare prints a square framed in * characters of the specified
size. The function prototype is:
void
printSquare(int squaresize);
Hint1:
this function should make use of printNchars function
Hint2:
this function should also make use of a single for loop
Use the functions in the main program to plot a square
Compile and test the program with values which demonstrate the correct operation of the program (as you specified in your test plan explained in the program header). Be sure to explain your algorithm in the documentation.
Deliverables:Submit your program; show a few sample runs of the program by using copy-paste to main body of your email submission.