UMBC CMSC104

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:

Array Notes

When you declare the array you must make sure the array will hold the longest month name, also there are 12 months, however, some people prefer to thing of month[1] as "January". If you wish, you can make the array one slot bigger (13) and simply ignore month[0].

You can declare and initialize the array in following manner:

  char  month[ 13 ][ 10 ] = { "",
			      "January",
			      "February",
			      "March",
			      "April",
			      "May",
			      "June",
			      "July",
			      "August",
			      "September",
			      "October",
			      "November",
			      "December" };
Then you can bring out the month of your choice in the following manner: printf( "%-10s\n", month[7] ); which would give you: July

When passing a two-dimensional array to a function, the header will look like this:

void PrintMonth( char theName[ ][ 10 ] , int size ); Notice that when you pass a two-dimensional array, the first dimension is not provided, just like in a one-dimensional array, however the second dimension MUST be given.

printf Notes

When you wish to print a string from a character array, you must declare the array to be the biggest size you will ever need. Then when you print it out, you have to use "%s" as the print specification. However when you want to have a fixed field size, by default, the characters will be printed right justified, when normally you want to have them left justified. We have already discussed how to align the floating point numbers, using something like "%10.2f". It is very important the your output be in columns correctly aligned. In most applications in the real world, your customer will demand this type of formatted output.

#include 

int main( void )
{
  char  myName[ 25 ] = "Gary Burt";

  printf( ">%30s<\n", myName );
  printf( ">%-30s<\n", myName );

  return 0;
}

>                     Gary Burt<
>Gary Burt                     <

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

Program Header Comment Block

Use the following comment block at the beginning of your source code:
/*****************************************************/
/* Program Header Block                              */
/* Filename:       6789prj5.c                        */
/* Name:           Ima Student                       */
/* SSAN:           6789                              */
/* Date:           6 May 2003                        */
/* Course/section: CMSC-104                          */
/* Description:                                      */
/*     Analysis:                                     */
/*         Input:                                    */
/*         Output:                                   */
/*         Constraints:                              */
/*         Formulas:                                 */
/*         Assumptions:                              */
/*     Design:                                       */
/*         (Your psuedocode goes here.)              */
/*                                                   */
/* Notes:          (As needed.)                      */
/*****************************************************/

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