Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

GEEN 2312: Introduction to Computing Assignment 2 Due Date: Wednesday March 9, 2

ID: 3672321 • Letter: G

Question

GEEN 2312: Introduction to Computing

Assignment 2

Due Date: Wednesday March 9, 2016

This assignment is about writing functions (Chapter 3).

Consider the drawing C program of Chapter 3 that we looked at in class. The source code is available in the Source Code folder in Blackboard. As you may recall, the program currently produces the following shapes (circle, triangle, intersecting lines,diamond):

   *

*   *

* *

/

/  

/    

------

/

/  

/    

/

/  

/    

     /

   /

/

In this assignment, you will be asked to enhance the program to display the house shape (refer to slide 8 of Chapter 3) as shown below:

   *

*   *

* *

/

/  

/    

------

/

/  

/    

/

/  

/    

     /

   /

/

/

/  

house shape

/    

------

|      |

-------

Add to the function prototypes section at the top of the program the following new function:

void draw_house(void); /* draws a triangle upside down */

At the end of the program and below the draw_diamond() function, implement the new function. Hint: Your draw_house function must call the function draw_triangle() to draw the roof part of the house and then write the necessary code to draw the bottom part of the house.

Good Luck!

Below is slide 8 from Chapter 3

The source code is below:

// Draw.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


/* Draws a stick figure */

#include

/* Function prototypes */
void draw_circle(void);   /* Draws a circle   */

void draw_intersect(void);   /* Draws intersecting lines   */

void draw_base(void);   /* Draws a base line    */

void draw_triangle(void);   /* Draws a triangle   */

void draw_diamond(void);   /* Draws a diamond   */

int
main(void)
{

      /* Draw a circle.    */
      draw_circle();

      /* Draw a triangle.    */
      draw_triangle();

      /* Draw intersecting lines.   */
      draw_intersect();

      /* Draw diamond.   */
      draw_diamond();

      return (0);
}

/*
* Draws a circle
*/
void
draw_circle(void)
{
      printf("   *   ");
      printf(" *   * ");
      printf(" * * ");
}

/*
* Draws intersecting lines
*/
void
draw_intersect(void)
{
      printf(" / \ "); /* Use 2 's to print 1 */
      printf(" /   \ ");
      printf("/     \ ");
}

/*
* Draws a base line
*/
void
draw_base(void)

{
      printf("------- ");
}

/*
* Draws a triangle
*/
void
draw_triangle(void)
{
      draw_intersect();
      draw_base();
}

/*
* Draws a diamond
*/
void
draw_diamond(void)
{
      draw_intersect();
    

printf("\     / ");
printf(" \   / ");
printf(" \ /   ");
    
}

house shape

Explanation / Answer

#include <stdio.h>

void draw_circle(void); /* Draws a circle */

void draw_intersect(void); /* Draws intersecting lines */

void draw_base(void); /* Draws a base line */

void draw_triangle(void); /* Draws a triangle */

void draw_diamond(void); /* Draws a diamond */

void draw_house(void); /*Draws a house*/

int main(void)

{

/* Draw a circle. */

draw_circle();

/* Draw a triangle. */

draw_triangle();

/* Draw intersecting lines. */

draw_intersect();

/* Draw diamond. */

draw_diamond();

/* Draw House. */

draw_house();

return (0);

}

/*

* Draws a circle

*/

void draw_circle(void)

{

printf(" * ");

printf(" * * ");

printf(" * * ");

}

/*

* Draws intersecting lines

*/

void draw_intersect(void)

{

printf(" / \ "); /* Use 2 's to print 1 */

printf(" / \ ");

printf("/ \ ");

}

/*

* Draws a base line

*/

void draw_base(void)

{

printf("------- ");

}

/*

* Draws a triangle

*/

void draw_triangle(void)

{

draw_intersect();

draw_base();

}

/*

* Draws a diamond

*/

void draw_diamond(void)

{

draw_intersect();

  

printf("\ / ");

printf(" \ / ");

printf(" \ / ");

}

/*

* Draws a house

*/

void draw_house(void)

{

printf("displaying the house ");

draw_triangle();

printf("| | ");

printf("| | ");

draw_base();

}