Membuat Tampilan Data Array Seperti Tabel di C++






Download Script



#include <conio.h>
#include <iostream.h>
#include <stdio.h>

//membuat struct mahasiswa
struct mahasiswa{
char nim[9];
char nama[30];
char kelas[4];
float nilai;
};

mahasiswa mhs[100];
int jmlMhs=1;

//Menu Utama
void menuUtama(){
clrscr();
cout<<"------------------\n";
cout<<" MENU UTAMA \n";
cout<<"------------------\n\n";
cout<<" [1] Input Data Mahasiswa\n";
cout<<" [2] Tampilkan Data Mahasiswa\n";
cout<<" [3] Keluar\n\n";
cout<<"------------------\n";
cout<<"Pilihan : ";
}

//input data mahasiswa
void inputData(){
char pil;
clrscr();
cout<<"-------------------------------\n";
cout<<" Input Data Mahasiswa ke ["<<jmlMhs<<"] \n";
cout<<"-------------------------------\n\n";
cout<<" -> NIM : ";
gets(mhs[jmlMhs].nim);
cout<<" -> Nama : ";
gets(mhs[jmlMhs].nama);
cout<<" -> Kelas : ";
gets(mhs[jmlMhs].kelas);
cout<<" -> Nilai : ";
cin>>mhs[jmlMhs].nilai;
cout<<endl<<endl;
jmlMhs++;
cout<<"Input data lagi (Y/N)? :";
cin>>pil;
if (pil=='Y' || pil=='y')
inputData();
else
menuUtama();
}

void tampilData(){
clrscr();
cout<<"-------------------------------\n";
cout<<" Tampil Data Mahasiswa \n";
cout<<"-------------------------------\n\n";
cout<<"---------------------------------------------------------\n";
gotoxy(1,6);
cout<<"| NIM ";
gotoxy(15,6);
cout<<"| Nama ";
gotoxy(40,6);
cout<<"| Kelas ";
gotoxy(49,6);
cout<<"| Nilai ";
gotoxy(57,6);
cout<<"|";
cout<<endl;
cout<<"-----------------------------"
<<"----------------------------\n";
for (int i=1; i<jmlMhs; i++){
gotoxy(1,i+7);
cout<<"| "<<mhs[i].nim;
gotoxy(15,i+7);
cout<<"| "<<mhs[i].nama;
gotoxy(40,i+7);
cout<<"| "<<mhs[i].kelas;
gotoxy(49,i+7);
cout<<"| "<<mhs[i].nilai;
gotoxy(57,i+7);
cout<<"|";
cout<<endl;
}
cout<<"------------------------------"
<<"---------------------------\n\n";
cout<<"Tekan sembarang tombol untuk "
<<"kembali ke menu utama...";
getch();
}

void main(){
int pil;
do {
menuUtama();
cin>>pil;
switch (pil){
case 1 :
inputData();
break;
case 2 :
tampilData();
break;
case 3 :
break;
}
}while(pil!=3);
}

2 comments:

Unknown said...

gan ajari dong,,, itu program kalo di modif biar jadi 2 menu ...
menu ke(1) input nama sama nim...
menu ke(2) masukkin nilai tugas,mid,sama uas...
setiap input dimenu 2 itu harus muncul nama dan nim mhs yang di inputkan dan apabila nim sama nama belom diinput user ga bisa input nilai ... aku uda nyoba berhari2 ga bisa nihh,,, mohon pencerahannya... please please please

Unknown said...

Gan gotoxy gk bisa di pake di dev ++ yah ? :(