Created
April 11, 2020 16:43
-
-
Save webber2408/1265b37bb8c223e31c84abbac70ea5e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
class Country{ | |
public: | |
string name; | |
int populationCount; | |
static int countryCount; | |
void setCountryDetails(string s, int n){ | |
this->name = s; // or name = s | |
this->populationCount = n; | |
countryCount++; | |
} | |
static int getTotalCountryCount(){ | |
return countryCount; | |
} | |
}; | |
int Country::countryCount = 0; | |
int main(){ | |
Country c1; | |
c1.setCountryDetails("India", 1300000000); | |
Country c2; | |
c2.setCountryDetails("USA", 328200000); | |
cout<<"Total Countries: "<<Country::getTotalCountryCount()<<endl; | |
} | |
/* | |
Output: | |
Total Countries: 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment