Professional Documents
Culture Documents
Duration: 2 Hours
Learning Outcomes
• Declare variables
• Use input output statements
• Apply operators and expression
SCENARIO:
Congratulations to you!!
You have impressed Miss Suria on your capability to solve the task handed to you in Activity
1. Therefore, Infinity Design Solution Sdn. Bhd, with the supervision of Miss Suria has given
you the task to help Finance Unit in completing payroll system. The scenario is that; In January
of each year, Infinity Design Solution Sdn. Bhd pays a 5% bonus to each of its salespeople.
The bonus is based on the amount of sales made by the sales person during the previous
year.
INSTRUCTION:
Before you continue to write codes in C++, Miss Suria gives you some exercises. Complete
the exercises below and follow the process in completing your codes.
Activity 2A
Activity Outcome: Declare variables
Duration : 90 minutes
a)
Type Description
bool Stores either value true or false
char Typically a single octet(one byte). This is an integer type.
int The most natural size of integer for the machine
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
wchar_t A wide character type
b)
PROCEDURE OUTPUT
Program 1: 30
23.3333
Step 1: Type the programs given
below
#include <iostream>
using namespace std;
// Variable declaration:
int a,
b; int
c; float
f;
int main ()
{
// Variable definition:
int a,
b; int c;
float f;
// actual initialization
a = 10;
b = 20;
c = a + b;
f = 70.0/3.0; cout
<< f << endl ;
return 0;
}
Step 2: Compile the program.
Step 3: Write the output.
Activity 2C
Task 3 : Identify and match the types of operator with their example correctly.
Types of Examples
operator
Arithmetic
B = (A + C) * A
Operators
Relational
A++ will give 11
Operators
Logical Operators C *= A is
equivalent to C =
C*A
Increment
(A && B) is false.
Operators
Assignment (A == B) is not
Operators true.
Activity 2D
:
PROCEDURE OUTPUT
Program 1:
c = a + b;
cout << "Line 1 - Value of c is :" << c << endl ;
c = a - b;
cout << "Line 2 - Value of c is :" << c << endl ;
c = a * b;
cout << "Line 3 - Value of c is :" << c << endl ;
c = a / b;
cout << "Line 4 - Value of c is :" << c << endl ;
c = a % b;
cout << "Line 5 - Value of c is :" << c << endl ;
c = a++;
cout << "Line 6 - Value of c is :" << c << endl ;
c = a--;
cout << "Line 7 - Value of c is :" << c << endl ;
return 0; }
Step 2: Compile the program.
Step 3: Write the output.
Activity 2E
main()
{
int a = 5;
int b = 20;
int c ;
if ( a && b )
{
cout << "Line 1 - Condition is true"<< endl ;
}
if ( a || b )
{
cout << "Line 2 - Condition is true"<< endl ;
}
/* Let's change the values of a and b */
a = 0; b = 10;
if ( a && b )
{
cout << "Line 3 - Condition is true"<< endl ;
}
else
{
cout << "Line 4 - Condition is not true"<< endl
;
}
if ( !(a && b) )
{
cout << "Line 5 - Condition is true"<< endl ;
}
return 0; }
Step 2: Compile the program.
Step 3: Write the output.
Activity 2E.1
Activity Outcome Identify input, process and output
Duration : 20 minutes
Miss Suria has given you the task to help Finance Unit in completing payroll system. Rewrite
the steps to produce a complete output as in 2E.4 following the below procedure.
Task 1: You must identify the input, process and output from the given task in Case Study.
Activity 2E.2
Activity Outcome: Constructing Flowchart
Duration : 20 minutes
Flowchart
Start
Display employee_name,
employee_id, gross_income,
allowance, overtime, income_tax,
loan, amount_sale
End
:
Activity 2E.3
Activity Outcome Constructing Pseudocode
Duration : 20 minutes
Pseudocode
Start
Input employee_name, employee_id, gross_income, allowance, overtime, income_tax, loan,
amount_sale
Display employee_name, employee_id, gross_income, allowance, overtime, income_tax, loan,
amount_sale
End
:
Activity 2E.4
Activity Outcome: Understand Input Output Statement in C++ . Duration
: 30 minutes
Output
:
CODE
#include <iostream>
int main()
string employee_name;
int employee_id;
cout<<"***********************************************************\n\n";
cout<<"***********************************************************"<<endl;
cin>>employee_name;
cin>>employee_id;
cin>>gross_income;
cin>>allowance;
cin>>overtime;
cin>>income_tax;
cin>>loan;
cin>>amount_sale;
cout<<"***********************************************************"<<endl;
cout<<"Name: "<<employee_name<<endl;
cout<<"Allowance: "<<allowance<<endl;
cout<<"Overtime: "<<overtime<<endl;
cout<<"Loan: "<<loan<<endl;
cout<<"***********************************************************"<<endl;
return 0;
}
:
Activity 2E.5
Activity Outcome Write a program code and implement arithmetic operator Duration
: 30 minutes
Task 1: Write a complete code from the given task in Case Study. Then, compile the program
using C++ and write the output
The scenario is that; In January of each year, Infinity Design Solution Sdn. Bhd pays a 5%
bonus to each of its sales people. The bonus is based on the amount of sales made by the
sales person during the previous year. Display the pay roll and calculate the total salary for a
single worker.
#include <iostream>
using namespace std;
main()
{
#define bonus=0.05
float total_salary, salary;
int num_sales;
total_salary=salary+(num_sales*0.05);