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

Design and implement a class Province that stores the name of the province, the

ID: 3716583 • Letter: D

Question

Design and implement a class Province that stores the name of the province, the name of premier of the province, its population and the number of cities. The class should have one get_data method to read the values of the class variables. Then write an application driver class that reads the data of three Canadian provinces and prints:

A. The name of the province whose premier`s name is on top of the list of all premiers name in asending alphabetical order.

B. The name of the province, that has the largest population.

C. The name of the two provinces, which have the lowest number of cities.

Please can you use the basic java programming language as i am a new student to Java

Explanation / Answer

#include <iostream>

using namespace std;

class Province{
private:
string name;
string premier;
int population;
int cities;
public:
void get_data();//get data from input
string get_name(){
return name;
}
string get_premier(){
return premier;
}
int get_population(){
return population;
}
int get_cities(){
return cities;
}
int operator != (const Province &b){//Assuming province names are unique
return name != b.name;
}
};

void Province::get_data() {
cout<<"Enter Province name: ";
getline(cin,name);
cout<<"Enter Premier name: ";
getline(cin,premier);
cout<<"Enter the population of the province: ";
cin>>population;
cout<<"Enter number of cities in the province: ";
cin>>cities;
cin.get();
}

Province max_premier(Province arr[],size_t size){//size_t is a standard unsigned integer used for size info
int max=0;
for (size_t i = 0; i < size; i++) {
if( arr[i].get_premier() > arr[max].get_premier()){
max = i;
}
}
return arr[max];
}

Province* twolowest_cities(Province arr[],size_t size){//size_t is a standard unsigned integer used for size info
int min=0;
Province *res = new Province[2];
for (size_t i = 0; i < size; i++) {
if( arr[i].get_cities()<arr[min].get_cities()){
min = i;
}
}
res[0] = arr[min];
min = (min+1)%size;//take another element as candidate second min
for (size_t i = 0; i < size; i++) {
if( arr[i].get_cities()<arr[min].get_cities() && arr[i]!=res[0]){
min = i;
}
}
res[1] = arr[min];
return res;
}

Province max_population(Province arr[],size_t size){//size_t is a standard unsigned integer used for size info
int max=0;
for (size_t i = 0; i < size; i++) {
if( arr[i].get_population() > arr[max].get_population()){
max = i;
}
}
return arr[max];
}

int main(int argc, char const *argv[]) {
Province arr[3];
Province cur;
Province *low;
for (size_t i = 0; i < 3; i++) {
arr[i].get_data();
}
cur = max_premier(arr,3);
cout<<"Name of provice at top according to order of premiers: "<<cur.get_name()<<' ';
cur = max_population(arr,3);
cout << "Name of province with max population: "<< cur.get_name() << ' ';
low = twolowest_cities(arr,3);
cout << "Two provinces with least number of cities:" << ' ';
for (size_t i = 0; i < 2; i++) {
cout << low[i].get_name() << ' ';
}
return 0;
}

Output:

Enter Province name:
West Bengal
Enter Premier name:
Mamata
Enter the population of the province:
100000000
Enter number of cities in the province:
1000000
Enter Province name:
Bihar
Enter Premier name:
Lalu
Enter the population of the province:
100000
Enter number of cities in the province:
1000
Enter Province name:
UP
Enter Premier name:
Nitish
Enter the population of the province:
100000
Enter number of cities in the province:
100
Name of provice at top according to order of premiers:UP
Name of province with max population:West Bengal
Two provinces with least number of provinces
UP
Bihar

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