Struct c++

Example for my mini project:

#include<iostream.h> #include<stdio.h> #include<conio.h> #include<string.h> main() { struct mhs { long int nrp; int nilaiok; char nama[30]; }; struct mata { int kode; char nama_mata[30]; }; struct nilai{ struct mhs mahasiswa; struct mata matakuliah; int nilai, nilaiok[5][5]; }; struct mhs data_mhs[5]; struct mata data_mata[5]; struct nilai data_nilai[5]; int a, b, c, d, x, y, z, dll; long int nrpok; cout << "Input Data Mahasiswa\n"; cout << "Jumlah Siswa yang Ingin Diinput : "; cin >> c; for(a=0;a<c;a++) { cout << "No "<<a+1<<endl; cout << "NRP\t: "; cin >> data_mhs[a].nrp; cout << "Nama\t: "; gets(data_mhs[a].nama); cout << endl; } clrscr; cout << "Input Mata Kuliah\n"; cout << "Jumlah Mata Kuliah yang Ingin Diinput : "; cin >> d; for(b=0;b<d;b++) { cout << "Kode\t\t\t: "; cin >> data_mata[b].kode; cout << "Nama Mata Kuliah\t: "; gets(data_mata[b].nama_mata); } clrscr(); for(a=0;a<c;a++) { cout << "No "<<a+1<<endl; cout << "Nama\t\t\t: " <<data_mhs[a].nama <<endl; cout << "NRP\t\t\t: " <<data_mhs[a].nrp <<endl; for(b=0;b<d;b++) { cout << "Kode\t\t\t: "; cout << data_mata[b].kode << endl; cout << "Nama Mata Kuliah\t: "; cout << data_mata[b].nama_mata << endl; cout << "Nilai\t\t\t: "; cin >> data_nilai[b].nilai; cout << endl; data_nilai[b].nilaiok[a][b]=data_nilai[b].nilai; strcpy (data_nilai[b].mahasiswa.nama, data_mhs[a].nama); data_nilai[b].matakuliah.kode=data_mata[b].kode; strcpy (data_nilai[b].matakuliah.nama_mata, data_mata[b].nama_mata); } } clrscr(); masukan: cout << "Lihat Nilai"<<endl; cout << "Masukan NRP : "; cin >> nrpok; for(a=0;a<c;a++) { data_mhs[a].nrp; if(nrpok==data_mhs[a].nrp) { clrscr(); goto hasil; } } clrscr(); goto masukan; hasil: x=0; z=3; y=4; cout << "NRP : " << data_mhs[a].nrp << endl; cout << "Nama : " << data_mhs[a].nama << endl; gotoxy(1,z); cout << "KODE"; gotoxy(10,z); cout << "MATAKULIAH"; gotoxy(25,z); cout << "NILAI"; for(b=0;b<d;b++) { gotoxy(1,y); cout << data_nilai[b].matakuliah.kode; gotoxy(10,y); cout << data_nilai[b].matakuliah.nama_mata; gotoxy(25,y); cout << data_nilai[b].nilaiok[a][b]; y++; } cout << endl; cout << "Tekan [1] untuk melihat nilai siswa yang lain : "; cin>>dll; if(dll=1) { clrscr(); goto masukan; }else{ clrscr(); cout<<"selesai"; } }

One thought on “Struct c++

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s