CSC121Assignment#4
Due 5/15/2023 by 11:59 pm
100 Points
Exercise #1 (30 Points)
Use a vector to solve the following problem. Read in 20 numbers, each of which is between 10 and
100, inclusive. As each number is read, validate it and store it in the vector only if it isn’t a duplicate of
a number already read. After reading all the values, display only the unique values that the user
entered. Begin with an empty vector and use its push_back function to add each unique value to the
vector.
SAMPLE RUN:
Enter an integer: 105
Enter an integer: 5
Enter an integer: 10
Enter an integer: 11
Enter an integer: 11
Enter an integer: 12
Enter an integer: 13
Enter an integer: 14
Enter an integer: 15
Enter an integer: 15
Enter an integer: 16
Enter an integer: 17
Enter an integer: 18
Enter an integer: 19
Enter an integer: 20
Enter an integer: 21
Enter an integer: 22
Enter an integer: 23
Enter an integer: 24
Enter an integer: 25
Enter an integer: 26
Enter an integer: 27
Enter an integer: 28
Enter an integer: 29
Unique values in the vector are:
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29↵
Exercise#2 (30 Points)
Use a one-dimensional array to solve the following problem: A company pays its salespeople on a
commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for
that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9
percent of $5000, or a total of $650. Write a program (using an array of counters), for a company with
20 employees, that determines how many of the salespeople earned salaries in each of the following
ranges (assume that each salesperson’s salary is truncated to an integer amount): a) $200-299 b) $300399 c) $400-499 d) $500-599 e) $600-699 f) $700-799 g) $800-899 h) $900-999 i) $1000 and over.
SAMPLE RUN:
Enter gross sales for salesperson #1: 1000.82
Enter gross sales for salesperson #2: 2342
Enter gross sales for salesperson #3: 2238.32
Enter gross sales for salesperson #4: 1230
Enter gross sales for salesperson #5: 8453
Enter gross sales for salesperson #6: 7238
Enter gross sales for salesperson #7: 8991
Enter gross sales for salesperson #8: 131
Enter gross sales for salesperson #9: 2831.47
Enter gross sales for salesperson #10: 7932
Enter gross sales for salesperson #11: 2238
Enter gross sales for salesperson #12: 8927
Enter gross sales for salesperson #13: 8278
Enter gross sales for salesperson #14: 7839.12
Enter gross sales for salesperson #15: 7789
Enter gross sales for salesperson #16: 2072
Enter gross sales for salesperson #17: 5890
Enter gross sales for salesperson #18: 8084
Enter gross sales for salesperson #19: 7673.54
Enter gross sales for salesperson #20: 3149
Count of employees in each salary range:
The number of salespeople earning in range $200 – 299: 2
The number of salespeople earning in range $300 – 399: 2
The number of salespeople earning in range $400 – 499: 5
The number of salespeople earning in range $500 – 599: 0
The number of salespeople earning in range $600 – 699: 0
The number of salespeople earning in range $700 – 799: 1
The number of salespeople earning in range $800 – 899: 2
The number of salespeople earning in range $900 – 999: 6
The number of salespeople earning in range $1000 and over: 2
Exercise#3 (40 Points)
Using the following UML diagram as a reference, create the classes. It is common practice to leave out
the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many
of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator
(setter) for every class attribute.
Understanding the UML Class Diagram
1. The first section specifies the class name.
2. The second section specifies the attributes (Data Members)
3. The third section specifies the behaviors (Methods)
The first character specifies the access specifier value, where
•
•
•
“-” means that the class member is private
“#” means that the class member is protected
“+” means that the class member is public.
Benefit Class
-healthInsurance:string
-lifeInsurance:double
-vacation:int
+Benefit( );
+Benefit(health:string, life:double, vacay:int);
+ void displayBenefits( );
Employee Class
-firstName:string
-lastName:string
-gender:char
-dependents:int
-annualSalary:double
-benefit:Benefit
+Employee( );
+Employee(fname:string, lname:string,gen:char,dep:int, benefits:Benefit);
+void DisplayEmployee( );
Code the Benefit Class
An employee typically has benefits, so:
1.
Create a Benefits class.
Creating the Employee Class
1. The default constructor should set the attributes as follows: firstName = “not given”, lastName =
“not given”, gender = “U” (for unknown), dependents = 0, and annualSalary = 20,000.
2. The multi-arg constructor should initialize all of the attributes using values passed in using its
parameter list.
3. As shown in the Class diagram, each attribute should have a “getter” to retrieve the stored attribute
value, and a “setter” that modifies the value.
4. The calculatePay( ) method of the Employee class should return the value of annual salary divided
by 52 (return annualSalary / 52;).
5. The displayEmployee() method should display all the attributes of the Employee object in a wellformatted string with logical labels applied to each attribute. Don’t forget to call calculatePay from
within the displayEmployee method in order to display the Employee’s weekly pay as well!
6. Integrate the Benefit class into the Employee class. (Composition)
Testing (main)
Create one object of Employee using the default constructor and another with the overloaded
constructor.
2. For each object created, write statements to exercise each of the public methods listed in the Class
diagram.
3.
For each object created, invoke the object’s displayEmployee() method to display the
employee’s information.
Compile and Test
When done, compile and run your code. Then, debug any errors until your code is error-free. Check
your output to ensure that you have the desired output, modify your code as necessary, and rebuild.
1.