Department of Information Technology & Communication: DFC 20013 - Programming Fundamentals
Department of Information Technology & Communication: DFC 20013 - Programming Fundamentals
LEARNING OUTCOMES :
for(d=1;d<6;d++)
{
cout<<"Number[ "<<d<<" ] = ";
cin>>num[d];
}
for(d=1;d<6;d++)
{
sum+=num[d];
}
system("pause");
}
1|Page
Output:
2|Page
QUESTION 2 (5 marks): Array 2 Dimension
Write a programme to display values in 2 dimensional arrays as in the given table below.
0 1 2
0 9 7 5
1 6 8 10
Display of Output:
#include<iostream>
using namespace std;
void main()
{
int values[2][3]={9,7,5,6,8,10};
cout<<"NUMBER OF FOOD EATEN ACCORDING THEIR GENDER\n";
cout<<"-----------------------------------------------\n\n\n";
cout<<"\t\t\tPizza\t\tKFC\t\tMcDonalds\n";
cout<<"Man\t\t\t"<<values[0][0]<<"\t\t"<<values[0][1]<<"\t\t"<<values[0]
[2]<<endl;
cout<<"Woman\t\t\t"<<values[1][0]<<"\t\t"<<values[1][1]<<"\t\t"<<values[1]
[2]<<endl;
system("pause");
}
Output:
3|Page
Write the programme based on the following situations. Every situation linked with another:
#include<iostream>
4|Page
#include<string>
using namespace std;
void main()
{
struct Student
{
char name[50];
char matrixnumber[12];
int age;
char course[7];
}
PersonA,PersonB;
strcpy(PersonA.name,"Arewardi A/P Arkom");
strcpy(PersonA.matrixnumber,"12DIP11F1001");
strcpy(PersonA.course,"DIP");
PersonA.age=18;
system ("pause");
}
5|Page
Build a programme to manage Emporium Hock Kee Seng sales data. All sales data must include
product code, product category, product name, quantity and price per unit. All the data must be insert
by the user. Lastly display all the data that inserted by the user.
This programme can manage 4 sales product. Used struct, array and looping to complete this
programme.
Example :
#include<iostream>
6|Page
using namespace std;
struct product
{
char name[40];
long int code;
char catgory[50];
double ppu;
int qtty,roll;
} s[4];
int main()
{
cout<<"############################################\n";
cout<<"# EMPORIUM HOCK KEE SENG SALES DATA #\n";
cout<<"############################################"<<endl<<endl;
for(int p=0;p<4;p++)
{
s[p].roll=p+1;
for(int p = 0; p<4;++p)
{
cout<<"Product Code : "<<s[p].code<<endl;
cout<<"Product Category : "<<s[p].catgory<<endl;
cout<<"Product Name : "<<s[p].name<<endl;
cout<<"Product Price Per Unit : "<<s[p].ppu<<endl;
cout<<"Product Quantity : "<<s[p].qtty<<endl<<endl;
}
system("pause");
return 0;
}
7|Page