Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a program written in C Overview of Data Conversion. Many small programs a

ID: 3688569 • Letter: I

Question

I need a program written in C

Overview of Data Conversion.

Many small programs are written to convert data from one format to another. For instance, you may receive data used or produced by MS Excel and want to use the data in another program that does not accept data in a spreadsheet format. You may receive raw data captured automatically by some industrial or manufacturing process, but the data is not in MS Excel format or in a format needed by some other program. In either situation, one could write a computer program to read data in one format, process the data, e.g., filter data that is not needed, rearrange data, compute using some or all of the data, and write the results as outputs in a different format. Some times the these conversion programs are “one time only”, meaning the program is written to convert data once, then the program won’t be used again. Some times the conversion program will be used many times, for instance, whenever data is generated by a industrial or manufacturing process that is ongoing. 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. For this lab assignment we will only work with Identifier Records. Our input file will not contain any records that contain the actual data being sampled.

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

*Note: A 10-digit identifier number will be too long to store in int format (an int variable can only contain numbers up to and including 2,147,483,647) within one machine memory location, i.e., variable name. We suggest that you read the identifier in two 5-digit int parts, i.e., into two variables. If you use this technique you will probably have to work with leading zeros for each part only when you output them.

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 Here are three examples. Examine them carefully. You should be able to decode them the way we have done with each explanation. You should also be able to create your own examples. If you do not understand the codes and cannot decode or create new examples, you should ask your instructor to help you.

Example 1: 500001012803102008108305200010 Intrepretation of the Identifier Record (in compact data format) in Example 1 tells us that the data sample (not shown) was taken from a machine whose number is 5000010128 on March 10, 2008 during work shift #1 (7:30 a.m. through 3:30 p.m.). The data in the sample was actually taken at 8:30 a.m. with each piece of data having a format looking like xxx.xx, i.e., five digits with two digits after the decimal point. Finally, the actual data will be displayed with ten 5-digit numbers in each record (or line). Remember, we are not showing the actual data, only the line (record) that describes information about the data.

The code needs to be similar to this

#include<stdio.h>

#define SRCFILE "srs.txt"

#define DSTFILE "dst.txt"

int main() {

FILE *src, *dst;

int year, month, day;

int cnt17 = 0, cnt16 = 0; /* year counts*/

int err = fopen_s(&src, SRCFILE, "r");

if (err != 0) {

printf("failed open srs ");

return 1;

}

int err1 = fopen_s(&dst, DSTFILE, "w");

if (err1 != 0) {

printf("failed open dst ");

return 1;

}

while (fscanf_s(srs, "%4d %2d %2d", &year, &month, &day) != EOF) {

int year2d = year % 100;

fprintf_s(dst, "%20d/%20d/%20d", month, day, year);

printf("%02d/%02d/%02d", month, day, year);

if (year == 2016)

cnt16++;

if (year == 2017)

cnt17++;

}

fprintf_s(dst, " 2016: %d ", cnt16);

fprintf_s(dst, "2017: %d ", cnt17);

printf(dst, " 2016: %d ", cnt16);

printf(dst, "2017: %d ", cnt17);

if (fclose(src) != 0) {

printf("failed close src");

return 1;

}

if (fclose(dst) != 0) {

printf("failed close dst");

return 1;

}

getchar();

getchar();

return 0;

}

Machine_samples_1.txt

500001012803102008108305200010

100000010103312008110004000020

610000012301112007304303000025

500002020404232007218155200010

455002000004012008114308300008

100000010001112007219004000020

610000012310042007302453000025

100000010003312008110004000020

610000012410032007219253000025

610000012505222007301303000025

455001000011032007108308300008

455002000011032007222008300008

100000010008232007303154000020

100000010103312008217204000020

500001012804012008109305200010

610000012403312008222003000025

500002020402282007113255200010

610000012306242007114303000025

100000010109082007216304000020

455001000004343007215008300008

500001012804012008219405200010

500002020403312008114005200010

610000012404012008303153000025

610000012509082007109303000025

455001000004012008108308300008

100000010208232007219304000020

500001012803312008113255200010

100000010203312008301304000020

500002020404012008110305200010

610000012303312008109303000025

100000010209082007114304000020

610000012503312008304303000025

455002000004343007215008300008

500001012801052007108305200010

500001012801132007109305200010

610000012401132007222003000025

500002020401202007113255200010

610000012301202007114303000025

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>

int countline(char *fname);

void main(int argc, char *argv[])
{
printf("No of LINES: %d ",countline(text.txt));   
char txt[50],str2[20], scode,time[4],dfcod[2],dsamp[5];
int i;
for (i=1, i<=line, i++) //each line is stored in a string array
{
while(line--){
fscanf(fname,"%s",&txt[i]);

printf("machine number is %s, txt[10]);// first 10 letters is printed
//string manipulation required to print the rest of the data
//extract the data from 11th position 12 numbers
for(int n=11,n<=18,n++)
{
for(int m=1,m<=12,m++)
{
str[m] = txt[n]
printf("on the date %s, str[m]);
}
}
for(int n=19,n<=20,n++)
{
scode = txt[n]
printf("digit shift code is %c, scode)

}
for(int n=20,n<=24,n++)
{
for(int m=1,m<=4,m++)
{
time[m] = txt[n]
printf("on the time %s, time[m]);
}
}
for(int n=25,n<=26,n++)
{
for(int m=1,m<=2,m++)
{
dfcod[m] = txt[n]
printf("data format code %s, dfcod[m]);
}
}
for(int n=27,n<=32,n++)
{
for(int m=1,m<=5,m++)
{
dsamp[m] = txt[n]
printf("data sample is %s, dsamp[m]);
}
}
i++;


}   
}

}


int countline(char *fname)
{
// this opens the file in fname in read mode   
FILE *filep = fopen(fname,"r");
int c=0;
int line=0;

if (filep == NULL)
return 0;

while(!feof(filep))
{
char = fgetc(filep);
if(c == ' ')
{
line++;
}
}
fclose(filep);
return lines;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote