Upload
amir-zaim-mohd-zaini
View
117
Download
4
Embed Size (px)
Citation preview
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CONTENTS……
QUESTION 1 ………. SOURCE CODE…………………………………………………………………… PSEUDOCODE…………………………………………………………………. FLOWCHART……………………………………………………………………. SAMPLE OUTPUT……………………………………………………………….
QUESTION 2 …… SOURCE CODE……………………………………………………………………… PSEUDOCODE…………………………………………………………………………. FLOWCHART………………………………………………………………………… SAMPLE OUTPUT……………………………………………………………………
QUESTION 3 …… SOURCE CODE…………………………………………………………………………… PSEUDOCODE………………………………………………………………………………. FLOWCHART………………………………………………………………………………….. SAMPLE OUTPUT…………………………………………………………………………..
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
QUESTION 1 ASSIGNMENT……………………
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
SOURCE CODE:
#include <iostream.h>
#include <string.h>
void main()
{
int ori_salary =0;
int new_salary =0;
char name[40];
int id;
cout << " Please input your name: " << endl;
cin.get(name, 40);
cin.ignore( 80, '\n');
cout << " Please input your id number: " << endl;
cin >> id;
cout << " Please input your current salary: " << endl;
cin >> ori_salary;
if ( ori_salary >= 3500)
{
new_salary = ori_salary + ( ori_salary * 0.075 );
cout << " Your current salary:" << ori_salary << endl;
cout << " Your new salary : " << new_salary << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " salary increased by 7.5% " << endl;
}
else if ( ( ori_salary >= 3000 ) && ( ori_salary <= 3499) )
{
new_salary = ori_salary + ( ori_salary * 0.15 );
cout << " Your current salary:" << ori_salary << endl;
cout << " Your new salary : " << new_salary << endl;
cout << " salary increased by 15% " << endl;
}
else if ( ( ori_salary >= 1500 ) && ( ori_salary <= 2999) )
{
new_salary = ori_salary + ( ori_salary * 0.25 );
cout << " Your current salary:" << ori_salary << endl;
cout << " Your new salary : " << new_salary << endl;
cout << " salary increased by 25% " << endl;
}
else if ((ori_salary > 0 ) && (ori_salary < 1500))
{
new_salary = ori_salary + ( ori_salary * 0.35 );
cout << " Your current salary:" << ori_salary << endl;
cout << " Your new salary : " << new_salary << endl;
cout << " salary increased by 35% " << endl;
}
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
else
{
cout << " INVALID VALUE!!! NO WAGES FOR YOU!" << endl;
}
}
ki
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
PSEUDOCODES:
Start
input name;
input id;
input ori_salary;
if ori_salary >=3500
then new_salary = ori_salary + ( ori_salary * 0.075 );
print ori_salary;
print new_salary;
print “Salary increased by 7.5 %”;
else if ori_salary > = 3000 AND ori_salary <= 3499
then new_salary = ori_salary + ( ori_salary * 0.15 );
print ori_salary;
print new_salary;
print “Salary increased by 15 %” ;
else if ori_salary >=1500 AND ori_salary <=2999
then new_salary = ori_salary + ( ori_salary * 0.25 );
print ori_salary;
print new_salary;
print “Salary increased by 25 %” ;
else if ori_salary >0 AND ori_salary < 1500
then new_salary = ori_salary + ( ori_salary * 0.35 )
print ori_salary;
print new_salary;
print “Salary increased by 35 %” ;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
else
print “INVALID VALUE!!! NO WAGES FOR YOU!"
endif
Stop
FLOWCHART:
START
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
Input name, id, ori_salary
If ori_salary
new_salary = ori_salary + ( ori_salary * 0.075 )
Print ori_salary, print new_salary , print “ salary increased by 7.5%
If ori_salary >= 3500 && ori_salary <=3499
new_salary = ori_salary + ( ori_salary * 0.15 )
Print ori_salary, print new_salary , print “ salary increased by 15%
If ori_salary >= 1500 && ori_salary <=2999
new_salary = ori_salary + ( ori_salary * 0.25 )
Print ori_salary, print new_salary , print “ salary increased by 25%
If ori_salary <
new_salary = ori_salary + ( ori_salary * 0.35 )
Print ori_salary, print new_salary , print “ salary increased by 35%
Print " INVALID VALUE!!! NO WAGES FOR YOU!"
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
SAMPLE OUTPUT:
Print " INVALID VALUE!!! NO WAGES FOR YOU!"
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
QUESTION 2 ASSIGNMENT……………………
SOURCE CODE:
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
#include <iostream.h>
void main()
{
long annual_income =0;
double tax_amount =0;
double net_income =0;
int status;
cout << " Please select your status first: " << endl;
cout << " 1. Single " << endl;
cout << " 2. Marital " << endl;
cin >> status;
switch ( status){
case 1 :
cout << " Please input your annual income " << endl;
cin >> annual_income;
if ((annual_income >0 ) && ( annual_income <=3000 ))
{
tax_amount = annual_income * 0.05;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " Your net income =" << net_income;
}
else if ( ( annual_income > 3000 ) && ( annual_income <= 5000))
{
tax_amount = annual_income * 0.075;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
cout << " Your net income =" << net_income;
}
else if ( ( annual_income > 5000 ))
{
tax_amount = annual_income * 0.1;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
cout << " Your net income =" << net_income;
}
else
{
cout << “ INVALID NUMBER!!!” ,, endl;
}
break;
case 2 :
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " Please input your annual income " << endl;
cin >> annual_income;
if (annual_income >0) && ( annual_income <=5000 ))
{
tax_amount = annual_income * 0.05;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
cout << " Your net income =" << net_income;
}
else if ( ( annual_income > 5000 ) && ( annual_income <= 8000) )
{
tax_amount = annual_income * 0.075;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
cout << " Your net income =" << net_income;
}
else if ( ( annual_income > 8000 ))
{
tax_amount = annual_income * 0.1;
net_income = annual_income - tax_amount;
cout << " Your tax amount =" << tax_amount << endl;
cout << " Your net income =" << net_income;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
}
else
{
cout << “ INVALID NUMBER!!!” << endl;
}
break;
default : cout << " INVALID VALUE " << endl;
}
}
PSEUDOCODES:
Start
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
Input status;
case based on the status
case 1:
status = single
if annual_income >0 AND annual_income <=30000
then tax_amount = annual_income * 0.05;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else if annual_income >30000 AND annual_income <= 50000
then tax_amount = annual_income * 0.075;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else if annual_income >50000
then tax_amount = annual_income * 0.1;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else
print “ INVALID NUMBER!!!”
endif
case 2 :
status = marital
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
if annual_income >0 AND annual_income <=50000
then tax_amount = annual_income * 0.05;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else if annual_income >50000 AND annual_income <= 80000
then tax_amount = annual_income * 0.075;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else if annual_income >80000
then tax_amount = annual_income * 0.1;
net_income = annual_income - tax_amount;
print tax_amount;
print income;
else
print “ INVALID NUMBER!!!”
endif
default : print “ INVALID VALUE!!!”
endcase
Stop
FLOWCHART
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
FROM FROM
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CASE 2 CASE 1
SAMPLE OUTPUT
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
QUESTION 3 ASSIGNMENT……………………
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
SOURCE CODE ( a very long ones)
#include <iostream.h>
#include <string.h>
int main()
{
int redeem;
char name [50];
long treat_points =0;
long balance =0;
long id;
cout << "*****************************" << endl;
cout << "......Yearly gift treats...." << endl;
cout << "****************************" << endl;
cout << " We're now offering treats to you..." << endl;
cout << " Here's the lists of gifts that you want to redeem: " << endl;
cout << endl;
cout << " Gift 1 : Nokia 5230 Nuron " << endl;
cout << " Code : ST0010 " << endl;
cout << " TreatPoints : 266500 " << endl;
cout << " HotDeals code : HST0011 " << endl;
cout << " TreatPoints + : 172000 + RM 680 " << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " extra charges for HotDeals " << endl;
cout << " Redeeming mode : " << endl;
cout << " 1. Standard " << endl;
cout << " 4. HotDeals " << endl;
cout << endl;
cout << " Gift 2 : Nokia 6210 - 3G Phone (Navigator) " << endl;
cout << " Code : ST0009 " << endl;
cout << " TreatPoints : 155500 " << endl;
cout << " HotDeals code : HST0012 " << endl;
cout << " TreatPoints + : 98000 + RM 480 " << endl;
cout << " extra charges for HotDeals " << endl;
cout << " Redeeming mode : " << endl;
cout << " 2. Standard " << endl;
cout << " 5. HotDeals " << endl;
cout << endl;
cout << " Gift 3 : Nokia 5800 Phone ( ExpressMusic)" << endl;
cout << " Code : ST0008 " << endl;
cout << " TreatPoints : 72500 " << endl;
cout << " HotDeals code : HST0013 " << endl;
cout << " TreatPoints + : 44000 + RM 280 " << endl;
cout << " extra charges for HotDeals " << endl;
cout << " Redeeming mode : " << endl;
cout << " 3. Standard " << endl;
cout << " 6. HotDeals " << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << endl;
cout << " Please input your name:" << endl;
cin.get(name,50);
cin.ignore(80,'\n');
cout << " Please input your card ID:" << endl;
cin >> id;
cout << " Please input your TreatPoints number value: " << endl;
cin >> treat_points;
cout << " Please input the redeeming mode : " << endl;
cin >> redeem;
switch ( redeem ) {
case 1 :
if ( treat_points >= 266500 )
{
balance = treat_points - 266500;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : ST0010 " << endl;
cout << " Type of gift : Nokia 5200 Nuron " << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " Extra charges : None " << endl;
cout << " Balance of treat points : " << balance << endl;
}
else
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
case 2 :
if ( treat_points >= 155500 )
{
balance = treat_points - 155500;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : ST0009" << endl;
cout << " Type of gift : Nokia 6210 - 3G Phone (Navigator) " << endl;
cout << " Extra charges : None " << endl;
cout << " Balance of treat points : " << balance << endl;
}
else
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
case 3 :
if ( treat_points >= 72500 )
{
balance = treat_points - 72500;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : ST0008" << endl;
cout << " Type of gift : Nokia 5800 Phone (ExpressMusic) " << endl;
cout << " Extra charges : None " << endl;
cout << " Balance of treat points : " << balance << endl;
}
else
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
case 4 :
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
if ( treat_points >= 172000 )
{
balance = treat_points - 172000;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : HST0011" << endl;
cout << " Type of gift : Nokia 5200 Nuron " << endl;
cout << " Extra charges : RM 680.00 " << endl;
cout << " Balance of treat points : " << balance << endl;
}
else
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
case 5 :
if ( treat_points >= 98000)
{
balance = treat_points - 98000;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : HST0012" << endl;
cout << " Type of gift : Nokia 6210 - 3G Phone (Navigator) " << endl;
cout << " Extra charges : RM 480 " << endl;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
cout << " Balance of treat points : " << balance << endl;
}
else
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
case 6 :
if ( treat_points >= 44000 )
{
balance = treat_points - 44000;
cout << " Customer card number : " << id << endl;
cout << " Coustomer name : " << name << endl;
cout << " Treat points : " << treat_points << endl;
cout << " Gift code : HST0013" << endl;
cout << " Type of gift : Nokia 5800 Phone (ExpressMusic) " << endl;
cout << " Extra charges : RM 280 " << endl;
cout << " Balance of treat points : " << balance << endl;
}
else
{
cout << " NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!" << endl;
}
break;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
default : cout << " WRONG CODE!!! NO GIFT FOR YOU!!!" << endl;
}
return 0;
}
PSEUDOCODE:
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
Start
Input id;
Input customer_name;
Input treat_points;
Input redeem;
case based on the redeem;
case 1:
redeem = 1;
if ( treat_points >= 266500)
then balance = treat_points – 266500;
print id;
print customer_name;
print treat_points;
print “ Gift Code : ST0010” ;
print “ Type of gift : Nokia 5230 Nuron” ;
print “ Extra charges : None”
print balance;
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
case 2:
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
redeem = 2;
if ( treat_points >= 155500)
then balance = treat_points – 155500;
print id;
print customer_name;
print treat_points;
print “ Gift Code : ST0009” ;
print “ Type of gift : Nokia 6210 – 3G Phone (Navigator)” ;
print “ Extra charges : None”
print balance;
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
case 3:
redeem = 3
if ( treat_points >= 72500)
then balance = treat_points – 72500;
print id;
print customer_name;
print treat_points;
print “ Gift Code : ST0008” ;
print “ Type of gift : Nokia 5800 Phone (ExpressMusic)” ;
print “ Extra charges : None”
print balance;
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
case 4 :
redeem = 4;
if ( treat_points >= 172000)
then balance = treat_points – 172000;
print id;
print customer_name;
print treat_points;
print “ Gift Code : HST0011” ;
print “ Type of gift : Nokia 5230 Nuron” ;
print “ Extra charges : RM 680”
print balance;
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
case 5:
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
redeem = 5;
if ( treat_points >= 98000)
then balance = treat_points – 98000;
print id;
print customer_name;
print treat_points;
print “ Gift Code : HST0012” ;
print “ Type of gift : Nokia 6210 – 3G Phone (Navigator)” ;
print “ Extra charges : RM 480”
print balance;
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
case 6:
redeem = 6;
if ( treat_points >= 44000)
then balance = treat_points – 44000;
print id;
print customer_name;
print treat_points;
print “ Gift Code : HST0013” ;
print “ Type of gift : Nokia 5800 Phone (ExpressMusic)” ;
print “ Extra charges :RM 280”
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
print balance;
else
print “NOT ENOUGH POINTS!!! PLEASE TRY AGAIN!!!"
endif
default:
redeem = 0;
print " WRONG CODE!!! NO GIFT FOR YOU!!!";
endcase
Stop
FLOWCHART
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2
SAMPLE OUTPUT
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING ASSIGNMENT 2