Puzzle SL36

Add the function getPerimeter() to the following project:


/* --- rect.h --- */
void setWidth( int w );
void setHeight( int h );
int getArea();

/* --- rect.c --- */
static int width = 0;
static int height = 0;

void setWidth( int w )
{
  width = w;
}

void setHeight( int h )
{
  height = h;
}

int getArea()
{
  return height*width;
}

/* --- mainRect.c --- */
#include <stdio.h>
#include "rect.h"

void main()
{
  setHeight( 4 );
  setWidth( 3 );

  printf("Area: %d  Perimeter: %d\n", getArea(), getPerimeter() );

}

Think of this as adding the method getPerimeter() to a class (in object oriented programming).



Answer         Next Page         Previous Page Home