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.
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?
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..
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace 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;
}
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace 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.