Lab Exercise 4: Function: Jabatan Teknologi Maklumat & Komunikasi

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

JABATAN TEKNOLOGI MAKLUMAT & KOMUNIKASI

LAB EXERCISE 4 : FUNCTION

DFC 2073 – PROGRAMMING FUNDAMENTALS

NAMA PENSYARAH – PUAN ROSMAYATI BINTI ISMAIL

NAMA AHLI :

MUHAMMAD RAFIUDDIN BIN MOHD ZAMRI


(12DNS17F1026)

AHMAD FIRDAUS BIN NGAH


(12DNSF1012)

1|Page
Answer 1

#include <iostream>
using namespace std;

int cal();
int main()
{
int monthly_salary, Annual_Salary;
cout<<"Keys in your monthly salary : ";
cin>>monthly_salary;

Annual_Salary = cal(monthly_salary,12);
cout<<"Annual Salary = "<<Annual_Salary<<endl;

system ("pause");
}
int cal(int monthly_salary, int Annual_Salary)
{
int r;
r = monthly_salary*12;
return r;
}

OUTPUT

2|Page
Answer 2

#include<iostream>
using namespace std;

char name[20],position[20],department[20];
int employee_id;
float net_salary,basic_salary,KWSP_deduction,KWSP;
void input_salary();
float calculate(float);
void display();
int main()
{
input_salary();
net_salary= calculate(basic_salary);
display();
system("pause");
return 0;
}

void input_salary()
{
cout<<"\t\t XYZ COMPANY"<<endl;
cout<<"\tSalary slip for july 2017"<<endl;
cout<<endl;
cout<<"Name :";
cin>>name;
cout<<"Employee ID :";
cin>>employee_id;
cout<<"Position :";
cin>>position;
cout<<"Department :";
cin>>department;
cout<<"Basic Salary :"<<"RM";
cin>>basic_salary;
cout<<endl;
cout<<endl;

}
float calculate(float salary)
{
KWSP=0.11;
KWSP_deduction=basic_salary*KWSP;
net_salary=basic_salary-KWSP_deduction;
return net_salary;
}
void display()
{
cout<<"KWSP deduction : "<<"RM"<<KWSP_deduction<<endl;
cout<<"Net Salary : "<<"RM"<<net_salary<<endl;
}

OUTPUT :

3|Page
4|Page

You might also like