Вы находитесь на странице: 1из 14

# DEPARTMENT OF INFORMATION TECHNOLOGY & COMMUNICATIONS

LAB EXERCISE 1
DFC 2013 : PROGRAMMING
FUNDAMENTALS

## NAME : MIGARSINI THENNARASU

REGISTRATION : 21DIP15F1134
CLASS : DIP2C
LECTURER : PUAN NORZIMAH CHE HASSAN

## PROGRAM 2A : DEFINE VARIABLE (FLOAT) AND SIMPLE

MATH OPERATION

1./2./4.
//Calculate the average of 3 input value
using namespace std;
void main()//main function : where the execution begins
{

float g1,g2,g3,g4,g5,avg;
cout<<"Please key in the first student score : \n";//output
cin>>g1;//input
cout<<"Please key in the second student score : \n";//output
cin>>g2;//input
cout<<"Please key in the third student score : \n";//output
cin>>g3;//input
cout<<"Please key in the fourth student score : \n";//output
cin>>g4;//input
cout<<"Please key in the fifth student score : \n";//output
cin>>g5;//input
avg=(g1+g2+g3+g4+g5)/5.0;//process for this calculation
cout<<"The average score for the students is "<<avg<<"\a"<<"\n";//output
system("pause");

Namapenuh,
namasamaran

## 3. \n = This means insert a newline in the text at this point.

\a = This means match only at beginning of string.

5.a)

IPO Table

Input

g1,g2,g3,g4,g5

Process

## Calculate average = (g1+g2+g3+g4+g5) / 5.0

Output

Average Score

5.b)
Flow Chart

Start

g1,g2,g3,g4,g5

Calculate average =
(g1+g2+g3+g4+g5)/5.0

Average Score

End

## PROGRAM 2B : DEFINE VARIABLE (CHARACTER &

STRING) & USING INPUT OUTPUT STATEMENT
1./2.

//This program is used to display your family name and your full name.
void main()//main function : where the excution program begins
{
char NamaSamaran [36];//declaring data type char with identifier
char NamaPenuh [20];//declaring data type char with identifier
cin>>NamaPenuh;//first input
cout<<"\n Your full name is "<<NamaPenuh<<"\n";//second output with
the user first output
cin>>NamaSamaran;//second input
cout<<"\n Your nick name is "<<NamaSamaran<<"\n";//fourth output
with the user second output
system("pause");
}

3.a)

IPO Table
Input

Namasamaran,
Namapenuh

Process

Output

3.b)

Namapenuh ,
Namasamaran

Flow Chart

Start

Namasamaran,
namapenuh

name,

Namapenuh,
namasamaran

End
4. When user type his/her name as Abu Bakar the output will
directly show the
nick name.

## PROGRAM 2C : USING GETS COMMAND

5.
//This program is used to display your family name and your full name.

void main()//main function : where the excution program begins
{
char NamaSamaran [36];//declaring data type char with identifier
char NamaPenuh [20];//declaring data type char with identifier
gets(NamaPenuh);//first input
cout<<"\n Your full name is "<<NamaPenuh<<"\n";//second output with
the user first output
gets(NamaSamaran);//second input
cout<<"\n Your nick name is "<<NamaSamaran<<"\n";//fourth output
with the user second output
system("pause");
}

file needed :
<iostream> using
namespace std;
Only one character is

## Use to read string, it

space( space , form
feed .) and will stop
until reach ENTER,
then will convert
ENTER to null
terminator (\0) and
save.
(produce by Enter)
and convert to null
terminator and save.

## PROGRAM 2D : PROBLEM WITH CIN WHEN IT IS USE

BEFORE GETS.

7. When cin is use to read nick name before gets read full name it will doesnt
show Nick Name.
8.
void main()//main function : where the excution program begins
{
char Umur[10];//declaring data type char with identifier
char NamaPenuh[20];//declaring data type char with identifier

gets(Umur);//first input
cout<<"\n Your age is "<<Umur<<"\n";//second output with the user first
input
cin>>NamaPenuh;//second input
cout<<"\n Your full name is "<<NamaPenuh<<"\n";//fourth output with
the user second input
system("pause");
}

PROGRAM 2E :

## //This program is used to calculate employee's monthly payment.

void main()//where the excution begins
{

## const float rate=25;

int day;
char Name[20];
float salary;

cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";//ouput

## cout<<"\nSalary System for\nSyarikat Abu Bakar Sdn Bhd";//output

cout<<"\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n";//outp
ut
cout<<"Rate of payment is fixed at \$"<<rate<<" per day\n\n";//output
cin>>Name;//input
cout<<"\n\nEnter number of days worked : ";//output
cin>>day;//input
cout<<"\n\nWelcome ! "<<Name;//output for insert name
salary=day*rate;
cout<<"\n\nFor "<<day<<" days of work, you have earned RM"<<salary;//output
cout<<"\n\n\n";//output
system("pause");
}

IPO TABLE
INPUT
PROCESS
OUTPUT

## Employees monthly payment

Calculate employees monthly payment
Display employees monthly payment

FLOW CHART
Start

## Employees monthly payment

Calculate employees
monthly payment

payment

End