Search Me..Find Best!

Sunday, April 6, 2014

C++ Source Code For Calculating The Population of a Country

c program example for calculating the Population of A country Using Classes in Object Oriented Programming... Object oriented Programming in C++
Course code is CS 241
Enjoy :)

/*courtesy imagzi.blogspot.com
*/

#include<iostream>
using namespace std;
class cntry{
private:
int pvn;
int ppl;
string name;
public:
cntry()//To initialize the values by constructor
{
cout<<"Enter the name of the country : ";
cin>>name;
}
void display()//display the cntry class data members
{
cout<<"The "<<name<<"'s ";
}
};
//to calculate and display the data members of province we make another class
class province{
private:
int cities,ppltn,a=0,pv[4];
public:
province()
{
cout<<"Entet the number of cities in the country : ";
cin>>cities;
cout<<"\nPlease enter the population of 4 province : ";
for(int i=0;i<=3;i++)
{
cin>>pv[4]; 
}

}
int add();
void display()
{
cout<<" has "<<cities<<" cities and "<<" 4 provinces .";
cout<<"\n the total Population of the country is : "<<a;
}


                                 
};
int province::add()
{
for(int i=0;i<=4;i++)
{
a+=pv[i];
 
}
return a;
}

int main()
{
cntry c;
province p;
c.display();
p.display();
}

0 comments:

Post a Comment