CIS 150 C++ Programming Project: Sequential access (text) file
Objectives
- Create an input loop to enter data
- Stop input when the user chooses to end it
- Validate user input using functions
- Convert strings to uppercase
- 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:
- department: string
- employee id: string
- month: int (must be between 1 and 12)
- day: int (must be between 1 and 31)
- year: int (must be between 2000 and 2100)
- hours: double (must be between 0.0 and 24.0)
Program requirements
- Include required libraries.
- Create prototypes before main for the functions getInt, getDouble, getChar, and upper.
- Declare variables for each of the fields the record has.
- Declare a character variable for asking the user if he wants to enter another record.
- Open a file named seqfile.txt for text output where you want to append to the end of the file.
- If the file failed to open, display an error and exit with a failure exit status.
- Create a loop that will run until the user chooses to not enter another record.
- In the loop, prompt the user for each field in the record and validate the input.
- In the loop, convert the department and employee ID to uppercase.
- In the loop, output each field to the file separated by a comma, and followed by a newline.
- After the loop, close the file and exit with a success exit status.
- There should be four functions used, complete with prototypes:
- 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
- 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
- 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
- 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
- Note: Points may be deducted for not meeting the course coding standards.
- 2 points for including the required libraries
- 3 points for having the input loop run and end properly
- 3 points for converting all text input to uppercase
- 3 points for a properly functioning getInt function
- 3 points for a properly functioning getDouble function
- 5 points for a properly functioning getChar function
- 4 points for a properly functioning upper function
- 4 points for writing the data correctly to a sequential access file
- 3 points for appending data to the file rather than replacing the file contents