Professional Documents
Culture Documents
ID NUMBER: 01DDT20F1041
CLASS: DDT2B
LECTURER: PUAN.NOR ANISAH MOHD SAAD
LAB ACTIVITY 1: INTRODUCTION TO
FUNDAMENTALS OF PROGRAM
Duration: 2 Hours
SCENARIO:
You have impressed Miss Suria on your capability to solve the task handed to you in 4A and 4B in
DFC10042. Therefore, Infinity Design Solution Sdn. Bhd, with the supervision of Miss Suria has given
you the task to develop payroll system by using C++ program in Integrated Development
Environment (IDE) to increase employees salary by 13% from gross pay and 5% from allowance
received (Please refer Lab Activity 4B in DFC10042).
INSTRUCTION:
Your task is to convince Miss Suria that you are familiar with Integrated Development
Environment (IDE) by writing and compiling a program using C++ before you proceed to develop
payroll system.
Activity 1A
PROCEDURE OUTPUT
Program 1:
int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}
Step 2: Compile the program.
Step 3: Write the output.
Program 2:
#include<iostream.h> void
main()
{
int a,b, sum;
sum = a + b;
cout << sum << endl;
}
Step 2: Compile the program.
Step 3: Write the output.
Program 3:
#include <iostream>
using namespace std;
int main ()
{
// declaring variables:
int a, b;
int result;
// process:
a = 5;
b = 2;
a=a+
1;
result = a
- b;
return
0; }
Step 2: Compile the program.
Step 3: Write the output.
Program 4:
#include <iostream>
using namespace std;
int main ()
{
i
n
t
i
;
Task 2 : Please refer Activity 4B.1 until Activity 4B.4 in DFC 1043.Write and compile the program
using C++. Write the output.
Output
Activity 1C
Activity Outcome: Detect the errors in following programs. Write the correct answers, compile
and run a program using C++
Duration : 60 minutes
Task 3 : Miss Suria has provided you with extra tasks. Follow the procedure below step by step.
PROCEDURE OUTPUT
Program 1 :
#include “iostream”
int main
{
char name[50];
}
Step 2: Write the
correct answers
Step 3: Compile
and run the
program.
Step 4: Write the output.
Program 2 :
includ
e
<iostr
eam>
using
name
space
std;
int main ()
{
cout << Hello World!
cout >> "I'm a C++ program";
}
Step 2: Write the
correct answers
Step 3: Compile
and run the
program.
Step 4: Write the output.
Program 3 :
#include <iostream>
using namespace std;
main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl; cout <<
"Size of long int : " << sizeof(long int) << endl; cout << "Size of
float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl; cout << "Size
of wchar_t : " << sizeof(wchar_t) << endl;
}
Step 2: Write the correct answers
Step 3: Compile and run the program.
Step 4: Write the output.
Program 4 :
#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'
int main
{
int area
#include <iostream>
using namespace std;
main()
{
int
a
=
21
int
b
=
10
;
int
c;
if( a == b )
{
cout << "Line 1 - a is equal to b" << endl
}
else
{
cout << "Line 1 - a is not equal to b" << endl
}
if ( a < b )
{
cout << "Line 2 - a is less than b" << endl
}
else
{
cout << "Line 2 - a is not less than b" << endl
}
if ( a > b )
{
cout << "Line 3 - a is greater than b" << endl
}
else
{
cout << "Line 3 - a is not greater than b" << endl
}
#include <iostream>
using namespace std;
main()
{
2
1
;
1
0
;
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: Write the correct
answers Step 3: Compile
and run the program.
Step 4: Write the output.
THANK YOU