


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Fall 2007;
Typology: Lab Reports
1 / 4
This page cannot be seen from the preview
Don't miss anything!



CPS 196 Lab 13 Fall 2007
I. Create a new program, snowman.c, in your labs project. Enter the following program by cutting and pasting either from here or from the lecture page.
/snowman.c/ #include<stdio.h>
/* function prototype */ void drawcircle(void);
int main(void) { drawcircle(); /function call/ drawcircle(); drawcircle(); return(0); } /function definition / / Draw a circle, no parameters. / void drawcircle(void) { /declarations - local variables/ char s; /executable statements/ s='*'; printf("%8c%c%c%c\n",s,s,s,s); printf("%6c%c%5c%c\n",s,s,s,s); printf("%5c%9c\n",s,s); printf("%4c%11c\n",s,s); printf("%4c%11c\n",s,s); printf("%5c%9c\n",s,s); printf("%6c%c%5c%c\n",s,s,s,s); printf("%8c%c%c%c\n",s,s,s,s); }
a) Resize your Visual Studio window, if necessary, so that you can see this window and the console window (the black background window) at the same time.
First debug as normal: Step Into (F11) the program and then repeatedly Step Over (F10), observing what happens in the console window until the program is done. Do Stop Debugging to complete the program.
b) Now use debug to observe the function executions as well: Step into (F11) the program. Do Step Over (F10)
EXCEPT for each line which is a function call (such as drawcircle();), choose Step Into (F11). Observe the order of execution of the program.
c) Add a new function, void drawrect(void) as follows:
i. Just below the function prototype for drawcircle, add a function prototype for drawrect. Note that the function prototype must end in a semicolon (;).
ii. At the bottom, below the function definition of drawcircle, write a function definition of drawrect. Note that the first line of the function definition is exactly like the function prototype, but without the semicolon. This function should draw a rectangle outlined by stars that is 8 characters wide and 5 characters high, centered over the snowman. You may want to test each line as you write this function.
iii. Add a function call to drawrect, in main, just above the first call to drawcircle. (This rectangle is supposed to be the snowman’s hat.)
iv. You may have to make several adjustments to drawrect before you get the right size in the right place.
Results: the function call I used: triple(
the output:
the function call I used: rewriter(
the output:
C) Experiment 2. Variables as arguments. Explore what happens when you use a variable of the proper data type, instead of a constant, as the parameter(s). Do this for each function, by writing a main that is appropriate for that particular function. For example, rewriter could have something like:
int main(void) { int num = 5; char anychar = 'R'; rewriter(anychar, 5); return(0); }
My main:
what happened:
My main:
what happened: