Uploaded by Solomone Pule

Assign1S11193979

advertisement
TEMO, Sakeo [S11193979]
CS111 Assignment 1, 2023, Semester 1
A write-up answering the questions in Section 2 and 4
SECTION 2
2.1
Write a pseudocode for your program
Step 01
BEGIN
Step 02
DISPLAY Welcome message and Program Specification(s)
Step 03
ASK IF User wants to Continue or Quit
Step 04
IF user chooses to Continue, go on to Step 05, IF user chooses to Quit, go to Step 22, OTHERWISE,
DISPLAY Invalid Input Message then go back to Step 03
Step 05
GET user’s name (First name and Surname)
Step 06
GET user’s Employee ID
Step 07
GET user’s Gender
Step 08
IF Gender is valid, go on to Step 09, OTHERWISE, DISPLAY Invalid Input Message then go back to Step 07
Step 09
GET user’s Year of Birth
Step 10
IF Birth Year is valid, go on to Step 11, OTHERWISE, DISPLAY Invalid Input Message then go back to Step
09
Step 11
GET Number of Hours Worked in a Week
Step 12
IF Number of Hours Worked is valid, go on to Step 13, OTHERWISE, DISPLAY Invalid Input Message then
go back to Step 11
Step 13
CALCULATE user’s Age
Step 14
CALCULATE Weekly Normal Pay
Step 15
CALCULATE Weekly Time and a Half Overtime Pay
Step 16
CALCULATE Weekly Double Time Overtime Pay
Step 17
CALCULATE Weekly Gross Pay (Normal + Time and a Half + Double Time)
Step 18
CALCULATE Annual Salary (Weekly Gross Pay * Number of Weeks in a Year)
Step 19
CALCUALTE Income Tax (As per gender and categorical rating)
Step 20
DISPLAY Result(s)
Step 21
Go back to Step 03
Step 22
END
2.2.1
Which variables do you need?
firstName, lastName, employeeID, userResponse, gender, birthYear, weeklyHoursWorked, age, timeAndHalfHours,
doubleTimeHours, weeklyGrossPay, annualSalary, incomeTax, validInput
2.2.2
Which variables do you use for input?
firstName, lastName, employeeID, userResponse, gender, birthYear, weeklyHoursWorked
2.2.3
Which types do you use for which variable. Explain why?
string for firstName and lastName since they are string of characters, and also for employeeID since it is a numerical data
to ne used in any numerical calculation
char for userResponse (which either a ‘C’ or ‘Q’) and gender (which is either a ‘M’ or a ‘F’), both one-character valued
variables.
int for birthYear, weeklyHoursWorked, age, timeAndHalfHours, doubleTimeHours for these are all integer-valued (whole
number value) variables, and they are used in numerical calculation(s).
float for weeklyGrossPay, annualSalary, incomeTax for they are all with currency/money values, plus, the hourly salary
rate which is used in the calculation of these, is a currency value also which may have decimal value(s).
bool for validInput which is a boolean variable having values true or false depending on the validity of input
encountered.
2.2.4
What type of loop is best to validate the input? What is the loop condition?
while loop
while (input is invalid) {
get input
validate input
}
2.3
Please describe at least three test cases that will allow you to assess whether the program is correct. Which
inputs should you choose, and what outputs would you expect? Answer in less than 300 words. Does your
program actually satisfy those test cases?
CASE 1:
Age < 55
We can assess this category as according to each gender and different tax rates. It is easy to mistaken calculate
data a male employee as a female, and to use the wrong tax rate category too.
Hence we can have different scenarios under this case; as one male and one for female.
For example, a 36-year-old male that worked 50 hours a week, the program should calculate:



weekly gross pay = (40 x 20) + (5 x 30) + (5 x 40) = 800 + 150 + 200 = 1150
annual salary = 1150 x 52 = 59800
tax = 59800 x 0.2 = 11960
CASE 2:
55 ≤ Age < 80
Since there is no genital parity with this age category, assessment can be towards the acceptance of the write
value of age, and also test out scenario for different tax rates.
EXAMPLE: With the age of 43 (born in 1980), and with annual income of 155480 (96 hours of work weekly), a
30% tax is to be charged.
Number of hours worked = 96
Weekly gross pay = (40 x 20) + (5 x 30) + (51 x 40) = 800 + 150 + 2040 = 2990
Annual salary = 52 x 2990 = 155480
Tax = 155480 x 0.3 = 46644
CASE 3:
Age > = 80
This seems to be the most trivial assessment as no tax to be paid is expected for this age category, regardless of
gender.
So if an employee who is 90-year old worked 14 hours a week:
Weekly gross pay = 14 x 10 = 280
Annual salary = 52 x 280 = 14560
Tax = 0
All of these 3 cases has been tested and my program seem to produce the right output as expected.
THINKING OUTSIDE THE BOX
As according to my codes of implementation, I have introduced a whole lot of constants to replace using of
literals in the program code; as thinking outside the box, here are some of the constants introduced:
// constants
const int
NORMAL_HOURS = 40,
TIME_HALF_HOURS = 45,
WEEKS_IN_YEAR = 52,
YOUNGEST_YEAR = 2007,
OLDEST_YEAR = 1933,
THIS_YEAR = 2023,
MAXIMUM_HOURS = 100,
MINIMUM_HOURS = 0;
// maximum normal hours of work per week
// maximum time and a half working hours
// multiplier for total number of weeks in a year
// employee must be 16 years or older
// employee must be 90 years old at most
// current year of calculation
// can only work up to 100 hours a week
// cannot allow negative hours
2.4 [Communicate & Apply Ethically] (8 marks)
The program for this assignment is honest, in that it reports honestly what the user provides as input. Of course,
rather than reporting what the user enters, your program could make a biased report - a preferred option - more
income or less tax if it wants to.
Would this be ethical to do? Would this be in line with the ACS Code of Ethics and with basic Programming
Ethics? Explain. Please answer in less than 300 words.
It is NOT ethical for my program to make a biased report for the sake of more income or less tax.
This is NOT in line with ACS Code Ethics as it defies the requirement of HONESTY. Such dishonesty is not a show of
competent and is not professional. Again dishonesty is a breach of the basic programming which also shows lack of
integrity and professionalism. Such act can also be harmful to some people even though it may seem to benefit some,
but not in an ethical manner
Section 4
4.1
Final Checklist
(a) Did you copy from other groups, other students, or public sources?
No
(b) Did you let other students copy from you?
No
4.2
(a) Did you put your name and student number on the first page? YES
(b) Did you put your name and student numbers into the program? YES
(c) Will you upload a write-up for Sections 2 & 4? YES
(d) Did you upload the program for section 3? YES
(e) Did you submit before the deadline? YES
Download