1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
char selectOption ();
void askOption ();
void getPPnoInOut(_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc);
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Yearstocalc);
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Inmigration, int Outmigration, int Yearstocalc);
void getPPwithInOut (_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Inmigration, int &Outmigration, int &Yearstocalc);
int main ()
{
char option;
_int64 populationStartSize;
int annualBirthRate;
int annualDeathRate;
int inMigration;
int outMigration;
int numberOfYears;
option = selectOption(); //exectues select option & ask option
switch (option)
{
case 'P': //Pull in/execute vales from PP without in and out
getPPnoInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);
calcAndPrintPopulationChange (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);
break;
case 'C': //Pull in/execute values from PP with In and out
getPPwithInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears, inMigration, outMigration);
calcAndPrintPopulationChange (populationStartSize, annualBirthRate, annualDeathRate, inMigration, outMigration, numberOfYears);
break;
case 'E': exit (0);
}
}
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Yearstocalc)
{
_int64 populationStartSize;
int annualBirthRate;
int annualDeathRate;
int inMigration;
int outMigration;
int numberOfYears;
int newpop;
getPPnoInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);
cout << "Starting population Size: " << populationStartSize << endl;
cout << "Birth Rate: " << annualBirthRate << endl;
cout << "Death Rate: " << annualDeathRate << endl;
cout << "Number of Years calculated: " << numberOfYears << endl;
for (int i = 0; i < numberOfYears; i++)
{
newpop = populationStartSize * (1+annualBirthRate/100)-(annualDeathRate/100*populationStartSize);
}
cout << "In " << numberOfYears << " years, the population will be " << newpop << "." << endl;
}
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Inmigration, int Outmigration, int Yearstocalc) //**This function is not complete yet.
{
_int64 populationStartSize;
int annualBirthRate;
int annualDeathRate;
int inMigration;
int outMigration;
int numberOfYears;
int newpop;
getPPwithInOut (populationStartSize, annualBirthRate, annualBirthRate, numberOfYears, inMigration, outMigration);
cout << "Starting population Size: " << populationStartSize << endl;
cout << "Birth Rate: " << annualBirthRate << endl;
cout << "Death Rate: " << annualDeathRate << endl;
cout << "In-Migration Rate: " << inMigration << endl;
cout << "Out-Migration Rate: " << outMigration << endl;
cout << "Number of Years calculated: " << numberOfYears << endl;
for (int i = 0; i < numberOfYears; i++)
{
newpop = populationStartSize * (1+annualBirthRate/100)-(annualDeathRate/100*populationStartSize);
}
cout << "In " << numberOfYears << " years, the population will be " << newpop << "." << endl;
}
void getPPnoInOut(_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc)
{
cout << "Input the starting population: "; //population
cin >> PopulationStart;
while (PopulationStart < 1)
{
cout << "Whoops! Population size must be larger than 0" << endl;
cout << "Input the starting population: " << endl;
cin >> PopulationStart;
}
cout << endl <<"Input the birth rate as an integer %: "; //birth rate
cin >> Birthrate;
while (Birthrate < 0 || Birthrate > 100)
{
cout << "Whoops! The Birth Rate must be greater that 0 but less than 100" << endl;
cout << "Input the birth rate as an interger %: ";
cin >> Birthrate;
}
cout << endl << "Input the death rate as an integer %: "; //death rate
cin >> Deathrate;
while (Deathrate < 0 || Deathrate > 100)
{
cout << "Whoops! The Death Rate must be greater that 0 but less than 100" << endl;
cout << "Input the death rate as an integer %: ";
cin >> Deathrate;
}
cout << endl << "Input the number of years for the calculation as an integer: "; //number of years
cin >> Yearstocalc;
while (Yearstocalc < 0 || Yearstocalc > 100)
{
cout << "Whoops! The number of years must be greater that 0 but less than 100" << endl;
cout << "Input the number of years for the calculation as an integer: ";
cin >> Yearstocalc;
}
}
void getPPwithInOut (_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc, int &Inmigration, int &Outmigration)
{
cout << "Input the starting population: "; //population
cin >> PopulationStart;
while (PopulationStart < 1)
{
cout << "Whoops! Population size must be larger than 0" << endl;
cout << "Input the starting population: " << endl;
cin >> PopulationStart;
}
cout << endl <<"Input the birth rate as an integer %: "; //birth rate
cin >> Birthrate;
while (Birthrate < 0 || Birthrate > 100)
{
cout << "Whoops! The Birth Rate must be greater that 0 but less than 100" << endl;
cout << "Input the birth rate as an interger %: ";
cin >> Birthrate;
}
cout << endl << "Input the death rate as an integer %: "; //death rate
cin >> Deathrate;
while (Deathrate < 0 || Deathrate > 100)
{
cout << "Whoops! The Death Rate must be greater that 0 but less than 100" << endl;
cout << "Input the death rate as an integer %: ";
cin >> Deathrate;
}
cout << endl << "Input the number of years for the calculation as an integer: "; //number of years
cin >> Yearstocalc;
while (Yearstocalc < 0 || Yearstocalc > 100)
{
cout << "Whoops! The number of years must be greater that 0 but less than 100" << endl;
cout << "Input the number of years for the calculation as an integer: ";
cin >> Yearstocalc;
}
cout << endl << "Input the In-migration rate as an integer %: ";
cin >> Inmigration;
while (Inmigration < 0 || Inmigration > 100)
{
cout << "Whoops! The In-migration rate must be greater than 0 but less than 100" << endl;
cout << "Input the In-migration rate as an integer %: ";
cin >> Inmigration;
}
cout << endl << "Input the Out-migration rate as an integer %: ";
cin >> Outmigration;
while (Outmigration < 0 || Outmigration > 100)
{
cout << "Whoops! The Out-migration rate must be greater than 0 but less than 100" << endl;
cout << "Input the Out-migration rate as an integer %: ";
cin >> Outmigration;
}
}
void askOption ()
{
cout << "Please select from the following options" << endl;
cout << /* need to setw << */ "Select 'P' for population growth without considering in or out-migration." << endl;
cout << /* need to setw << */ "Select 'C' for populating growth with in and out migration to be considered." << endl;
cout << /* need to setw << */ "Select 'E' to clost the program." << endl;
cout << /* need to setw << */ "Please note that the program is case sensitive!" << endl;
cout << /* need to setw << */ "Option (P, C, or E): " << endl;
return;
}
char selectOption ()
{
char option;
cout << "Welcome to the Population Growth Program" << endl;
askOption ();
cin >> option;
while (option != 'P' && option != 'C' && option != 'E')
{
cout << "Whoops! option must be either P, C, or E." << endl;
askOption ();
cin >> option;
}
return option;
}
| |