All,
Here is a project I have been assigned and I am having trouble with the output of the report.dat file. I am hoping someone could help me out, I can not get the output file to look like the one in the example, thanks
Overview of Program Logic
1. You are to have a major while control loop that allows the user to enter data tree by tree until a tree number of 999 is encountered.
2. Program is to be modular and utilize getTreeNo, getSpeciesCode, getDbh, getTotHt, calcTotVol, and displayTreeData functions.
3. Edit the incoming data according to the stated specifications for legal data values. You are to use a do/while loop for data entry and keep the user in the loop until valid data is entered for the tree.
4. Total volume is calculated using the totalVol formula.
5. Write the respective tree data ( treeNo, speciesCode, dbh, totalHt, and totalVol.) for each entry once the entire record is validated. This output is to be stored on an external data file named report.dat.
6. Once a tree number of 999 is entered, the program should exit the while loop and then calculate and display (1) the total number of trees entered, and (2) the average total volume. (Note: the average totalVol is determined by the sum of totalVol values divided by the total number of trees.) The above output is to be displayed on report.dat as well as the standard cout device.
Your report should look similar to the following. Feel free to make the format a little more attractive and even up the spacing. The report is to be stored on report.dat external data file.
Forest Inventory Detail Edit and Volume Calculation
Tree No. Species Description DBH Tot. Ht. Tot. Vol.
123 11 Loblolly Pine 5.8 120 9.984
124 12 White Pine 10.2 140 32.575
125 22 RedOak 15.6 142 71.858
Total trees measured = 3
Average total volume = 38.19
int getTreeNo()
{
int input;
do
{
cout<<"Enter tree number(between 1-199) or 999 to finish: ";
cin>>input >>input >>input;
if((input<1||input>199)&&input!=999){
cout<<"Invalid number entered.\n";
}
}
while((input<1||input>199)&&input!=999);
return input, input, input;
}
//getSpeciesCode
int getSpeciesCode(int Table[],string Name[]){
int code;
int found=0;
double getDbh(){
double inches;
do
{
cout<<"Enter the number of inches(between 5 and 50.6): ";
cin>>inches >>inches >>inches;
if(inches<5||inches>50.6){
cout<<"Invalid number entered.\n";
}
}
while(inches<5||inches>50.6);
return inches, inches, inches;
}
//getTotHt
int getTotHt(){
int Ht;
do
{
cout<<"Enter the closest even total height(between 24-160): ";
cin>>Ht >>Ht >>Ht;
if((Ht<1||Ht>199)&&Ht%2!=0){
cout<<"Invalid number entered Note that it must be a even number.\n";
}
}
while((Ht<1||Ht>199)&&Ht%2!=0);
return Ht, Ht, Ht;
}
//calcTotVol
double calcTotVol(int code,int table[],double b0[],double b1[],double dbh, int totalHt){
int index;
double totalVol;
//find index
for(int i=0;i<6;i++){
if(code==table[i]){
index=i;
break;
}
}