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

I\'m getting an Error: LNK1561: entry point must be defined. Can someone edit it

ID: 3678454 • Letter: I

Question

I'm getting an Error: LNK1561: entry point must be defined. Can someone edit it using mainly basic C++ such as object implementation or passing objects to functions and using class objects, I don't really get what's wrong with it but I am getting this error. Please don't change too much but if you do can you add comments to where changes are made so it will be easier to read for me. Thanks!

Prompt:

In a population, the birth rate and death rate are calculated as follows: Birth Rate = Number of Births ÷ Population Death Rate = Number of Deaths ÷ Population For example, in a population of 100,000 that has 8,000 births and 6,000 deaths per year, Birth Rate = 8,000 ÷ 100,000 = 0.08 Death Rate = 6,000 ÷ 100,000 = 0.06 Design a Population class that stores a current population, annual number of births, and annual number of deaths for some geographic area. The class should allow these three values to be set in either of two ways: by passing arguments to a three-parameter constructor when a new Population object is created or by calling the setPopulation, setBirths, and setDeaths class member functions. The class should also have getBirthRate and getDeathRate functions that compute and return the birth and death rates. Write a short program that uses the Population class and illustrates its capabilities. Input Validation: If a population figure less than 2 is passed to the class, use a default value of 2. If a birth or death figure less than 0 is passed in, use a default value of 0

Code:

#include
#include
#include

using namespace std;

class Population {
private:
int curPopulation;
int annualBirths;
int annualDeaths;

public:
Population();
Population(int a, int b, int d);
void setPopulation(int pop);
void setBirths(int births);
void setDeaths(int deaths);
double getBirthRate();
double getDeathRate();
};

void Population::setPopulation(int a)
{
if(a >= 2)
{
curPopulation = a;
}
else
a=2;
}

void Population::setBirths(int b)
{
if(b<0)
{
annualBirths=0;
}
else
annualBirths = b;
}

void Population::setDeaths(int d)
{
if(d<0)
{
annualDeaths=0;
}
else
annualDeaths = d;
}

double Population::getBirthRate()
{
  
double c = curPopulation;
double b = annualBirths;
double br = 0;
br = b/c;
cout << "The Birth rate is:" << br << endl;
return br;
}

double Population::getDeathRate()
{
double c = curPopulation;
double d = annualDeaths;
double dr = 0;
dr = d/c;
cout << "The Death rate is:" << dr << endl;
return dr;
}

Population::Population(void)
{

}

Population::Population(int a, int b, int c)
{
if (a<2)
{

p=2;

}
  
if(b<0)
{
annualBirths=0;
}
else
annualBirths = b;

if(c<0)
{
annualDeaths=0;
}
else
annualDeaths = c;

}

int main()
{
double d=0;
Population p1 = Population(100000, 8000,6000);

double d1, d2;
d1 = p1.getBirthRate();
d2 = p1.getDeathRate();
cout << endl;

Population p2;

int pop1,birth2,death3;
cout<<"Enter the poulation: ";
cin >> pop1;
p2.setPopulation(pop1);
cout << "Enter the number of Births: ";
cin >> birth2;
p2.setBirths(birth2);
cout << "Enter the number of Deaths: ";
cin >> death3;
p2.setDeaths(death3);
cout << endl;

double d3,d4;
d3=p2.getBirthRate();
d4=p2.getDeathRate();
cout << endl;

return 0;

}

Explanation / Answer

#include <iostream>

#include <iomanip>

using namespace std;

class Pop            //decllare a class

{

                private:

                                int population;         //member variables

                                int births;

                                int deaths;

                               

                                public:

                                void setPopulation(int);    //function prototypes

void setBirths(int);

void setDeaths(int);

int getPopulation();

double getBirthRate();

double getDeathRate();

Pop():

population(0),

births(0),

deaths(0) {

}                              };

void Pop::setPopulation(int p) {population = p;

}

void Pop::setBirths(int b)  {births = b;}

void Pop::setDeaths(int d) {deaths = d;

}

int Pop::getPopulation(){return population;

}

                               

                                double Pop:: getBirthRate()

                                {return births/static_cast <double>(population);

                                }

                               

                                double Pop::getDeathRate()

                                {

                                                return deaths/static_cast <double>(population);

                                }

                               

                               

                                int main()

                                {

                                                Pop myTown;

                                                int numPeople;

                                                int numBirths;

                                                int numDeaths;

                                               

                                               

                                                cout<<"Enter the total population ";

                                                cin>>numPeople;

                                               

                                                while(numPeople < 1)

                                                {

                                                                cout<<"value must be greater than 0, please re-enter ";

                                                                cin>>numPeople;

                                                }

                                               

                                                myTown.setPopulation(numPeople);

                                                cout<<"Enter annual number of births ";

                                                cin>>numBirths;

                                               

                                                while(numBirths < 0)

                                                {

                                                                cout<<"value cannot be negative, please re-enter ";

                                                                cin>>numBirths;

                                                }

                                               

                                                myTown.setBirths(numBirths);

                                                cout<<"Enter annual number of deaths ";

                                                cin>>numDeaths;

                                               

                                                while(numDeaths < 0)

                                                {

                                                                cout<<"value cannot be negative, please re-enter ";

                                                                cin>>numDeaths;

                                                }

                                               

                                                myTown.setDeaths(numDeaths);

                                               

                                                cout<<"population statistics ";

                                                cout<<fixed<<showpoint<<setprecision(3);

                                               

                                                cout<<" Population: " <<setw(7)<<myTown.getPopulation();

                                               

                                                cout<<" Birth rate: "<<setw(7)<<myTown.getBirthRate();

                                                cout<<" Death Rate:  "<<setw(7)<<myTown.getDeathRate()<<endl;

                                                 

                                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