Академический Документы
Профессиональный Документы
Культура Документы
Duration: 2 Hours
Learning Outcomes
This lab activity encompasses activities 4A(i), 4A(ii), 4A(iii) and 4A(iv).
By the end of this practical session, you should be able to :
SCENARIO:
En. Mohamed (IT Manager) ask Suria to manage staff salary so that process of calculating,
storing and accessing the data can be done easily. So Suria decide to use an array to manage
the data.
Activity 4A(i)
The following code illustrates how to declare and initial values into a one dimensional array, and
access its elements. Duration : 30 minutes
Step 1: Type the program given below:
cout<<"Staff ID \tSalary"<<endl;
for (int i=0; i<NUM; i++)
{
}
cout<<i<<"\t\t"<<salary[i]<<endl;
}
Activity 4A(ii)
The following code illustrates how to input values into a one dimensional array, and access its
elements.
Duration : 30 minutes
Step 1: Type the program given below:
#include <iostream.h>
#define NUM 10
void main()
{
int salary[NUM];
for (int i=0; i<NUM; i++)
{
cout<<"Input salary for staff ID "<<i<<" : ";
cin>>salary[i];
}
cout<<"Staff ID \tSalary"<<endl;
for ( i=0; i<NUM; i++)
{
cout<<i<<"\t\t"<<salary[i]<<endl;
}
}
Activity 4A(iii)
The following code illustrates how to input values into a two dimensional array, and access its
elements.
Duration : 30 minutes
Step 1: Type the program given below:
#include <iostream.h>
void main()
{
int OT[10][3];
for (int i=0; i<=9; i++)
{
for (int j=0; j<=2; j++)
{
cout<<"Input OT payment "<<j+1<<" for staff ID "<<i<<" : ";
cin>>OT[i][j];
}
}
cout<<"Staff ID \tOT 1 \t\tOT 2 \t\tOT 3"<<endl;
for ( i=0; i<=9; i++)
{
cout<<i<<"\t";
for (int j=0; j<=2; j++)
{
cout<<"\t"<<OT[i][j]<<" \t";
}
cout<<endl;
}
}
Activity 4A(iv)
Suria want to calculate average OT payment for all staffs but she did not know how to edit the
program. Help Suria to complete the program below:
Duration : 30 minutes
Step 1: Type the program given below and fill in the blanks with the correct code.
#include <iostream.h>
void main()
{
int OT[10][3], total, average;
double avg;
";