Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 12

[Type

DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

MACHINE PROBLEM #2: Calculating Gross Pay of an Employee


NAME: Limbo, Nia Lei Colleen - De Castro, Tyrone Ralph SECTION: C1A
START DATE: September 20, 2018 END DATE: September 20, 2018

I. OBJECTIVES

 To include a nested selection structure in pseudocode and in


flowchart
 To code a nested selection structure using the if statement.
 To recognize common logic errors in selection structures
 To include the switch form of the selection structure in pseudocode
and in a flowchart and to code a switch case.

II. DISCUSSION
Nested Selection Structures:
A nested selection structure is contained within the outer selection structure
– In the true path or in the false path
Use if more than one decision must be made before appropriate action can
be taken
Logic errors in selection structures are usually the result of:
– Using a logical operator rather than a nested selection structure
– Reversing the primary and secondary decisions
– Using an unnecessary nested selection structure
Multiple-Patch Selection Structures
You can create a selection structure that can choose from several alternatives
– Multiple-path selection structure
• Also called extended selection structure
• If selection structure has many paths from which to choose, it is
often simpler to use the switch form
• Also known as the case form

III. METHODOLOGY
Direction: Construct an IPO, draw a flowchart and write a program for the given
scenarios.
Using Nested Selection Structure:
An automobile shop wants you to write a payroll for its employees. The program
must calculate each employee’s net salary, that is, the salary after taxes. Prompt
the user for the employee’s pay rate, hours worked, employee code (either ‘A’ for

1
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

full-time ir ‘B’ for part time), and state code (either ‘Y’ for New York or ‘J’ for New
Jersey). Allow the user to enter either upper- or lowercase letters. The program
should display the regular pay, the overtime pay, the gross pay, the tax, and the
net pay. Calculate the gross pay as follows. If the employee worked 40 hours or
less, the regular pay is the pay rate times the hours worked, and the overtime
pay is zero. If the employee worked over 40 hours, the regular pay is the pay rate
times 40, and the overtime pay is 1.5 times the pay rate the hours worked over
40.
Using Multiple Path Selection Structure:
The Easy Living resort hotel wants you to write a program to calculate the base
charge for its guests. The program should prompt the user for the room type (‘G’
for garden view, ‘P’ for pool view, or ‘L’ for lake view) and the number of days the
guest is to stay. The program should also prompt for whether the guest is to have
a refrigerator in the room and whether there is to be an extra bed in the room.
The daily room rates are as follows. A garden view room is $125.00 each day; a
pool view room is $145.00 each day; a lake view is $180.00 each day. A
refrigerator costs $2.50 extra each day. An extra bed costs $15.00 extra each
day for either a garden view room or a pool view room, but costs $20.00 extra
each day for a lake view room. Calculate the total bill by multiplying the room rate
(adjusted for a refrigerator and extra bed, if necessary) by the number of days
the guest is to stay. The program should display the room type, the number of
days of the stay, the basic daily room rate, the daily charge for the
refrigerator and bed (only if the guest requests these), and the total change for
the stay.
IV. OUTPUT

Using Nested Selection Structure:

IPO CHART C++ Codes


Input // Nia Lei Colleen Limbo and Tyrone Ralph De Castro
Pay rate, hours // BSCS - C1A
worked, employee
// MP4
code and state code
// October 19, 2018

Process
1. Enter hours
worked, pay rate, #include <iostream>
employee code
and state code #include <iomanip>

2. If the hours
worked is using namespace std;
equivalent to 40
hours or less,
Compute regular
int main()
pay by
multiplying pay {
rate to hours
worked //Declare variables

3. Else if, the

2
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

worked hours is int employee = 0.0;


greater than 40
int payRate = 0.0;
hours, compute
regular pay by int hoursWorked = 0.0;
multiplying pay
rate to 40. int overtime = 0.0;
Calculate int grossPay = 0.0;
Overtime pay by
multiplying 1.5 to int regularPay = 0.0;
the pay rate of
int overtimePay = 0.0;
hours worked
greater than 40. int netPay = 0.0;
4. Calculate the double tax = 0.0;
sum of the
regular pay and double taxRate =0.0;
overtime pay to char stateCode=' ';
get the gross
pay. Calculate char employeeCode = ' ';
net pay by
char answer;
subtracting the
tax to gross pay
5. If the employee //Enter Input Items
code is ‘A’ and
the state code is cout<<"Do you want to process an employee?
‘Y’, the tax is 7%. (Y/N):";
If a part time cin>>answer;
employee, the
tax is 0 answer=toupper(answer);

6. If the employee
code is ‘A’ and
while (answer=='Y')
the state code is
not ‘Y’, the tax is
4.5% of the gross
pay. If a part time {
employee, the cout<<"Enter the number of hours worked in a
tax is 0 week: ";
7. Display the cin>> hoursWorked;
regular pay,
overtime pay, cout<<"Enter pay rate:$";
gross pay, tax
cin>> payRate;
and net pay
cout << "Enter employee code - A (full Time
8. If the user wants
Employee) B (Part Time Employee): ";
to input another
customer. cin >> employeeCode;
 Start the employeeCode = toupper (employeeCode);
process
// Validate employee code
from the
top. if(employeeCode != 'A' && employeeCode !=
'B')
{
cout << "Invalid employee code!";
Output
return(0);

3
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

regular pay, }
overtime pay,
gross pay, cout << "Enter state code - Y (New York) J(New
Jersey): ";
tax,
cin >> stateCode;
net pay, number
stateCode = toupper (stateCode);
of customers.
// Validate state code
.
if(stateCode != 'Y' && stateCode != 'J')
{
cout << "Invalid state code!";
return(0);
}

//computations
if (hoursWorked <=40)
{
grossPay = hoursWorked*payRate;
cout<< "Regular pay:
$"<<regularPay<<fixed<<setprecision(2)<<endl;
cout<< "Overtime pay is:
$"<<endl;

if (stateCode == 'Y')
if (employeeCode == 'A')
{
taxRate = 0.07;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else
{
taxRate = 0;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else

4
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

if (stateCode == 'J')
if (employeeCode == 'B')
{
taxRate = 0;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else
{
taxRate = 0.045;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else

cout<< "Overtime: 0 hours" <<endl;


cout<< "Overtime pay is:$"<<endl;
cout<< "Gross pay is:
$"<<grossPay<<fixed<<setprecision(2)<<endl;
cout<< "Tax pay is:
$"<<tax<<fixed<<setprecision(2)<<endl;
cout<< "Net pay is:
$"<<netPay<<fixed<<setprecision(2)<<endl;
}
else
{
regularPay = payRate * 40;
cout << "Regular Pay: $" << regularPay <<
fixed << setprecision(2) << endl;
overtime = hoursWorked - 40;
overtimePay = overtime * 1.5 * payRate;
grossPay = regularPay + overtimePay;

if (stateCode == 'Y')
if (employeeCode == 'A')
{
taxRate = 0.07;

5
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

tax = grossPay * taxRate;


netPay = grossPay - tax;
}
else
{
taxRate = 0;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else

if (stateCode == 'J')
if (employeeCode == 'B')
{
taxRate = 0;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else
{
taxRate = 0.045;
tax = grossPay * taxRate;
netPay = grossPay - tax;
}
else

//Display
cout << "Overtime Time: " << overtime << "
hours" << endl;
cout<< "Overtime pay:
$"<<overtimePay<<fixed<<setprecision(2)<<endl;
cout<< "Gross pay:
$"<<grossPay<<fixed<<setprecision(2)<<endl;
cout<< "Tax pay:
$"<<tax<<fixed<<setprecision(2)<<endl;
cout<< "Net pay:
$"<<netPay<<fixed<<setprecision(2)<<endl;
}

6
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

employee +=1;
cout<<"Do you want to process another
employee? (Y/N):";
cin>>answer;
answer=toupper(answer);

//endwhile

{
cout << "Number of Employee Processed:" <<
employee << endl;
}
}
return 0;
}
//End of main function

Flowchart:

7
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

Using Multiple Path Selection Structure:

IPO CHART C++ CODE


// Nia Lei Colleen Limbo and Tyrone Ralph De Castro
Input: // BSCS - C1A
Room Type // MP4
Number of Days // October 19, 2018
Extra Refrigerator
Extra Bed #include <iostream>
Process: #include <string>
1. Enter room type using namespace std;
and number of
days.
2. Indicate if you int main(){
would like to add an char room, ref, bed;
extra refrigerator
and an extra bed. char stopApp;

3. If the room type is int customers;


G int days;
 The room double rate, bill, charge, refCharge, bedCharge;
rate is $125.
string type;
Else
bool repeat;
 The room
type is P the
room rate is
do
$145.
{
Else
again:

The room
type is L the cout<<"Please enter room type. G for Garden
room rate is View, P for Pool View and L for Lake View : ";
$180.
cin>>room;
4. If the user wants an
additional
refrigerator cout<<"Enter number of days : ";
 Add an cin>>days;
additional
$2.50 to the
total charge. cout<<"Would you like to have a refrigerator in
5. If the user wants an the room? Y/N ";
additional bed cin>>ref;
 Add an
additional
$15 to the cout<<"Would you like to have an extra bed?
total charge. Y/N ";

8
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

6. If the user selects a cin>>bed;


Lake view room
and wants an
additional bed switch (room){
 The case 'G': case 'g':
additional
fee is $20 type="Garden";
instead of rate=125;
$15.
break;
7. Show the room
type, the number of case 'P': case 'p':
days
type="Pool";
of the stay, the
basic daily room rate=145;
rate, the daily
charge for the break;
refrigerator and bed case 'L': case 'l':
(only if the guest
requests these), type="Lake";
and the total
rate=180;
change for the stay.
break;
8. If the user wants to
input another default :
customer.
cout<<"Invalid input";
 Start the
}
process
from the top. switch (ref){
Output: case 'Y': case 'y':
Room Type refCharge=2.50;
Number of Days of Stay break;
Basic Daily Room Rate case 'N': case 'n':
Daily Additional Charges refCharge=0.00;
Total Charges break;
Number Of Customers default:
cout<<"Invalid input";
}
switch (bed){
case 'Y': case 'y':
if (toupper(room)=='L'){
bedCharge=20.00;
}
else {
bedCharge=15.00;
}

9
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

break;
case 'N': case 'n':
bedCharge=0.00;
break;
default:
cout<<"Invalid input";
}
charge=refCharge+bedCharge;
bill=(rate+charge)*days;

cout<<"Room type : " <<type<<" View" <<endl;


cout<<"Number of days : " <<days<<" days"
<<endl;
cout<<"Basic daily room rate : $ " <<rate
<<endl;
cout<<"Daily charge : $ " <<charge <<endl;
cout<<"Total Charge : $ " <<bill <<endl;

customers += 1;
cout << "Number of Customers Processed:" <<
customers << endl;

cout << "Do you want to continue? (Y/N)" <<


endl;
cin >> stopApp;
goto again;
} while(toupper(stopApp) == 'Y');

return 0;
}

10
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

Flowchart

11
[Type
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER SCIENCE DEPARTMENT
Computer Programming 1

V. GRADING CRITERIA (Pseudocode and Flowchart)

Beginning (1) Developing Accomplished Exemplary Score


(2) (3) (4)
Organization Not Some Organized, Good
and Layout organized, organization, flow for the organization,
flow makes flow slightly most part is flow is logical,
no sense and unclear clear and easy to
is not clear follow
Quality and Unable to Details are Some details Details are
Accuracy of find specific somewhat are not accurate.
Information details and/or ambiguous relevant to
details are and/ or process and
mostly somewhat chart contains
inaccurate inaccurate a few
inaccuracies
Construction All of the Most of the Some Symbols and
symbols and symbols and symbols and processes
processes processes processes used are all
are incorrect. are not clear used are not correct
and incorrect. clear and
incorrect

12

You might also like