Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I need to write a code in c++ computer science class and not sure how to writ

ID: 3689284 • Letter: H

Question

Hi I need to write a code in c++ computer science class and not sure how to write it

This is the assignment

Please note that this project indicates precisely what your program should accomplish, without a precise indication of how the program works. Part of your assignment is designing the techniques of how the program works.

Isle Royale is a remote wilderness island, isolated by the frigid waters of Lake Superior, and home to populations of wolves and moose. As predator and prey, their lives and deaths are linked in a drama that is timeless and historic. Their lives are historic because it has been documented for more than five decades. You will continue the research project that is the longest continuous study of any predator-prey system in the world.

Each year the populations of these animals varies according to these equations:

          New wolf population   = (1 - d + bG)F

          New moose population = (1 + r - rG/k - aF)G

The variables in these equations are:

          F = last year's wolf population (try about 100)

          G = last year's moose population (try about 10000)

          d = death rate of wolves (try about 0.1)

          b = conversion rate (try about 0.00001)

          r = growth rate of moose (try about 0.4)

          a = ability rate (try about 0.0005)                               

          k = carrying capacity of island (try about 30000)

These fancy phrases probably don't mean much to you, but the equations should be enough to program the simulation. If you want to find out more about this mathematical model, see the book Population Biology by P.W. Hendrick.

This program declares a group of constants and then uses a function to compute the wolf and moose populations over a period of 100 years. The constants and prototype for the function must be exactly these. (HINT: use an unnamed namespace):

const double DEATH_RATE = 0.1;

const double CONVERSION_RATE = 0.00001;

const double GROWTH_RATE = 0.4;

const double WOLF_ABILITY = 0.0005;

const int CAPACITY = 30000;

const int YEARS= 100;

void population(int wolves[], int moose[]);

// This function uses the declared constants to compute the wolf and

// moose population for future years, putting these values in

// wolves[0]...wolves[YEARS] and moose[0]...moose[YEARS].

// THIS FUNCTION DOES NOT WRITE ANY OUTPUT.

// IT JUST PUTS THE NUMBERS IN THE ARRAY.

void computeMinimum(const int data[], int &i);

// The function examines data[0]...data[YEARS] to find the minimum entry.

// The index of this entry is placed in the parameter i.

// If there are several equally small minimum elements, then i is set

// to the index of the first such item.

// THIS FUNCTION DOES NOT WRITE ANY OUTPUT.

// IT JUST PUTS THE NUMBERS IN THE ONE REFERENCE PARAMETER.

void computeMaximum(const int data[], int &i);

// The function examines data[0]...data[YEARS] to find the maximum entry.

// The index of this entry is placed in the parameter i.

// If there are several equally large maximum elements, then i is set

// to the index of the first such item.

// THIS FUNCTION DOES NOT WRITE ANY OUTPUT.

// IT JUST PUTS THE NUMBERS IN THE ONE REFERENCE PARAMETER.

Notice that the size of the two arrays must be at least YEARS+1 since the function will compute values for wolves[0]...wolves[YEARS] and moose[0]...moose[YEARS].

For this assignment (see Springboard - no late submissions), your program must produce an output of exactly this form into a text file name report.txt:

---------- Year ---------- Wolves ---------- Moose

                    0                         100                10000

                  10                         215                23238

                  20                      542                14541

                  30                         607                  8693

                  40                         518                  9005

                  50                         502                10676

                  60                         535                10476

                  70                         539                  9913

                  80                         529                  9975

                  90                         527                10168

                100                         531                10148

The minimum population for wolves was 100 in year 0.

The maximum population for wolves was 622 in year 26.

The minimum population for moose was 8338 in year 34.

The maximum population for moose was 23404 in year 9.

Please notice that the lines of dashes in the first line of the output have exactly ten dashes each. The numbers on the subsequent lines must line up as shown in the above example. In order to align such numbers, you will need to use the setw function from #include <iomanip>. This function produces an object that is sent to the file just before printing a number. For example, to print a number x using a total of 15 spaces, you would use the statement:

    file << setw(15) << x;

In addition to the items listed above, this version of the program is required to have the following items for us to test:

const int YEARS= 100;           // Number of years in the simulation

const int TABLE_INCREMENT = 10; // Size of the steps in the output table

To get the initial values for the wolves and mooses, use commandline arguments to pass in these values. Be sure to validate the input and convert them to integers. (Commandline arguments will be covered in Class/Lab).

The completed program should be able to execute without printing anything to standard output. To report errors to your user use standard error! Your program should only execute if two arguments are passed into it. (myprogram.exe 100 1000)

You should write and propose other functions as needed to satisfy your sense of top-down design and the required class style guide.

This is a complex project with a lot of working parts. START EARLY!

Code:

Use a header comment with your name and the purpose of the program.

Your design must include breaking your code into functions

Functions must use a separate file (.hpp)

Functions must have header comments that include the purpose of the function and the pre-condition and post-condition documentation as well.

Use appropriate file handling techniques and steps for ensuring file processing.

Use appropriate techniques and steps for initializing, building and processing the arrays.

Use appropriate code comments.

Use appropriate variable names.

Use good coding practices (i.e., spacing, indentation, etc.).

Use standard error for all error message (no cout statements should be found in this program)

Explanation / Answer

#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>


using namespace std;

int main()

{
int wolves [101];
int moose [101];
const int oldwolf = 100;
const int oldmoose = 10000;
const double deathrate = 0.1;
const double conversionrate = 0.00001;
const double growthrate = 0.4;
const double wolfability = 0.0005;
const int capacity = 30000;
const int years = 100;
double newwolf = (1-deathrate + conversionrate*growthrate)*oldwolf;
double newmoose = (1 + growthrate - growthrate*oldmoose/capacity - wolfability*oldwolf)*oldmoose;


void population(int wolves [], int moose []);
{
wolves [0] = 100;
moose[0] = 10000;
}
//Trying to place the correct population in
//the arrays
for (int i=1; i<=years; ++i){
wolves[i]=wolves[i-1];

}
for (int i=1; i <=years; ++i){
moose[i]= newmoose*i;
}


void computeMinimum(const int data[], int &i);
void computeMaximum (const int data[], int &i);

//Trying to write to a text document
ofstream outFile;
outFile.open("Report.txt", fstream::in|fstream::app);
outFile<<setw (60)<<"---------- Year ---------- Wolves ---------- Moose" << endl;
outFile<< years <<;
outFile<< wolves[] <<;
outFile << moose[] <<;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote