Question: C++ Coding. Write main, ElectoralMap.cpp and ElectoralMap.h. Homework 3 is all about creating an election simulator. For this programming exercise, you're going to work through
C++ Coding. Write main, ElectoralMap.cpp and ElectoralMap.h.

Homework 3 is all about creating an election simulator. For this programming exercise, you're going to work through some exercises that will be very helpful in getting started. 1. You may find incorporating map s into your program very helpful. Write the code for a class ElectoralMap that implements the singleton design pattern. When instantiated, this ElectoralMap should assign unique ids to 4 different District s and store them in a map with id mapping to District. Use a static field to help with the unique ids. i. Your District s should be a regular class. ii. You should override the operator for both the ElectoralMap and the District. ii. You should use a static const int field in your ElectoralMap to designate the number of District s. Example in Earth.h iv. Each District should start with a random area between 5 and 29 square miles. v. You should implement a get_district(int id) method in ElectoralMap that lets you access District s by id. vi. You do not need to implement any other methods. (Though you will want to for your complete homework!) vii. Test your code when you change your number of districts to a number other than 4 2. Write a main.cpp concurrently with step 1 and include adequate code to test your ElectoralMap and District classes. Note: do this PE even if you are doing the individual project--practice using maps, implementing singleton, and using static fields. To turn in: pe7.zip, including o Makefile o main.cpp o ElectoralMap.h (you can put both your ElectoralMap and your District class definitions here) o ElectoralMap.cpp Homework 3 is all about creating an election simulator. For this programming exercise, you're going to work through some exercises that will be very helpful in getting started. 1. You may find incorporating map s into your program very helpful. Write the code for a class ElectoralMap that implements the singleton design pattern. When instantiated, this ElectoralMap should assign unique ids to 4 different District s and store them in a map with id mapping to District. Use a static field to help with the unique ids. i. Your District s should be a regular class. ii. You should override the operator for both the ElectoralMap and the District. ii. You should use a static const int field in your ElectoralMap to designate the number of District s. Example in Earth.h iv. Each District should start with a random area between 5 and 29 square miles. v. You should implement a get_district(int id) method in ElectoralMap that lets you access District s by id. vi. You do not need to implement any other methods. (Though you will want to for your complete homework!) vii. Test your code when you change your number of districts to a number other than 4 2. Write a main.cpp concurrently with step 1 and include adequate code to test your ElectoralMap and District classes. Note: do this PE even if you are doing the individual project--practice using maps, implementing singleton, and using static fields. To turn in: pe7.zip, including o Makefile o main.cpp o ElectoralMap.h (you can put both your ElectoralMap and your District class definitions here) o ElectoralMap.cpp
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
