Question
Please Read Carefully Thank You! 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. Your C++ program should be modular (see the specified function table), contain no global variables, be clear and concise, have meaningful data names, and informative comments. 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
Explanation / Answer
//I've changed all floats into doubles--whoever gave you the project did alot of odd typecasting... #include #include #include using namespace std; //prototype int getTreeNo(); int getSpeciesCode(int[],string[]); double getDbh(); int getTotHt(); double calcTotVol(int,int[],double[],double[],double, int); void displayTreeData(ofstream&,int ,int ,int [], string [],double,int,double); int main(){ int treeNo,speciesCode,totalHt,noTrees; double dbh; double totalVol,avgTotVol; int Species[6]={11,12,13,21,22,23}; string speciesDesc[6]={"Loblolly Pine","White Pine","Red Pine","White Oak","Red Oak","Other Oak"}; double b0[6]={1.2446,0.000,2.0822,.7316,1.6378,.7554}; double b1[6]={.002165,.002364,.002046,.001951,.002032,.002174}; noTrees=0;//set number of trees to 0 avgTotVol=0.0;//set volume to 0 ofstream out("report.dat");//make a file out stream out