CS361 Week 8 Programming Assignments

CS361 Week 8 Programming Assignments

CS361 Week 7/8 Programming Assignment

For both programs this week, you must write prototypes for all of your user-defined functions. The prototypes should be placed above main, and the function definitions should be placed below main.

Program #2

Write a program to print out renewal and cancellation notices to magazine subscribers,

and write a test plan to test your program.

Program Overview

The program will read the current date (month and year) from the user.

Then in a loop, it will read a subscriber's name, a subscription start month and year, and the number of years subscribed. Using this information, it will output a subscription status for each subscriber.

The program will loop, processing subscribers, until the user chooses to exit.

Program Details

This program will incorporate re-use of code. You will modify the week 4 program 2 code that identified a month name, to use in this program as a function.

The program code will be re-written as a month input function as follows:

  • The user will still identify the month by entering the first few letters, exactly as they did for the original program.
  • Instead of displaying the month name, the code should be modified to now set a "month number" variable to the correct month number (1-12).
  • The function should have at least one input parameter, a month number, representing the highest month number that will be allowed.
  • If the user enters an invalid month, the function should issue an error message and loop, until a valid month is entered.
  • Once a valid month has been entered, there should be a SINGLE return statement in the function, that returns the valid month number.

You will also create a year input function, which will have the following input parameters: a prompt string, a low year limit and a high year limit. The input parameter values will be used to read and error check that the year entered by the user is valid (i.e. falls within the low and high year limits).

Program Execution

To establish the current date, your program should first read:

- the current month (using the above described month input function) and

- the current 4-digit year from the user (using the above described year input function).

  • The values for the current month and current year should be read from the user only once (not every time the program loops to run another subscription).
  • When reading the current year, the function should not accept any year before 2012 (the program implementation year, stored as a constant), but should accept years up to 5 years in the future (so the program will work for a few years, without modification).
  • When reading the currentmonth, the function should accept all valid months (1-12).

Sample Input for the current month and year:

Then, for each subscription (i.e. each time the program loops):

1) Read the subscriber's first name and then separately read the subscriber's last name. No error checking is required.

NOTE: Since first and last names may contain spaces, you will need to use the getline function to read them (see WBW section 1.5.2 String Input), instead of using cin.

2) Read in the month and year that the subscription started.

NOTE: Subscription start dates should not be future dates.

Use the same month input function and year input function you already wrote and used to read in the current month and year.

  • The subscription start year must not be more than 5 years prior to the current year (because subscription lengths are not more than 5 years). And since the subscription start date should not be a future date, the subscription start year must not be past the current year. These year limit values should be passed into the year input function as the low year and high year limit arguments.

NOTE: Since the 5 year limit is tied to the subscription length limit described below, only one constant definition is necessary.

  • Since a subscription start date should not be a future date, if the subscription start year is the current year, then the subscription start month should not be past the current month. This means that if the subscription start year is the current year, the program must pass an argument into the month input function to limit the upper value of the month the user can enter. If the user enters a subscription start month that is past the current month in the current year, the function should issue an error message and loop, until a valid month is entered.

3) Read in the length (in whole years) of the subscription. Error check that the length

of subscription is between 1 and 5 years.

NOTE: This 5 year limit may be increased by the company sometime in the future. Your program should still work, with only a minor constant value change, if this happens.

All error checking should be performed from within each function that reads specific data from the users.

4) Finally, output the results to the user as specified below ( Note: The logic for this section can be tricky – be sure to take ALL possible cases into consideration).

  • For all subscribers, first neatly output the current date, the subscriber's name, subscription start date and subscription expiration date (i.e. the last month that a subscription will be received).
  • Note that the expiration month is one month before the starting month.

Example:

If my 3-year subscription to a magazine began in April of 2013, the expiration date is March of 2016.

  • The months should be displayed in WORDS, not numbers. Implement a separate function to convert from month number to month word.
  • Next print out the Account Status.

Each account will fall into ONE of the THREE categories below:

If the current month is

EITHER the expiration month

OR the month before the expiration month,

print a message asking the subscriber to renew.

Example:

Account Status: Subscription expires within a month

Please call to RENEW subscription

Be sure to check for instances when the current month is Dec, and the expiration month is Jan of the next year.

If the expiration date has passed, print a message stating that the

subscription has been cancelled.

Example:

Account Status: Expiration date has passed

Your subscription has been CANCELLED

Otherwise, print a message stating that the account is current, and display the number of months remaining on the subscription (start counting with the month following the current month).

Sample Input (for each subscriber):

Sample Output (for each subsciber):

After displaying the output for one subscriber, ask the user whether they would like to process another subscription. Your program should LOOP and process subscriptions until the user indicates that they are do not want to process any more subscritions. Remember that the current date will remain the same while the program is executing, so it will not need to be entered again.

Your program should be modular, and all functions (other than main) should be prototyped.

Include at least the following functions:

A generic year input function (described above)

A generic month input function (described above)

A subscription length input function to read and validate the subscription length

A subscriber data input function which calls the above three functions to read the subscription start and length data, and also reads the subscriber's name. Passes back ALL subscriber data to main via reference parameters.

A function that takes a month number as input and returns a month name

At least two additional user-defined functions

Testing

As part of your submission for this week, you must write a test plan for this program. Your test cases should include what INPUT you used for the test and what OUTPUT you expected.

Submit your test plan as an MS Word document or an MS Excel spreadsheet.

Program and Function Documentation

1) Be sure to include top of program comments as specified in WBW section 1.8.

2) Make sure you comment any constants/variables whose names are not completely descriptive.

3) You must also include a comment above each user-defined function that includes:

Description of what the function does

Description of the input parameters (if any), used to pass values into the function

Description of the output parameters (if any), used to pass values back from the function

Description of what is returned from the function via the return statement (if anything)

Example of function comments:

//*********************************************************************

// function GetYear reads a 4-digit year from the user

// Input Parameters: prompt – string used to prompt for input

// lowerLimit – lowest allowable value for year

// upperLimit – highest allowable value for year

// Return Value: year – 4-digit year in the allowable range

//*********************************************************************

Submission

This programming assignment is due by midnight Tuesday of Week 8. Submit your program source code (the .cpp files) via the Assignment Drop Box in the Week-by-Week. Both program files and your test plan file should be attached to one submission for week 8.

Before submitting your files, you MUST name them as follows:

Lastname-wk8-prog1.cpp

Lastname-wk8-prog2.cpp

Lastname-wk8-testplan-prog2.xxx

Grading

The rubric that will be used to grade your program is included on the next pages

Weeks 7-8 Programming Assignment 7 Rubric
(10% of your cumulative grade)
Program 1: (28 pts)
Rating / Exemplary / Proficient / Basic (needs work) / Not Demonstrated
Rating Category
Data Storage Points / Variables defined locally, using appropriate data types. Used descriptive names, following coding standards naming conventions. / A few minor errors in data typing, naming, or assignment. / One or more major errors, OR majority of names did not follow naming conventions. / Identifier names are not descriptive, and there is a multitude of errors OR defined global variable(s).
main function: User Input / Displays explicit prompts, and validates user input in a loop, reprompting as necessary. / One minor error in the user input and validation code. / Multiple errors in the user input and validation code or input read, but not validated. / No input read from user - values possibly hardcoded.
Function Implementations: Formula / Function prototype and definition correct with proper parameter usage and a return value. Function logic produces correct results. / One or two minor error in function prototype or definition, or in function logic. / Multiple errors in function prototype or definition, or in function logic. / Required function was not implemented. Task was simply performed from within the main function or task not performed using formula at all.
Function Implementations: Iterative / Function prototype and definition correct with proper parameter usage and a return value. Function logic produces correct results. Loop statements are written correctly. / One or two minor errors in function prototype or definition, or in function logic or loop statements. / Many errors in function prototype or definition, or in function logic or loop statements. / Required function was not implemented. Task was simply performed from within the main function, or task not performed by looping at all.
Function Implementation: Recursive / Function prototype and definition correct with proper parameter usage and a return value. Function logic produces correct results. If statements and recursive call(s) are written correctly. / One or two minor errors in function prototype or definition, OR in function logic, recursive call, or if statements. / Many errors in function prototype or definition, OR in function logic, recursive call, or if statements. / Required recursive function was not implemented.
main function: Logic/Output / The logic accomplishes all program requirements and displays all of the required output. Loops correctly to repeat and exits only when 0 entered. / One or two minor errors in the main function logic loop, or output, or calls to other functions, and/or does not exit loop via test condition. / Many errors in the main function logic/ouput display, or function runs correctly ONCE, but does not loop. / Logic accomplishes none of the program requirements, and display completely incorrect output (or no output).
C++ Constructs / Readability / Miscellaneous / Code is organized and easy to follow. There is no unnecessary code and all code is spaced and indented correctly. / Code is fairly easy to read, but there are some spacing, indentation, and/or other minor issues, or extraneous code. / Code is somewhat difficult to read or has some other major issue. / The code is formatted so badly that it is extremely hard to read or has multiple major other issues.
Program 2: (72 pts)
Rating / Exemplary / Proficient / Basic (needs work) / Not Demonstrated
Rating Category
Data Storage Points / Constants defined for ALL fixed values. Variables defined locally, using appropriate data types. Used descriptive names, following coding standards naming conventions. / A few minor errors in data typing, naming, or assignment OR missing one or two necessary constants for fixed value. / One or more major errors, OR majority of names did not follow naming conventions, OR missing multiple constants for fixed values. / Constants not used, identifier names are not descriptive, and there is a multitude of errors OR defined global variable(s).
Input Function: Month Input / Generic function prototyped and defined, modified from week 4. Displays explicit prompt, and validates user input. Returns correct month number. Called twice, to read both current month and subscription start month. / One or two minor errors in function prototype, definition (type, parameter, and return value), or calls, or in the user input and validation code. / Many errors in function prototype, definition (type, parameter, and return value), or calls, or in the user input and validation code, or defined two functions instead of one generic function. / Required function was not implemented. Task was simply performed from within the main function.
Input Function: Year Input / Generic function prototyped and defined. Upper and lower limits passed as input parameters. Displays explicit prompt, and validates user input in a loop, reprompting as necessary. Called twice, to read both current year and subscription start year. / One or two minor errors in function prototype, definition (input parameters and return value), or calls, or in the user input and validation code. / Many errors in function prototype, definition (input parameters and return value), or calls, or in the user input and validation code, or defined two functions instead of one generic function, or essentially wrote two functions within one using a big if-else statement. / Required function was not implemented. Task was simply performed from within the main function.
Input Function: Number of Years subscribed / Function prototyped and defined to read and validate number years subscribed. Displays explicit prompt, and validates user input within limits, using constant. / One minor errors in function prototype, definition, or call, or the user input prompt, reading, or validation code. / Many errors in function prototype or definition, or the user input prompt, reading, or validation code. / Required function was not implemented. Task was simply performed from within the main function.
Input Function: Subscriber Data Input / Function prototyped and defined to call the other 3 input functions plus code to correctly read entire name, even if it contains spaces. Passes back all values via reference parameters. / One or two minor errors in function definition, logic, or calls to other functions, or does not read any data after a space in the name(s), or one value returned instead of passed back via a reference parameter. / Many errors in function definition, logic, or calls to other functions. / Required function was not implemented. Tasks were simply performed from within the main function.
Logic: Calculation of Expiration Date / All if statements are written correctly. All math computations compute correct results. / One or two minor errors in the if statements or math computations, and/or fails to adjust month or year for expirations in December. / Many errors in the if statements or math computations, and/or fails to adjust month and year for expirations in December. / Fails to calculate any expiration dates correctly.
Logic: Determination of Account Status / All logic statements are written correctly. / One or two minor errors in the logic statements, and/or wrong status for months expiring in Jan or Feb. / Many errors in the logic statements. / Fails to correctly determine any account standings correctly.