In lines 94 and 95 i'm getting an error message that says
94 :invalid conversion from `int*' to `int'
94 :initializing argument 1 of `void Country::setPopulation(int)'
95 :no matching function for call to `Country::setArea(double[20])'
note :candidates are: void Country::setArea(double)
I can't seem to figure out what the issue is, I have run the whole program without using any arrays and it worked perfectly however after adding array's i get these issues that i'm don't know how to fix, can anyone help?
// This program implements a Rectangle class.
#include <iostream>
usingnamespace std;
constint MAX=20;
// Country class declaration
class Country
{
private:
int population;
double area;
public:
void setPopulation(int);
void setArea(double);
int getPopulation();
double getArea();
};
// Member function implementation section
//*******************************************************************
// Country::setPopulation *
// This function sets the value of the member variable population. *
// If the argument passed to the function is zero or greater, it is *
// copied into length. If it is negative, 1.0 is assigned to length.*
//*******************************************************************
void Country::setPopulation(int pop)
{
if (pop >= 0)
population = pop;
else
{ population = 1;
cout << "Invalid population. Using a default value of 1.0\n";
}
}
//*******************************************************************
// Country::setArea *
// This function sets the value of the member variable area. *
// If the argument passed to the function is zero or greater, it is *
// copied into width. If it is negative, 1.0 is assigned to width. *
//*******************************************************************
void Country::setArea(double a)
{
if (a >= 0.0)
area = a;
else
{ area = 1.0;
cout << "Invalid area. Using a default value of 1.0\n";
}
}
//****************************************************************************
// Country::getPopulation *
// getPopulation returns the value in the private member variable population.*
//****************************************************************************
int Country::getPopulation()
{
return population;
}
//********************************************************************
// Country::getArea *
// getArea returns the value in the private member variable area. *
//********************************************************************
double Country::getArea()
{
return area;
}
//*******************************************************************
// main *
//*******************************************************************
int main()
{
Country info[MAX]; // Declare a Country object
int num;
int infoPop[MAX];
double infoArea[MAX];
//Get info population and area
cin >> num;
for (int i=0; i < num; i++){
cout << "What is the population? ";
cin >> infoPop[MAX];
cout << "What is the area? ";
cin >> infoArea[MAX];
}
for (int i=0; i < num; i++){
// Call member functions to set info dimensions
info[i].setPopulation(infoPop);
info[i].setArea(infoArea);
}
// Call member functions to get info to display
cout << "\nHere is the data:\n";
for (int i=0; i<num; i++){
cout << "Population: " << info[i].getPopulation() << endl;
cout << "Area: " << info[i].getArea() << endl;
}
system("PAUSE");
return 0;
}
// This program implements a Rectangle class.
#include <iostream>
usingnamespace std;
constint MAX=20;
// Country class declaration
class Country
{
private:
int population;
double area;
public:
void setPopulation(int);
void setArea(double);
int getPopulation();
double getArea();
};
// Member function implementation section
//*******************************************************************
// Country::setPopulation *
// This function sets the value of the member variable population. *
// If the argument passed to the function is zero or greater, it is *
// copied into length. If it is negative, 1.0 is assigned to length.*
//*******************************************************************
void Country::setPopulation(int pop)
{
if (pop >= 0)
population = pop;
else
{ population = 1;
cout << "Invalid population. Using a default value of 1.0\n";
}
}
//*******************************************************************
// Country::setArea *
// This function sets the value of the member variable area. *
// If the argument passed to the function is zero or greater, it is *
// copied into width. If it is negative, 1.0 is assigned to width. *
//*******************************************************************
void Country::setArea(double a)
{
if (a >= 0.0)
area = a;
else
{ area = 1.0;
cout << "Invalid area. Using a default value of 1.0\n";
}
}
//****************************************************************************
// Country::getPopulation *
// getPopulation returns the value in the private member variable population.*
//****************************************************************************
int Country::getPopulation()
{
return population;
}
//********************************************************************
// Country::getArea *
// getArea returns the value in the private member variable area. *
//********************************************************************
double Country::getArea()
{
return area;
}
//*******************************************************************
// main *
//*******************************************************************
int main()
{
Country info[MAX]; // Declare a Country object
int num;
int infoPop = MAX; //<----
double infoArea = MAX; //<----
//Get info population and area
cin >> num;
for (int i=0; i < num; i++){
cout << "What is the population? ";
cin >> infoPop; //<----
cout << "What is the area? ";
cin >> infoArea; //<----
}
for (int i=0; i < num; i++){
// Call member functions to set info dimensions
info[i].setPopulation(infoPop);
info[i].setArea(infoArea);
}
// Call member functions to get info to display
cout << "\nHere is the data:\n";
for (int i=0; i<num; i++){
cout << "Population: " << info[i].getPopulation() << endl;
cout << "Area: " << info[i].getArea() << endl;
}
system("PAUSE");
return 0;
}