Pseudo Code 1
Pseudo Code 1
Prepare a payroll earnings statements. All the employees are on commission basis of 12.5% of sales. Each month, they also receive a bonus that varies depending on the profit for the month and their length of service. Sales manager calculates the bonus and enters it with the salesperson's total sales for the month. The program has to calculate taxes and retirement for the month based on the following rates: Federal tax: state tax: retirement plan 25 % 10% 8%
Pseudocode
Program Payroll Calculation based on commission based on sales, and bonus. 1. Define commissionRate, FederalTaxRate, StateTaxRate and RetirementRate 2. getData (Total Sales, bonus) 3. assign Commission = calcComm(Total Sales) 4. assign Total Earning = Commission + Bonus 5. calcTaxes(total earning, FederalTax, StateTax ,Retirement) 6. display End Program Payroll ================== Get income Data ============================= Function getData 1. prompt user and read Total sales and bonus End Function getData ================== Calculate Commission ========================= Function calcComm 1. assign commission = commissionRate * Sales 2. return commission End Function calcComm ================== Calculate Taxes =============================== Function calcTaxes 1. assign fedTax = FederalTaxRate * Earning 2. assign stateTax = StateTaxRate * Earning 3. assign retirement = RetirementRate * earning End Function calcTaxes ================== Print Information ================================ Function display 1. display fedTax, stateTax, retirement, total deduction, sales, commission, bonus and net earning. End Function display
Problem 2
Write a function to compute the area and perimeter of a right angle triangle when given the length of the two smaller sides. use following formula: c2 = a2 + b2 and area = 0.5 * (a * b)
Pseudocode
Program Calculate area and Perimeter Calculation is based on given two sides of a right angle Triangle 1 getSides (side1, side2) 2 calcAreaPeri(side1, side2, area, peri) 3 display(side1, side2, area, peri) End Calculate area and Perimeter ================= Get two sides of a right angle triangle ================== Function getSides 1 Prompt user and read two sides of a right angle triangle End Function getSides ================= Calculate area and perimeter ========================= Function caclAreaPeri 1 Assign side3 = square root of (square of side1 + square of side2) 2 Assign area = (0.5 * side 1 * side 2) 3 Assign peri = (side 1 + side 2 + side 3) End Function calcAreaPeri ================ Print Results ==================================== Function display 1 Display side1, side2, area and perimeter End Function display
Problem 3
Write a program that determines a student's grade. It reads three test scores (1-100) and calls a function that calculates and returns a student's grade based on the following rules: If average is more than or equal to 90%, the grade is 'A'. if the average is less than 90% and more than or equal to 70%, it checks the third score. If the third score is more than 90%, the grade is 'A' otherwise it is 'B'. If the average is less than 70% and more than or equal to 50%, it checks the average of second and third scores. If the average of the two is greater than 70% the grade is 'C', otherwise it is 'D'. If the average is less than 50%, then the grade is 'F'.
Pseudocode
Program Grade Find grade for a student based on three scores 1 getData (score1, score2, score3) 2 assign Grade = findGrade(score1, score2, score3) 3 Display End Program grade ====================== Get Data =============================== Function getData 1 Prompt user and read three grades End Function getData ====================== findGrade ============================== Function findGrade Assign Average = findAve(score1, score2, score3) If (average >= 90) assign grade = A Else if (average >= 70) a. If (score3 > 90) assign grade = A b. Else assign grade = B c. End if 4 Else if (average >= 50) a. Assign lastTwoAverage = findLastTwoscoreAverage(score2, score3) b. If(lastTwoAverage > 70) assign grade = C c. Else assign grade = D d. End if 5 Else assign grade = F 6 End if 7 Return grade End Function findGrade 1 2 3
====================== Display Information ========================== Function display 1 Display score1, score2, score3 and grade End Function display ===================== Find Average ================================ Function FindAve 1 Assign average = (score1 + score2 + score3)/3.0 2 return average End Function findAve ===================== lastTwoAverage ============================= Function findLastTwoscoreAverage 1 assign lastTwoAverage=(score2+score3)/2.0 2 return lastTwoAverage End Function findLastTwoscoreAverage
Problem 4
Write a program to create a calendar for a year. The program reads the year from the keyboard. It then calculates which day of the week is the first day of the year and prints the calendar for that year. The program prompts the user for the input as shown below Enter the year for your calendar? 2000 The output is a calendar for the whole year. To print the correct calendar for the requested year, you must first find which day of the week is the first day of that year. This can be done with the following formula. ( ( ( (year 1) * 365) + (year-1)/4 (year-1)/100 + (year-1)/400) % 7) +1 You must also calculate leap years. The formulas for this calculation is (!(year%4) && (year%100) ) || !(year%400)
Pseudocode
Program printCalendar 1 prompt user to read Year 2 check whether input is valid 3 Loop (not valid) a. prompt user to input valid year 4 End Loop 5 Open datafile for output(if not possible print an error message) 6 Assign firstWeekDay= calcWeekDay(year) 7 PrintCalendartoOutFile 8 Close datafile End Program printCalendar ===================== calcWeekDay ============================== Function CalcWeekday 1 Calculate the first day of year given the year x using following formula (((x-1)*365)+((x-1)/4)-((x-1)/100)+((x-1)/400)+1)%7 2 return the value End Function CalcWeekday ==================== PrintCalendartoOutFile ======================= Algorithm printCalendartoOutFile given (firstweekday of year, year , output file) 1 Initiate months and daysInMonth (eg January,31 and February, 28) 2 for month February assign daysInMonth = daysInMonth + leapYear(year) 3 for months January to December 3.1 print days to the output file using printDay function 3.2 new week day of the first day in the month is given by week day%7 End Algorithm printCalendartoOutFile
==================== leapYear ========================== Function leapYear (year) 1 return (!(year%4) && (year%100) ) || !(year%400) End Algorithm leapYear ===================== Print Day ========================== Function printDay given (days in month, week position, output file)
1 Print days title to the output file(Sun Mon etc) 2 Print no of tabs to output file where no is the week position of the first day of the month 3 For day is 1 to daysInMonth to print day to the output file separated by tabs 3.1 increment week position by one 3.2 if week position is 7 print a new line to the output file 4 Print three new lines to the output file 5 Return weekDay as current weekday added with no of days in current month End Function printDay