Professional Documents
Culture Documents
ASSIGNMENT 1
Question 1
Write pseudocode and complete C++ program to ask the user to enter the required data to
calculate the area of the circle and square. The formulas to calculate the respective areas
are as follows:
Question 2
Write the pseudocode to enter a number from the user. Then, display the Fibonacci series of
the number. For example, the Fibonacci series are as below:
(10 marks)
Question 3
A XOX finance company will give a loan to a customer for buying a car based on the amount
of the loan. If the loan is RM100,000 or more, the interest rate will be 3.5%, otherwise, it will
be 5% annually. Given the amount of the loan and the period of repayment, write the
pseudocode to calculate the amount of interest and the monthly payment or installment.
(10 marks)
Question 4
The ABC telephone company gives its customers two types of packages, package A and
package B. For each package, there is a basic charge and the customer is allowed to make
free phone calls for up to a certain number of minutes. Any additional call will be charged 10
cents per minute. The customers are also given a certain number of free SMS. Additional
SMS will be charged 15 cents per message.
charge = basic charge + (total minutes – free call) x 0.10 + (total sms – free sms) x 0.15
3 CS/20222/CSC402/A1
Question 1
1. Start
2. Initialize constant pi=3.142
3. User enter radius and length
4. Calculate area_circle=pi x radius
5. Calculate area_square= length x length
6. Print area_circle and area_square
7. End
#include<iostream>
#include<cmath>
using namespace std;
int main(){
float const pi=3.142;
float areacircle,areasquare,length,radius;
areacircle= pi*radius*radius;
areasquare= pow(length,2);
Question 2
1. Start
2. User enter n
3. Initialize int arrFab[n], term1=0, term2=1, nextT
4. Set arrFab[0]=term1, arrFab[1]=term2
5. For j=2, j<n+1 //j=2 because two slot in array occupied
5.1. next equal to sum of term1 and term2
5.2. term1 =term2, term2=nextT, arrFab[ j ]= next
5.3. j increment by 1
6. loop
7. For a=0, a<n+1 //a as the displayed term n number
7.1. Print a
7.1.1. For b=0, b<a //b as address of fabonacci series in array arrFab[ ]
7.1.2. Print arrFab[b]
7.1.3. b increment by 1
7.1.4. loop
7.2. a increment by 1
7.3. loop
8. end
6 CS/20222/CSC402/A1
#include<iostream>
arrFab[0]=term1;
arrFab[1]=term2;
for(j=2;j<i+1;j++){
nextT=term1+term2;
term1=term2;
term2=nextT;
arrFab[j]=nextT;
}
for(a=0;a<i+1;a++){ //display fabonacci
cout<<a<<"\t\t\t ";
for(b=0;b<=a;b++){
cout<<arrFab[b]<<" ";
}
cout<<endl;
}
int main(){
int n,j,next_t;
printFabo(n);
cout<<"_______________________________________________________
_____________________________________"<<endl;
return 0;
}
7 CS/20222/CSC402/A1
Question 3
1. start
2. user enter loan, period(in year)
3. if loan<100 000
3.1. rate=0.05
4. else
4.1. rate=0.035
5. calculate amount_interest=loan x rate x period
6. calculate monthly_installment=(loan + amount_interest) / (period x 12)
7. print amount_interest, monthly_installment
8. end
8 CS/20222/CSC402/A1
Question 4
a. input: package
output: charge
process: charge= basic charge+ minute_charge + sms_charge
9 CS/20222/CSC402/A1
b. Flowchart
10 CS/20222/CSC402/A1
c. Pseudocode
1. start
2. user enter package, total min, total sms
3. if package is ‘A’
3.1. basic charge=100
3.2. free call=200
3.3. free sms=20
4. else if package is ‘B’
4.1. basic charge=125
4.2. free call=250
4.3. free sms=35
5. else
5.1. user enter package
6. calculate excess_minute=total minute-free call
7. calculate excess_sms=total sms-free sms
8. if excess_minute>0
8.1. minute_charge = excess_minute x 0.10
9. else
9.1. minute_charge= 0
10. if excess_sms>0
10.1. sms_charge=excess_sms x 0.15
11. else
11.1. sms_charge=0
12. calculate charge=basic charge + minute_charge + sms_charge
13. print charge
14. end
11 CS/20222/CSC402/A1
d. Coding
#include<iostream>
using namespace std;
int main(){
float
charge,total_min,total_sms,basic_charge,excess_minute,excess_s
ms,min_charge,sms_charge;
int free_call,free_sms;
char package;
do{
excess_minute=total_min-free_call;
excess_sms=total_sms - free_sms;
if(excess_minute>0){
min_charge=excess_sms*0.10;}
else{
min_charge=0;}
if(excess_sms>0){
sms_charge=excess_sms*0.15;}
else{
sms_charge=0;}
charge=basic_charge+min_charge+sms_charge;
return 0;
}