Hello guys. I\'m new to this, so I hope I\'m doing this correctly. I\'ve tried t
ID: 3547861 • Letter: H
Question
Hello guys. I'm new to this, so I hope I'm doing this correctly. I've tried to figure out the problem myself, but some of the stuff our teacher hasn't even gone over. It's due a week from today. Thanks for the help. Here's the problem.
Overview of the Problem. For this problem, you will receive unformatted data, i.e., not separated by spaces, tabs, commas, or other charaters that separate one data item or field from the next one. The data for this problem is now described.
Data is captured automatically from a production line and recorded in a text file for later analysis. The file format (organization) is very specific. The data file contains two types of records. The first type of record, called the Identifier Record, identifies particulars about the data sample. This record is always the first record in the file. The second type of record, called a Data Record contains actual data samples.
Identifier Record Format
1. 10 digit identifier*
2. 8 character date
3. 1 digit shift code
4. 4 character time
5. 2 character data format code
6. 5-digit data sample count
Prototype Identifier Record Format
IIIIIIIIIIDDMMYYYYSHHTTWF#####
Identifier (I) contains a 10-digit identification number
Day(D) 2-digit day number 01 through 31
Month(M) 2-digit month number 01 through 12
Year(Y) 4-digit year, e.g., 2007
Shift(S) 1 is first shift, 2 is second shift, and 3 is third shift.
Hour(H) 2-digit hours using a 24-hour clock 00 through 23
Minute(T) 2-digit minutes 00 through 59
Format Width(W) 1-digit number 1 through 9
Format Fractional Part(F) 1-digit number 0 through 9
Number of Data Value(#) 5-digits with leading zeroes required
Compare each of the three examples to the Prototype Identification Record format.
IIIIIIIIIIDDMMYYYYSHHTTWF#####
500001012803102008108305200010
610000012304232007218155200010
455001000010102007302453000025
A data file named machine_samples_1.txt contains only Identification Records about various samples of machine production data collected at some manufacturing facility. The file does NOT contain any actual data records, just identification records. You can treat machine_samples_1.txt as an ASCII plain text file, i.e., open it and view its contents using MS Notepad or a similar text editor.
You may assume that each record contains complete and correct information. The only information contained in the file will match the definition of Identification Records. No part of a record will be missing data. No record will contain more data than the prototype format specifies. All of the data within each record will be reasonable and match the prototype format. (Note: In real world situations, these assumptions often will not be met. A correctly written program would have to check for all of them. We impose the assumptions because you are learning to program and we do not want to frustrate you with lots of data validity checking at this stage of your education.)
You may not assume anything about the number of Identification records. You may not assume that the file contains a minimum number of records nor any maximum number. Your program must process records as it encounter them within the file.
Your program must correctly handle the following special case situations. (Note: We do make these requirements because they are very common and relatively easy to locate and handle.)
1. The data file may not exist or may not exist in the folder/directory in which you expect to find it or may be protected so that you cannot read it. The Identification Records may be in a file with a different name. In all of these cases, your program must properly handle the error without abnormally terminating. Your program should display an appropriate message and stop without attempting to read any information from the file. (Note: Your program should NOT attempt to handle each case individually, nor should it display unique messages for each individual case. Doing so is too difficult and will frustrate you.) If any of these special case situations occur, your program will NOT be allowed to open the file.
2. The data file does exist, but contains no data, i.e., it is empty. There are no Identification Records in the file and there is no other data in the file. When your program attempts to read the first record, i.e., line, of the file, the program may not be able to read any information because the file contains none. We have already mentioned this special case.
Data Conversion and Processing Requirements
Your program will produce two output files. Both files will contain plain text, i.e., ASCII characters. Name the first file manufacture.cvs. Name the second file manufacture_report.txt.
The first file, manufacture.cvs will contain the same data as the original input file, but with each data field separated by a comma. Dates must be converted to mm/dd/yyyy form and times must be converted to hh:mm form. The two data format fields in the original must be converted to the format fn.m, where the letter f will always be present, the data from the original record will be n and the number of decimal places after the decimal point will be m. Do not include any additional data, i.e., no descriptive text, no extra blank lines, etc. Do not include your name, date, etc. in this file! A file like this could be used to create spreadsheets because most spreadsheet programs, including MS Excel, likes to import data with some data field separation.
Sample Input and Corresponding Output for manufacture.cvs
500001012803102008108305200010
610000012304232007218155200010
455001000010042007302453000025
5000010128,03/10/2008,1,08:30,f5.2,00010
6100000123,04/23/2007,2,18:15,f5.2,00010
4550010000,10/04/2007,3,02:45,f3.0,00025
The second file, manufacture_report.txt will produce a more readable report with nicely formatted columns, column headings and some summary statistics.
Include course required information in this file! This information includes your name, lab assignment number, etc. After your personal and lab assignment identification information, include the following: (1) a descriptive report title, e.g., Summary of ABC Manufacturing Processes. (2) headings like machine, date, shift, time. Do NOT include any information about the last three fields, i.e., format of data and number of data items per record. (3) beneath each heading, list the appropriate information from the Identification Records. Do NOT list any information from the last three fields. (4) At the end of the report display the total number of Identification Records processed as well as the number of records associated with each shift. (Note: After you learn about arrays, later in this course, you could perform more extensive analysis like reporting the number of different machines, the number of records reported for each machine, or listing data in sorted order. This would require more complicated programming that you neither have the knowledge or skill to perform now.) (6) Skip one line and display the message End of Report at the left margin on the last line of your report. (7) Make sure the information you write to the file manufacture_report.txt is neatly organized, that the column headings and data beneath them appear in a professional manner, i.e., neatly centered or tabbed, not ragged.
Sample Input and Corresponding Output for manufacture_report.txt
500001012803102008108305200010
610000012304232007218155200010
455001000010042007302453000025
<Include Personal Identification
And Lab Assignment Identification>
Summary of ABC Manufacturing Processes
Machine Date Shift Time
5000010128 03/10/2008 1 08:30
6100000123 04/23/2007 2 18:15
4550010000 10/04/2007 3 02:45
Records Processed: 3
Shift 1: 1 Shift 2: 1 Shift 3: 1
End of Report
Explanation / Answer
#include #include #include #include using namespace std; int main() { int identifier1, identifier2, day, month, year, shift, hour, minute, width, fractional, value; FILE * datafile; //defines datafile FILE * outfile1; //defines outfile1 //opens machine_samples_1.txt in read mode datafile = fopen("machine_samples_1.txt","r"); //return file open error if (datafile == NULL) { fclose (datafile); printf("Could not open file "); printf(" "); system("PAUSE"); return EXIT_FAILURE; } else { //define variables for each data section with proper sizes. EOLdump is used to grab the end of line character in each row. char identifier[10],day[2],month[2],year[4],shift[1],hour[2],minute[2],width[1],part[1],dataValue[5],EOLdump[1]; //open manufacture.cvs in write mode outfile1 = fopen("manufacture.cvs", "w"); //continue reading and processing data until EOF while (!feof(datafile)) { fgets(identifier, 11, datafile); puts(identifier); fprintf(outfile1,"%s,",identifier); fgets(day, 3, datafile); puts(day); fprintf(outfile1,"%s/",day); fgets(month, 3, datafile); puts(month); fprintf(outfile1,"%s/",month); fgets(year, 5, datafile); puts(year); fprintf(outfile1,"%s,",year); fgets(shift, 2, datafile); puts(shift); fprintf(outfile1,"%s,",shift); fgets(hour, 3, datafile); puts(hour); fprintf(outfile1,"%s:",hour); fgets(minute, 3, datafile); puts(minute); fprintf(outfile1,"%s,",minute); fgets(width, 2, datafile); puts(width); fprintf(outfile1,"f%s.",width); fgets(part, 2, datafile); puts(part); fprintf(outfile1,"%s,",part); fgets(dataValue, 6, datafile); puts(dataValue); fprintf(outfile1,"%s ",dataValue); fgets(EOLdump, 2, datafile); system("CLS"); } } fclose(datafile); fclose(outfile1); system("PAUSE"); return EXIT_SUCCESS; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.