Fishweights Problem

You are doing statistics on salmon fish weights randomly sampled from Maine lakes. At each of several sites across the state, data is collected weekly and given to you in a text file. The number of sites varies from week to week. Each line contains a lake identification number and a fish weight in pounds. Turn in source code and output sent to a text file.

Input: File fishweight.txt contains the data in the following format:
1000 4.0
1000 2.0
1100 1.5
1010 2.0
1010 2.2
1010 1.9
1100 2.8
1050 4.2
1100 1.7
1100 1.6
1050 2.2
1050 4.5
1100 4.0
1000 5.1
1000 3.4
1050 1.1
1010 1.2
1050 2.0
1000 2.6
1010 3.4
1010 3.9
1100 2.8
1100 1.6
1000 3.0
1010 5.3
1010 5.0
1100 4.7
1000 4.1
1050 3.6
1050 4.2
1100 3.9
1000 2.6
1010 1.9
1100 4.0
1010 5.0
1000 2.7
1010 3.1

An integer lake identification number is followed by a fish weight in pounds. Use this sample for your final run but note your code must work for any data set, including the empty one.


Output: Report in a text file a neat chart of the lake identification, lake name, and fish weight chart using field widths. Set precision to show one decimal place. Following the display of data, report the results of the following statistics. If the data set has no fish, after the count display “No statistics” as you are not able to generate average, maximum, or minimum.

Programmer Name
Overall number of fish collected
Average fish weight over all sites
Weight of heaviest fish over all sites (Hint: Assume the first fish is heaviest and see if any are larger.)
Weight of lightest fish over all sites (Hint: Assume the first fish is lightest and see if any are smaller.)

After the statistics display a histogram made of stars of the number of fish in each of the four lakes. For example, the following chart would display if there were 2 fish in Chemo, 3 in Greene, 5 in Hopkins, and 1 in Toddy. A sample histogram is shown below.

Lake Fish Count
----------------------------
Chemo **
Greene ***
Hopkins *****
Toddy *

The lake names are mapped to the lake IDs as follows.

Lake ID Lake Name
---------------------------------------
1000 Chemo
1010 Greene
1050 Hopkins
1100 Toddy

I'm so confused by this...can I use fstream to open the text file?
Last edited on
Yes, and you should.

What part of the assignment is confusing you?
Your code must work for any data set, including the empty one. What does that mean? Am I only using the four lakes? How am I supposed to know which lake goes with all of the ID's? How can the first fish be heaviest and the lightest?

So I sound stupid and this is what I have at the moment..

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

int main()
{
	int ID;		//lake ID
	char name;	//name of lake
	int weight;		//weight of fish in pounds
	int numFish;	//overall number of fish collected
	int avgFish; 	//average fish weight
	int maxWeight;	//weight of heaviest fish
	int minWeight;	//weight of lightest fish
	ifstream inFile; //declare input file stream object

	

	// Use to read from file
	inFile.open ("/Users/Maria/Documents/fishweights.txt"); 
	//Read lake id, fish weight
	inFile >> ID;
	inFile >> weight;
	inFile.close ();
	
	cout << fixed << showpoint << left << setprecision(1) << "Lake ID " << setw(10) << ID << endl;
	cout << fixed << showpoint << left << setprecision(1) << "Lake Name " << setw(10) << name << endl;
	cout << fixed << showpoint << left << setprecision(1) << "Fish Weight " << setw(10) << weight << endl;  
	
	return 0;
}
Last edited on
I would take that to mean if you get an empty data file your program would report something to the user like.

cerr << "Empty Data File";
Your code must work for any data set, including the empty one. What does that mean?
Did you read the next paragraph?


Am I only using the four lakes?
One assumes so since there are only 4 in the table.


How am I supposed to know which lake goes with all of the ID's?
The assignment tells you which lake goes with which ID.


How can the first fish be heaviest and the lightest?
If you have one fish and that fish's weight is 4.0, what is the weight of the lightest fish? What is the weight of the heaviest?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
	int id;		//lake ID
	wchar_t name;	//lake name
	wchar_t Chemo;
	wchar_t Greene;
	wchar_t Hopkins;
	wchar_t Toddy;
	int weight;		//weight of fish in pounds
	int numFish;	//overall number of fish collected
	int avgFish; 	//average fish weight
	int maxWeight;	//weight of heaviest fish
	int minWeight;	//weight of lightest fish
	ifstream inFile; //declare input file stream object

		
	if (id == 1000)
	{
		name = Chemo;
		cout << name;
	}
	
		
	if (id == 1010)
	{	
		cout << name;
		
	}
		
	if (id == 1050)
	{
		cout << name;
	}
		
	if (id == 1100)
	{
		cout << name;
	}
	
	numFish = 37;
	
	if (name == Chemo)
	{
		numFish = 9;
	}
	
	if (name == Greene)
	{
		numFish = 11;
	}
	
	if (name == Hopkins)
	{
		numFish = 7;
	}
	
	if (name == Toddy)
	{
		numFish = 10;	
	}
	
	if (numFish <= 0)
	{
		cout << "No statistics" ;
	}
		
	inFile.open ("/Users/Maria/Documents/fishweights.txt"); // Use to read from file
	//Read lake id, fish weight
	inFile >> id;
	inFile >> weight;
	inFile.close ();
		
	cout << fixed << showpoint << left << setprecision(1) << "Lake ID " << setw(10) << id << endl;
	cout << fixed << showpoint << left << setprecision(1) << "Lake Name " << setw(10) << name << endl;
	cout << fixed << showpoint << left << setprecision(1) << "Fish Weight " << setw(10) << weight << endl;  
		
	return 0;
}


Thank you. I'm slowly getting there...I know I don't have my data types right though. It won't show the lake name.
Last edited on
Topic archived. No new replies allowed.