Question: I need help for this programming project Sequential access (text) file Objectives 1.Create an input loop to enter data 2.Stop input when the user chooses

I need help for this 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

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:

a.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

b.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

c.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

d.string upper(string s): which creates an uppercase version of the string passed in and returns it

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

My code is:

#include #include using namespace std;

int main() { ofstream myfile; myfile.open ("seqfile.txt"); string department; string employeeID; int month,year,day; double hours;

do { cout << "Enter dept ID: "; cin >> department; cout << "Employee ID: "; cin >> employeeID; cout << "Enter month: "; cin >> month; if (month < 1) { cout << "Error: Value below minimum of 1 "; cout << "Enter month: "; cin >> month; } else if (month > 12) { cout << "Error: Value above maximum of 12 "; cout << "Enter month: "; cin >> month; } cout << "Enter day: "; cin >> day; if (day < 1) { cout << "Error: Value below minimum of 1 "; cout << "Enter day: "; cin >> day; } else if (day > 31) { cout << "Error: Value below maximum of 31 "; cout << "Enter day: "; cin >> day; } cout << "Enter year: "; cin >> year; if (year < 2000) { cout << "Error: Value below minimum of 2000 "; cout << "Enter year: "; cin >> year; } else if (year > 2100) { cout << "Error: Value below maximum of 2100 "; cout << "Enter year: "; cin >> year; } cout << "Enter hours: "; cin >> hours; if (hours < 0.0) { cout << "Error: Value below minimum of 0.0 "; cout << "Enter hours: "; cin >> hours; } else if (hours > 24.0) { cout << "Error: Value above maximum of 24.0 "; cout << "Enter hours: "; cin >> hours; } myfile << department << " " << employeeID << " " << month << " " << day << " " << year << " " << hours << " "; char choice; cout << "Enter another record? (Y/N)"; cin >> choice; if (choice == 'N') break; if (choice != 'N') { cout << "Error: Invalid choice "; cout << "Enter another record? (Y/N)"; cin >> choice; } } while(true);

cout<<"File seqfile.txt has been modified."<

return 0; }

but it still has problem, when input the error second time, the program will go to next step, it won't return.

please help me to fix

thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!