Lab Activity 3B PDF
Lab Activity 3B PDF
Lab Activity 3B PDF
K -01DDT19F2041(DDT2B)
Duration: 2 Hours
SCENARIO:
Help Suria to do some exercises to improve her skills in solving problems related to looping
control structures.
Activity 3B.1
Activity Outcome: Write a program using repetition control structures in solving the given
problems.
Duration : 180 minutes
1.a)
#include <iostream>
using namespace std;
int main ()
{
for (int counter=1, average=0, Total=0, number; counter > 0; counter++ )
{
cout << "Input number : ";
cin >> number;
Total = Total + number;
if (counter > 5)
{
average = Total / 5;
cout << "Total : " << Total;
cout << "\nAverage : " << average;
cout << "\n";
counter ++;
}
else
{
counter ++;
}
}
return 0;
}
1.b.
#include <iostream>
using namespace std;
int main ()
{
int counter = 1, average = 0, Total = 0;
while(counter > 0)
{
int number;
cout << "Input number : ";
cin >> number;
Total = Total + number;
if (counter > 5)
{
average = Total / 5;
cout << "Total : " << Total;
cout << "\nAverage : " << average;
cout << "\n";
counter ++;
}
else
{
counter ++;
}
}
return 0;
}
1.c.
#include <iostream>
using namespace std;
int main ()
{
int counter = 1, average = 0, Total = 0;
do
{
int number;
cout << "Input number : ";
cin >> number;
Total = Total + number;
if (counter > 5)
{
average = Total / 5;
cout << "Total : " << Total;
cout << "\nAverage : " << average;
cout << "\n";
counter ++;
}
else
{
counter ++;
}
}while(counter > 0);
return 0 ;
}
2. A class of ten students took a quiz. The mark is between the ranges 0 - 25 for this quiz
is available to you. Determine the average mark for this quiz. Based on this problem,
you are required to create a program.
#include <iostream>
using namespace std;
int main ()
{
float marks = 0, mark, average;
for(int i=10; i <= 10; i--)
{
//user input the marks
cout << "Input the mark : ";
cin >> mark;
marks = marks + mark;
if(mark <= 25 && mark >= 0)
{
if (i == 1)
{
average = marks / 10;
cout << "\nTotal Marks : " << marks;
cout << "\nAverage : " << average;
break;
}
}
else
{
cout << "\nError!";
break;
}
}
return 0;
}
3. Calculate the salary that employee get based on number of working. Rate of the
payment is RM8.00 per hour but the salary will be deducted with 10% KWSP. By using
a repetition control structure, write a program to calculate the total salary of 5
employees and the average salary of the employee.
#include <iostream>
using namespace std;
int main ()
{
double salary, hour, total_salary = 0, ave_salary;
if(i == 5)
{
cout << "\nTotal salary : " << total_salary;
ave_salary = total_salary / 5;
cout << "\nAverage salary of employee : " << ave_salary;
}
}
return 0;
}
4. Write a program asking the user for the upper and the lower bound and then
displaying all the numbers between them. It should work somehow like this:
Lower bound: 12
Upper bound: 23
12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
using namespace std;
int main ()
{
for(int i = 12; i >=12 && i <= 23; i++)
{
cout << i << " ";
}
return 0;
}
Activity 3B.2
Activity Outcome: Write a program using repetition control structures in solving the given
problems.
Duration : 180 minutes
Task 1:
PROBLEM
Case Senario:
Now Suria already to develop a system that will automate the process of calculating payroll for
employees worked at Infinity Design Solution Sdn. Bhd. Each employee will be recognized by
employee ID. The system will receive gross income, allowance, overtime, income tax and loan
deduction. The system will automatically calculate the total income, total deduction and net salary
for the employee. System will calculate the total income based total deduction. Now Head of HR
Department gives a new task to Suria. Help Suria to create t a payroll system will automatic
execute to calculate salary for 200 staff of Infinity Design Solution.
#include <iostream>
using namespace std;
int main ()
{
}
return 0;
}
Task 2:
PROBLEM
Case Senario:
Now Suria need to enhance a payroll system for Infinity Design Solution, which is the the payroll
system will calculate Average Salary of 10 employee. Help Suria.
#include <iostream>
using namespace std;
int main ()
{
float total_net_salary = 0, ave_net_salary;
if(i == 10)
{
cout << "\n[Average Area]";
ave_net_salary = total_net_salary / 10;
cout << "Average salary : " << ave_net_salary;
}
}
return 0;
}