0% found this document useful (0 votes)
26 views

#Include #Include : //create Structure

The code defines structs to store information about lecturers and students, including name, age, field of study, and GPA. It then declares arrays of each struct type and uses for loops to input data for 5 lecturers and 5 students, storing it in the arrays. Finally, it prints out the stored information about each lecturer and student.

Uploaded by

emma@rinako
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)
26 views

#Include #Include : //create Structure

The code defines structs to store information about lecturers and students, including name, age, field of study, and GPA. It then declares arrays of each struct type and uses for loops to input data for 5 lecturers and 5 students, storing it in the arrays. Finally, it prints out the stored information about each lecturer and student.

Uploaded by

emma@rinako
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/ 3

Coding :

#include <iostream.h>
#include <string.h>
//create structure
struct info {
string nama;
int umur;
};
struct pensyarah {
string bidang;
};
struct pelajar {
string program;
float pngk;
};
struct universiti{
info x;
pensyarah Pen;
pelajar Pel;
};
int main(){
//declare variable berjenis struct
universiti uPen[5], uPel[5];
int x;
//masukkan maklumat pensyarah
for(x=0;x<5;x++){
cout<<"sila masukkan nama:";
cin>>uPen[x].x.nama;
cout<<"sila masukkan umur:";
cin>>uPen[x].x.umur;
cout<<"sila masukkan bidang:";
cin>>uPen[x].Pen.bidang;
}
//masukkan maklumat pelajar
for(x=0;x<5;x++){

cout<<"sila masukkan nama:";


cin>>uPel[x].x.nama;
cout<<"sila masukkan umur:";
cin>>uPel[x].x.umur;
cout<<"sila masukkan program:";
cin>>uPel[x].Pel.program;
cout<<"sila masukkan pngk:";
cin>>uPel[x].Pel.pngk;
}
//paparkan maklumat pensyarah dan pelajar
cout<<"maklumat pensyarah\n";
for(x=0;x<5;x++){
cout<<uPen[x].x.nama;
cout<<uPen[x].x.umur;
cout<<uPen[x].Pen.bidang;
}
cout<<"maklumat pelajar\n";
for(x=0;x<5;x++){
cout<<uPel[x].x.nama;
cout<<uPel[x].x.umur;
cout<<uPel[x].Pel.program;
cout<<uPel[x].Pel.pngk;
}
return 0;
}

You might also like