Question: Design and code a class named Kingdom in the namespace westeros. The class should have two public members: m_name: a statically allocated array of characters

Design and code a class named Kingdom in the namespace westeros. The class should have two public members:

m_name: a statically allocated array of characters of size 32 (including '\0') that holds the name of the kingdom;

m_population: an integer that stores the number of people living in the kingdom.

Add to the westeros namespace, a function a function called display(...) that returns nothing, receives as a parameter a reference to an object of type Kingdom and prints to the screen the parameter in the following format:

KINGDOM_NAME, population POPULATION

Put the class definition and the westeros::display(...) declaration in a header named kingdom.h. Put the implementation of westeros::display(...) in a file named kingdom.cpp.

Complete the implementation of the w2_in_lab.cpp main module shown below (see the parts marked with TODO).

#include #include "kingdom.h"

using namespace std; using namespace westeros;

int main(void) { int count = 0; // the number of kingdoms in the array // TODO: declare the kingdoms pointer here (don't forget to initialize it)

cout << "==========" << endl << "Input data" << endl << "==========" << endl << "Enter the number of kingdoms: "; cin >> count; cin.ignore();

// TODO: allocate dynamic memory here for the kingdoms pointer

for (int i = 0; i < count; ++i) { // TODO: add code to accept user input for the kingdoms array } cout << "==========" << endl << endl;

// testing that "display(...)" works cout << "------------------------------" << endl << "The first kingdom of Westeros" << endl << "------------------------------" << endl; display(pKingdoms[0]); cout << "------------------------------" << endl << endl;

// TODO: deallocate the dynamic memory here

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!