source : pxhere.com |
BORLAND C++ CONTOH PROGRAM MENU
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void main()
{
clrscr();
struct mk
{
char kodemk[10];
char namamk[100];
int sks;
};
mk matakuliah[20];
int banyakdata=0;
int pilihan=1;
while ((pilihan ==1) ||(pilihan ==2)||(pilihan ==3)||(pilihan ==4))
{
clrscr();
cout<<"Menu:"<<endl;
cout<<"1.Tambah data"<<endl;
cout<<"2.Edit data"<<endl;
cout<<"3.Cari data"<<endl;
cout<<"4.Tampilkan data"<<endl;
cout<<"5.Keluar"<<endl;
cout<<"Pilihan Anda:";
cin>>pilihan;
char x[20];
cin.getline(x,sizeof(x));
if(pilihan ==1)
{
clrscr();
cout<<"Jumlah data :"<<banyakdata<<endl;
if(banyakdata >=20)
{
cout<<"Data sudah penuh"<<endl;
}
else
{
cout<<"==========Tambah data Baru==========="<<endl;
cout<<"Kode MK:";
cin.getline(matakuliah[banyakdata].kodemk,sizeof(matakuliah[banyakdata].kodemk));
cout<<"Nama MK:";
cin.getline(matakuliah[banyakdata].namamk,sizeof(matakuliah[banyakdata].namamk));
cout<<"SKS:";
cin>>matakuliah[banyakdata].sks;
banyakdata++;
cout<<"Data telah disimpan"<<endl;
}
cout<<"Tekan enter untuk melanjutkan .."<<endl;
getch();
}
else if(pilihan ==2)
{
clrscr();
cout<<"============Edit data terakhir==========="<<endl;
cout<<matakuliah[banyakdata-1].kodemk<<","<<matakuliah[banyakdata-1].namamk<<","<<matakuliah[banyakdata-1].sks<<endl;
cout<<"Kode MK:";
cin.getline(matakuliah[banyakdata-1].kodemk,sizeof(matakuliah[banyakdata-1].kodemk));
cout<<"SKS:";
cin>>matakuliah[banyakdata-1].sks;
cout<<"Data telah disimpan"<<endl;
cout<<"tekan enter untuk melanjutkan.."<<endl;
getch();
}
else if(pilihan ==3)
{
clrscr();
char kode[10];
int ketemu=0;
int indek;
cout<<"=============Cari Data==============="<<endl;
cout<<"masukkan Kode MK:";
cin.getline(kode, sizeof(kode));
for(int i=0;i<banyakdata;i++)
{
if(stricmp(kode, matakuliah[i].kodemk) ==0)
{
ketemu=1;
indek=i;
}
}
if(ketemu ==0)
{
cout<<"data tidak ditemukan"<<endl;
}
else
{
cout<<"Data ditemukan"<<endl;
cout<<"Kode MK:"<<matakuliah[indek].kodemk<<endl;
cout<<"namaMK:"<<matakuliah[indek].namamk<<endl;
cout<<"SKS:"<<matakuliah[indek].sks<<endl;
}
cout<<"Tekan enter untuk melanjutkan..";
getch();
}
else if(pilihan ==4)
{
clrscr;
cout<<"==========Tampilkan seluruh data========="<<endl<<endl;
if(banyakdata >0)
{
cout<<"============================================"<<endl;
cout<<setiosflags(ios::left)<<setw(15)<<"Kode MK"<<setw(15)<<"Nama MK"<<setw(15)<<"Sks"<<endl;
cout<<"============================================"<<endl;
for(int i=0; i<banyakdata;i++)
{
cout<<setiosflags(ios::left)<<setw(15)<<matakuliah[i].kodemk<<setw(15)<<matakuliah[i].namamk<<setw(15)<<matakuliah[i].sks<<endl;
}
cout<<"=========================================="<<endl;
}
else
{
cout<<"data masih kosong"<<endl;
}
cout<<endl<<"Tekan enter untuk melanjutkan..";
getch();
}
}
}
Minta LIKE nya doongg :) !!!
BalasHapusTerimakasih.. tulisannya sangat bermanfaat..
BalasHapusMy blog
My Campus