ICS 141 Programming with Objects

Program #2

Due Tuesday, February 3, 2004

35 points

 

COVER SHEET

 

Points Possible

Points

Earned

 

Comments

Design (5 pts):

D1:  Solution has two or more classes

D2: Class diagram includes methods, data and data types

D3:  Relationship between classes is correctly shown

 

 

Style (5 pts):

S1: Program comments

S2: Indenting and aligning

S3: Meaningful names

S4: Efficient code

 

 

Implementation (25 pts):

I1:  (2 pts) Program prompts for and reads the number of candidates

I2:  (4 pts) Program reads names and number of votes for each candidate

I3:  (4 pts) Program correctly displays all candidates names and number of votes

I4:  (4 pts) Program correctly displays the percentages of votes received for all candidates

I5:  (4 pts) Program correctly displays the winner

I6:  (4 pts) Program correctly uses arrays

I7: (3 pts) Output is attractive

 

 

 

I understand that I must turn in original and individual work.  I have not allowed anyone else to see my code.  I have not used someone else's work.

 

 

_____________________________________________________________________

Signature                                                                      Date

 

Print name here:  _______________________________________________________

 

 

 

 

Goals: To understand single dimensional arrays.

 

This assignment is designed to solidify array concepts.

 

The problem statement:

Write a program that allows the user to enter the number of candidates in an election, their last names, and the number of votes received by each candidate.  The program should then display each candidate’s name, the number of votes received by that person, and his or her percentage of the total votes received.  Your program should also display the name of the winner.  Make sure your output is attractively displayed.

 

Sample run:

 

Inputs:

            Number of candidates:   4

            Name:  Jones

            Votes:   5000

            Name:  Smith

            Votes   10000

            Name:  Nguyen

            Votes:   15000

            Name:  Kumar

            Votes:   2000

 

Outputs:

Candidate         Votes Received             % of Total Votes

Jones                5000                             15.63%

Smith                10000                           31.25%

Nguyen             15000                           46.88%

Kumar              2000                             6.25%

================== ======================

Total Votes       32000

 

The winner is Nguyen

 

The design:

Use two classes to do the job. The two classes are the worker class and the application class.  The worker class is problem specific and the application class is generic.  The application class will take care of the setup overhead and manage the interface with users.  Finally, the application class will create an instance of the worker class, initialize it and run it.  The relationship between the worker class and the application class is an association relationship. 

 

Your program will require at least two arrays – one for the names of the candidates and one for the number of votes he or she received.

 

Implement your program using a number of methods.  That is, break the problem into small pieces and solve the pieces one at a time.

 

Draw the class diagram.

 

Do screen captures of at least two of the program’s runs.

 

Include comments in your programs.  At a minimum, include the following information at the top of every file:

 

Your name:

Date:

Name of the class:

Brief description of the class:

 

Include additional comments as needed to make the program clearly understandable.

 

Turn in:

1. The cover sheet for this assignment.

2. A diskette containing your source code.  DO NOT EMAIL YOUR SOLUTION TO ME.  Your diskette should contain only work for this class.  Each assignment should be organized in a separate directory.  Label your diskette (or CD).

3. Print outs of your source code.

4. Print outs of at least two runs of your program (use screen capture).

5. A class diagram.