CSCI 160 Lab exercise 1: part 2

As with part 1, there are several key syntax elements you'll need to be familiar with. The core part 2 syntax elements can be found here.

For part 2, you'll be following similar steps as in part 1 except that you'll be creating a labex1 (instead of labex0) and you'll be writing the entire C++ program (your starting labex1.cpp file will just contain a single comment).

Refer back to the part 1 instructions if you forget the specifics of different steps.


labex1.cpp objectives

The objective for this exercise is to create and submit a complete and correct C++ program, adhering the the course code standards, with the following behaviour:

  1. The program is intended to calculate and display the vote share of three parties in an election, as a percent of the total votes cast, and also to calculate and display the percent of people who actually voted.

  2. The program stores a constant to represent the number of eligible voters, currently 16,164,886.

  3. The three parties in the election are Hodunk, Zaford, and Scav (aside: never pick names at the last minute when you're running short on imagination).

  4. The program prompts the user to enter the number of votes entered for the Hodunk, reads this and stores it. (No error checking is required on the validity of the user response.)

  5. The program prompts the user to enter the number of votes entered for the Zaford, reads this and stores it. (No error checking is required on the validity of the user response.)

  6. The program prompts the user to enter the number of votes entered for the Scavs, reads this and stores it. (No error checking is required on the validity of the user response.)

  7. The program then calculates and displays the percent of total votes that went to the Hodunk, followed by the percent of total votes that went to the Zaford, followed by the percent of total votes that went to the Scavs, followed by the percent of eligible voters who actually voted.

    Any percentages should be displayed in a format with exactly 2 digits following the decimal place, such as 9.31% or 27.84%.
Note: you may use either the iostream (cin/cout) or the cstdio (scanf/printf) approach for I/O, but pick one approach or the other, don't mix and match.


Suggested (iterative) development process

I strongly recommend adding and testing small parts of the program at a time, e.g.

Remember you must be in the correct directory, e.g. csci160/labex1, whenever you are working on the program, otherwise the necessary makefile and source code files are not present.

If you're unsure which directory you are in, enter the command
pwd
If you find you are in an incorrect directory then you can jump directly to the labex1 directory using the following command:
cd ~/csci160/lab1