Project 2: Election Spending

After an election, spending analysis is done by many organizations including government offices and watchdog groups. Most of this data is collected from Campaign Disclosure Statements filed by candidates and is publicly available.

In this project, we take our Candidate class from Assignment 9 to develop an analysis tool for election spending. We use a vector to make our list of candidates along with their votes and spending. Visualize the vector as a series of entries in a list. Each element of the vector represents a candidate. The entries are identified by a number as shown below.

candidates =

string name

int votes

double spending

[0]

string name

int votes

double spending

[1]

string name

int votes

double spending

[2]

The vector holds each Candidate object, one object to each slot (element) as shown. We can add or delete candidates in the list by adding or removing Candidate objects to and from the vector. Each object listed above holds three pieces of data. To access the data inside an object we use member functions like read(), print(), getName(), setName() and so on.

Keep the Candidate class name. Do NOT add any new member variables to the class (including vectors) and do not remove or modify any of the existing member functions specified in the last assignment, unless you had an error that you are correcting. Make sure to #include <climits> if you use INT_MAX and #include <cstdlib> if you use exit() to ensure the program compiles on all computers.

You must name the source code file election.cpp and include all your code in this single file.

Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.

Add a read() member function (and no other function) to your Candidate class. The function has no parameters and returns nothing. The read() function reads data from cin and stores it into the member variables of the Candidate object in the following order:

name

votes

spending

The read() function must operate like the following:

Enter the name of the candidate: Joe Schmoe
Enter the votes for Joe Schmoe: 24
Enter the spending for Joe Schmoe: 9876.54

In the above example, the user entered the values shown in aqua italics (for emphasis). The user must be able to enter spaces in the person's name as shown.

Use a vector to store your Candidate objects and add at least three of the persons from the previous assignment to the vector near the start of main().

Thus, your candidates list will have at least three candidates included automatically when your program starts.

Develop a menu to manage the candidates list that is redisplayed after each option is completed and looks like the following:

The user enters the number of the operation on the line labeled "Choice" where the underbar "_" is shown. The underbar "_" is shown for information only and is not part of the program display. Entering a 0 exits the program and that is the only way to exit the program. Do NOT change the number of a menu operation.

Hint: Place your menu in main() and call a non-member function to perform each menu option.

In addition to main() and the Candidate class member functions, define between three and eight non-member functions and call all the non-member functions at least once to perform an action.

Remember that a non-member function does not have a prototype declared inside the class.

Structure your code such to declare non-member function prototypes before main() and non-member function definitions after main() for all your functions.

Example Run: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and wording of the output. Data entry is shown in aqua italics for clarity only and is not part of the program display. For the input shown you must get the same output. However, the output must change properly if the inputs are different.

List the candidates in the candidates list, which includes the information from the print() function with a heading and item number starting at one as shown below.

Tutorial Lab

To prepare for the next lesson, complete the following exercises.

Type the in babynames.cpp program from the textbook on
pages 354-357 (332 -333)
into a text editor, and then compile and run the program. Submit the source code file (babynames.cpp) to Canvas for grading. Use the babynames.txt file to test your program.

Complete the Tutorial Exercises in CodeLab 10 and 11 before the specified due date. Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available. Click the "Solution" tab if you get stuck on a Tutorial problem.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Thus you should check your assignment against these criteria to maximize your score.

Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive. Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

Your assignment must work as submitted, so submit all the files needed to complete your assignment. Remember to test and double check your files before submitting them. If you make a mistake, you can resubmit up to the deadline. If you resubmit, you must include all your assignment files in the last submission as Canvas hides prior submissions.