UMBC CMSC104 CSEE Lectures

Project 5

Requirements Specfication

Write a program that will accept the monthly sales for the twelve months of a year. Declare two arrays in main, one for the sales, and one for the the names of the months. Use three additional functions:

Example Output

In the following example, the program displays what is in Blue and the user types what is in Red.

Enter the sales for January:   100498.50
Enter the sales for February:  498.50
Enter the sales for March:     99006.03
Enter the sales for April:     898.23
Enter the sales for May:       10022.34
Enter the sales for June:      25432.75
Enter the sales for July:      36498.23
Enter the sales for August:    44853.43
Enter the sales for September: 75002.99
Enter the sales for October:   44325.82
Enter the sales for November:  23375.07
Enter the sales for December:  87869.81

Highest Sales were in January:

Lowest Sales were in February

Average Sales were 12345.67:

January  :100498.50
February :   498.50
March    : 99006.03
April    :   898.23
May      : 10022.34
June     : 25432.75
July     : 36498.23
August   : 44853.43
September: 75002.99
October  : 44325.82
November : 23375.07
December : 87869.81

Sample Of Passing A 2-demensional Array

#include <stdio.h>

void printArray( char m[ ] [ 15 ] );

int main( void )
{
    int i;
    float sales[ 12 ] = { 1.0, 2.0, 3.0,  4.0,  5.0,   6.0,
                          7.0, 8.0, 9.0, 10.0, 11.0,  12.0 };
               
    char months[ 12 ][ 15 ] = { "January", "February", "March",
                                "April", "May", "June",
                                "July", "August", "September",
                                "October", "November", "December"} ;

     for( i = 0; i < 12; i++ )
     {
         printf( "%-9s:  %7.2f\n", months[ i ], sales[ i ] ); 
     }
     
     printArray( months );

     return 0;
}

void printArray( char m[ ] [ 15 ] )
{

     int i;

     for( i = 12; i > 0; i-- )
     {
         printf( " %-9s\n", m[ i ] );
     }

}

Program Header Comment Block

Use the following comment block at the beginning of your source code:
/***********************************************************
 * Filename:       jdoe2p5.c                               *
 * Name:           jdoe2p5.c                               *
 * Student Email:  jdoe2@umbc.edu                          * 
 * Date:           3 October 2004                          *
 * Course:         CMSC-104                                * 
 * Description:    (Your psuedocode for main() goes here)  *
 *     Analysis:                                           *
 *                 Input:                                  *
 *                 Output:                                 *
 *                 Formulas:                               *
 *                 Constraints:                            *
 *                 Assumptions:                            *
 *     Design:     (Psuedocode is here)                    *
 * Notes:          (As needed, such has how to compile)    *
 ***********************************************************/
  

Function Header Comment Block (One for each function)

/*********************************************************** 
 * Function name:    function_name                         *
 * Description:      (Your function psuedocode goes here)  *
 * Input Parameters: Name and data type of each parameter. *
 * Return Value:     Data type and description of what     *
 *                   the return value is.                  * 
 ***********************************************************/
  


UMBC CMSC104 CSEE | CMSC104 | Lectures