0% found this document useful (0 votes)
138 views6 pages

Labsheet / Assingment / Case Study / PBT: Jabatan Teknologi Maklumat Dan Komunikasi

This document contains a lab assignment for a Programming Fundamentals course. It includes 3 questions that require writing C++ code to: 1) Input and display 2D array values in a table. 2) Perform addition of two numbers using pointers. 3) Declare a structure to store student data for two people, assign data, and display the information.

Uploaded by

probably 09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views6 pages

Labsheet / Assingment / Case Study / PBT: Jabatan Teknologi Maklumat Dan Komunikasi

This document contains a lab assignment for a Programming Fundamentals course. It includes 3 questions that require writing C++ code to: 1) Input and display 2D array values in a table. 2) Perform addition of two numbers using pointers. 3) Declare a structure to store student data for two people, assign data, and display the information.

Uploaded by

probably 09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

JABATAN TEKNOLOGI MAKLUMAT DAN KOMUNIKASI

LABSHEET / ASSINGMENT / CASE STUDY / PBT

COURSE : (DFC 2073) – PROGRAMMING FUNDAMENTALS


TITLE : LAB TASK 3
CLASS : DNS1A
DUE DATE : 24 / 9 / 2017

PREPARED BY:

N NAME MATRIC NO
O
1 NIK AFIQ AIMAN BIN NIK MAHMAD KAMAL 12DNS17F1024

2 AHMAD FIRDAUS BIN NGAH 12DNS17F1012

PREPARED FOR:

LECTURER NAME : PN ROSMAYATI ISMAIL


MARKS
QUESTION 1
Write a program to input and display values in 2 dimensional arrays as in the given table
below.

int matrix[2][3], i,j;


{
cout<<"\tWelcome GUEST"<<endl;

for(int i=0; i<2; i++)


{
cout<<"\nBaris "<<i+1<<endl;
cout<<"--------------"<<endl;

for(int j=0; j<3; j++)


{
cout<<"Nilai "<<i<<"."<<j<<" : ";
cin>>matrix[i][j];
cout<<endl;
}
}

cout<<"\nDomino \tKFC \tMcDonald "<<endl;

for(int i=0; i<2; i++)


{
for(int j=0; j<3; j++)
{
cout<<matrix[i][j]<<"\t";
}
cout<<endl;
}
system("pause");
}
}
Question 2 (CLO2, C3)

Write a program to perform addition of two numbers using pointer. Your program must have this
following :

a. Two integer variables x, y and two pointer variables p and q.


b. Assign the addresses of x and y to p and q respectively
c. Assign the sum of x and y to variable sum
d. Print the sum of two numbers that entered by the user.

#include <iostream>
using namespace std;

void main()
{
int x, y, sum=0;
int *p, *q;

p = &x;
q = &y;

cout << "Enter Two Integers to Add = "<<endl;


cin >> x >> y ;

sum = x + y ;

cout << "Sum of entered number = "<<sum<<endl;


cout << endl;

system("pause");
}
Question 3 (CLO3, C3)

Write the programme based on the following situations. Every situation linked with another :

a. Declare a structure named “Student”

b. Declare the following structure members:

i. Name

ii. Matrix number

iii. Age

iv. Courses

c. Declare the following structure members:


i. Person A

ii. Person B

d. Assign following data to Person A structure members:

i. Azhan Ariff

ii. 12DNS17F2001

iii. 18

iv. DNS

e. Ask user to key in all data to Person B structure members.

f. Display all the Person A and Person B data.


ANSWER

#include <iostream>
using namespace std;
struct Student
{
char name[20];
char matrix_num[20];
int age;
char courses[10];
};

Student person_A = {"Azhan Ariff", "12DNS17F2001" , 18 , "DNS" };


Student person_B;

void main()
{
cout<< "Person B" <<endl;
cout<< "Enter name : "<<endl;
cin>>person_B.name;
cout<< "Enter matrix number : "<<endl;
cin>>person_B.matrix_num;
cout<< "Enter age : "<<endl;
cin>>person_B.age;
cout<< "Enter courses : "<<endl;
cin>>person_B.courses;
cout<<endl;

cout<< "Person A" <<endl;


cout<<"\nName : " <<person_A.name << endl;
cout<<"Matrix Number : " <<person_A.matrix_num <<endl;
cout<<"Age : " <<person_A.age <<endl;
cout<<"Courses : "<<person_A.courses << endl;
cout<<endl;

cout<< "Person B" <<endl;


cout<<"\nName : " <<person_B.name << endl;
cout<<"Matrix Number : " <<person_B.matrix_num <<endl;
cout<<"Age : " <<person_B.age <<endl;
cout<<"Courses : "<<person_B.courses << endl;
cout<<endl;
cout<<endl;

system("pause");
}

You might also like