### tree volume

My code is not compiling. I need some assistance.Below is instructions for a tree volume program.

You have been contracted by Adcock Forest Products to produce a basic data input, edit, calculate volumes, and display details for a Forest Inventory System.

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.

Input is entered via the key board and consists of the following data for each sample tree:

Data Input Variables
Variable Name
treeNo
speciesCode
dbh
totalHt

Total Volume Calculation

Total volume of an individual tree is a function of dbh, species, and total height and has the following formula.

totalVol = b0 + b1 (dbh)2 ( totalHt)

b0 and b1 are regression coefficients for determining volume. Their values are determined by the two digit species code. To keep things simple, our C++ variables names for the coefficients are b0 and b1.

Tables
Location Species[6] speciesDes[6] b 0[6] b1[6]
0 11 Loblolly Pine 1.2446 .002165
1 12 White Pine 0.000 .002364
2 13 Red Pine 2.0822 .002046
3 21 White Oak .7316 .001951
4 22 Red Oak 1.6378 .002032
5 23 Other Oak .7554 .002174

Example of total volume calculation
Given: speciesCode = 13
dbh = 10.2
totalHt = 80

totalVol = 2.0822 + .002046 * 10.2 * 10.2 * 80 ;

totalVol = 19.111 cubic feet

Tree Data Constants and Calculated Results
Variable Name Data Type
treeNo int
speciesCode int
speciesDesc[6] string
dbh float
totalHt int.
totalVol double
Species[6] int
b0[6] double
b1[6] double
noTrees int
avgTotVol double

Function Description
getTreeNo Input tree number, input must be type int and > 0 and less than 200 or = 999. A value of 999 terminates input. Input is to be a do/while loop. Function is return by value.
getSpeciesCode Species code is type int and must be valid and found in the species table. Input is a do/while loop. Function is return by value.
getDbh Values are type float and must be greater than or equal to 5.0 and no greater than 50.6 inches. Is a return by value function.
getTotHt Values are type int and can range from 24 to 160. Total height is always measured as the closest even integer. For example, 131 would not be a valid measurement whereas 132 would be. A return by value function.
calcTotVol Calculate total volume (type float) using supplied formula. Output is 3 decimal places to the right of the decimal. Return by value function.

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.199

#include<stdio.h>

#include<iostream>
using namespace std;

class dat
{
public:
int tno,sc,db,ht,vol;
int te;
float sum;
void getip()
{
cout<<"enter tree no:";
cin>>tno;
if(tno==999)
exit(0);
cout<<"SpeciesCode:";
cin>>sc;
cout<<"Dbh:";
cin>>db;
cout<<"total height:";
cin>>ht;
cout<<"enter vol:";
cin>>vol;
disp();
}
void favg(int i,dat a[])
{ sum=0;
for(te=0;te<i;te++)
sum=sum+a[te].vol;
i++;
sum=sum/i;
cout<<"avg volume is :"<<sum<<endl;
}
void disp()
{
cout<<"tree no:";
cout<<tno<<endl;
cout<<"SpeciesCode:";
cout<<sc<<endl;
cout<<"Dbh:";
cout<<db<<endl;
cout<<"total height:";
cout<<ht<<endl;
cout<<"enter vol:";
cout<<vol<<endl;
}
}
int main()
{
dat a[100],temp;
int i,j,k;
i=0;
do
{a[i].getip();
i++;
cout<<"enter 1 to continue:";
cin>>j;
}while(j==1);
temp.favg(i,a);
system("pause");
return 0;
}

<errors>
(51): error C2628: 'dat' followed by 'int' is illegal (did you forget a ';'?)
(52): error C3874: return type of 'main' should be 'int' instead of 'dat'
(64): error C2440: 'return' : cannot convert from 'int' to 'dat'
Last edited on
Put your code in Code Marks.
Topic archived. No new replies allowed.