E
EkteGjetost
This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.
The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
Unfortunately for me, none of them are usefull at all, so pretty much i
don't have a clue as to what i should do.
I haven't read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you've basically
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.
Here's what i have to do:
Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80
Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn't open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You'll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
• A function to print the summary report (described above)
• A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
• A for loop (count the # of lines using expr1 & expr3)
• Two text files (one for input, the other for output)
but desperate situations call for desperate measures.
The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
Unfortunately for me, none of them are usefull at all, so pretty much i
don't have a clue as to what i should do.
I haven't read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you've basically
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.
Here's what i have to do:
Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80
Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn't open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You'll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
• A function to print the summary report (described above)
• A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
• A for loop (count the # of lines using expr1 & expr3)
• Two text files (one for input, the other for output)