CIS 150 C++ Programming Project: Sequential access (text) file

Objectives

  1. Create an input loop to enter data
  2. Stop input when the user chooses to end it
  3. Validate user input using functions
  4. Convert strings to uppercase
  5. Write data to a sequential access text file with each field separated by a comma and each record separated by a newline

Overview

This assignment involves the creation of a sequential access, text, variable-length record data file. You will create the user interface and store the data the user enters. Each record in the file has the following fields:

  1. department: string
  2. employee id: string
  3. month: int (must be between 1 and 12)
  4. day: int (must be between 1 and 31)
  5. year: int (must be between 2000 and 2100)
  6. hours: double (must be between 0.0 and 24.0)

Program requirements

  1. Include required libraries.
  2. Create prototypes before main for the functions getInt, getDouble, getChar, and upper.
  3. Declare variables for each of the fields the record has.
  4. Declare a character variable for asking the user if he wants to enter another record.
  5. Open a file named seqfile.txt for text output where you want to append to the end of the file.
  6. If the file failed to open, display an error and exit with a failure exit status.
  7. Create a loop that will run until the user chooses to not enter another record.
  8. In the loop, prompt the user for each field in the record and validate the input.
  9. In the loop, convert the department and employee ID to uppercase.
  10. In the loop, output each field to the file separated by a comma, and followed by a newline.
  11. After the loop, close the file and exit with a success exit status.
  12. There should be four functions used, complete with prototypes:
    1. int getInt(string prompt, int min, int max): which prompts the user, gets a valid integer within the range of min and max, and returns that value
    2. double getDouble(string prompt, double min, double max): which prompts the user, gets a valid double within the range of min and max, and returns that value
    3. char getChar(string prompt, string allowed): which prompts the user, gets a valid character, validates that the character is within the allowed list, and returns that character
    4. string& upper(string& s): which converts the string passed in to uppercase and returns the uppercase version

Sample Run 1

Enter dept ID: it
Employee ID:   d4772
Enter month:   1
Enter day:     2
Enter year:    2011
Enter hours:   8.25
Enter another record (Y/N)? y
Enter dept ID: it
Employee ID:   f9642
Enter month:   1
Enter day:     4
Enter year:    2011
Enter hours:   8.25
Enter another record (Y/N)? n

The file so far would look like this:

IT,D4772,1,2,2011,8.25
IT,F9642,1,4,2011,8.25

Sample Run 2

Enter dept ID: IT
Employee ID:   V1001
Enter month:   -9
Error: Value below minimum of 1
Enter month:   1
Enter day:     34
Error: Value above maximum of 31
Enter day:     3
Enter year:    08
Error: Value below minimum of 2000
Enter year:    2011
Enter hours:   480
Error: Value above maximum of 24
Enter hours:   5.25
Enter another record (Y/N)? Y
Enter dept ID: mgt
Employee ID:   a0010
Enter month:   1
Enter day:     2
Enter year:    2011
Enter hours:   6.5
Enter another record (Y/N)? p
Error: Invalid choice
Enter another record (Y/N)? n

The file would now look like this:

IT,D4772,1,2,2011,8.25
IT,F9642,1,4,2011,8.25
IT,V1001,1,3,2011,5.25
MGT,A0010,1,2,2011,6.5

Rubric