helpppp!

I am need of help with this assignment.

PROGRAM SPECIFICATION
For the assignment, we will write a program that reads a file of information pertaining to a Farmer’s Market. The file contains the names of various farms participating in a Farmer’s Market. The program should create a file object for input, read the data, perform some calculations, create a report, and then rewrite the information to a new output file.
The format of the file is as follows:
Field or data item in the file Data type Notes
Farm name String of characters This could end with a comma
Count of item Integer Number of items
Item String Name of the item
Item price Float or double Unit cost of each item
Download the file (called ASSGN6-A.txt) to examine the contents. You should see that the name of the farm is delimited with a comma, and everything else is delimited with a space. When reading the information into your program, the comma after farm name and the space between each remaining field is consistent and guaranteed. Item is also guaranteed to be one word (so probably don’t need a getline). Also, we will not need to validate the information in this program. Valid data is also guaranteed! Your program will read the data items and output them to a report. The count of items should be multiplied by the item price, and that should be shown as well. The format should appear on the screen as follows:

==============================================================
= FARMER’S MARKET INVENTORY =
==============================================================
Collins Farm: 43900 tomatoes @ .67 each totaling $29413.00

Rutherford Farms, Inc.: 809 apples @ .90 each totaling $728.10


Grand total: 999999 items totaling $999999.99


Hint: Use setw() in conjunction with setfill(‘=’) for your headings. Use setw() to align your output for the farm name. The maximum farm name is 25 characters in length. The remainder of the line will be formatted as seen.

Read each item and output them to the console as you process the file. Your report will show every item in the file.

As you process this file, you will ALSO be creating an output file. Your program should open an output file object using the name of your choice for the text file, and name of your choice for the name in your program. Rewrite each line of the input file to the output file, adding a variable with the amount that you calculated from count of items multiplied by the item price. Make sure that you put a space before the new total. As an example, the first item should look like this in your file:

Collins Farm 43900 tomatoes .67 29413.00
- or –
Collins Farm 43900 tomatoes 0.67 29413.00
Do both the report and new file creation in the same loop. Otherwise, your program will be very inefficient. Make sure you break your code into functions. Open your files in main and pass them by reference.


Here is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
  ifstream in("ASSGN6-A.txt");

  if(!in) {
    cout << "Cannot open input file.\n";
    return 1;
  }

  char str[255];

  while(in) {
    in.getline(str, 255);  // delim defaults to '\n'
    if(in) cout << str << endl;
  }

  in.close();

  return 0;
}


ASSGN 6-A file
Collins Farm, 43900 tomatoes .67
Bart Smith Farms, 34910 cassavas .99
Allen Farms, 117 coconuts .54
River Run Farm, 103 taros .65
Big Top Farm, 109 artichokes 2.23
Big Top Farm, 777 crosns .28
Big Top Farm, 9739 cucumbers .53
Marble Farm, 108 crosns .33
Food For Life Inc., 106 carrots .87
Food For Life Inc., 86 coconuts .84
Johnson Farms, 121 parsnips .22
A1 Farm, 111 beets .12
A1 Farm, 5591 taros .72
Looney Tunes Farm, 102 onions .49
Wolfe Creek Farm, 103 rhubarbs 1.21
Wolfe Creek Farm, 199 radishes .71
James Farm, 47 pickles .68
Weaver Farms, 75 walnuts 2.50
Weaver Farms, 500 pickles .59
Pore Boy Farms, 670000 peanuts .79
Rutherford Farms Inc., 809 apples .90
Rutherford Farms Inc., 659 pickles .70
Javens Farm, 129000 figs .44
Harrison Farms, 8001 yams 1.09
Setzer Farms Inc., 701 potatoes .89
Setzer Farms Inc., 651 tomatoes .69
Pikes Peak Farm, 1045 turnips .79
Holland Area Farms, 10001 radishes .69









Last edited on
.
Last edited on
.
Last edited on
What do you have now?
Topic archived. No new replies allowed.