CS 270, Spring 2014
Programming Assignment PA1
Introduction to C

Programming due Friday, Jan. 24 at 11:59pm, late deadline Saturday, Jan. 25 at 11:59pm.


This assignment has four objectives:
  1. to write a C program with console output,
  2. to learn how to submit your C program using the Checkin tab on the course web site,
  3. to understand how preliminary testing works, and
  4. to see if you can follow directions!
Write a C program in a file called PA1.c, using the example of the code structure shown below. You must write five functions and the main entry point, exactly as described in the directions below:

Program Structure

The following code can be used as a starting point, note that the function does not match any of the functions asked for above.
// PA1 Assignment
// Author: Chris Wilcox
// Date:   1/15/2014
// Class:  CS270
// Email:  wilcox@cs.colostate.edu

// Include files
#include <stdio.h>
#include <stdlib.h>

double square(double value)
{
    return (value * value);
}

int main(int argc, char *argv[])
{
    // Check number of arguments
    if (argc < 2)
        printf("usage PA1 <double>\n");

    double d = atof(argv[1]);
    printf("The square of %0.5f equals %0.5f.\n", d, square(d));

    return 0;
}

Sample output

Your program should print five lines. The sample output below shows how to compile, link, and run the PA1 program on Linux using the gcc compiler. See the grading criteria below for additional information.
$ gcc -Wall -std=c99 -c PA1.c
$ gcc -lm PA1.o -o PA1
$ ./PA1 1.0 1.0 1.0 1.0 1.0
CIRCLE, radius = 1.00000, area = 3.14159.
TRIANGLE, length = 1.00000, area = 0.43301.
SQUARE, length = 1.00000, area = 1.00000.
PENTAGON, length = 1.00000, area = 1.72048.
HEXAGON, length = 1.00000, area = 2.59808.

Specifications

Your program must meet the following specifications:

Grading Criteria

Submit your program to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy (if necessary).

© 2014 CS270 Colorado State University. All Rights Reserved.