#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#include<string.h>
struct budidarma {
char kode[5];
char nama[40], pend[15], ahli[30];
char npm[8], jenjang[2], tahun[4];
char jurusan[20];
}rbudidarma[10];
void menu();
void data_dosen();
void data_mhsw();
void output_ddosen();
void output_dmhsw();
void keluar();
void main (){
char pil='0';
while(pil !='6') {
menu();
pil=getch();
switch(pil){
case'1': data_dosen(); break;
case'2': data_mhsw(); break;
case'3': output_ddosen(); break;
case'4': output_dmhsw(); break;
case'5': keluar(); break;
}
}
}
void menu()
{
clrscr();
gotoxy(25,5); cout<<" MENU UTAMA ";
gotoxy(25,6); cout<<" ---------------------- ";
gotoxy(25,7); cout<<" [1] Input Data Dosen";
gotoxy(25,8); cout<<" [2] Input Data Mahasiswa";
gotoxy(25,9); cout<<" [3] Output Data Dosen";
gotoxy(25,10); cout<<" [4] Output Data Mahasiswa";
gotoxy(25,11); cout<<" [5] Keluar Program";
gotoxy(25,12); cout<<" _______________________________";
gotoxy(25,13); cout<<" PILIHAN : ";
}
void data_dosen(){
FILE *coba;
float atof();
int i, n=0;
while(1)
{
clrscr();
gotoxy(35,5); cout<<" INFORMASI DATA DOSEN" ;
gotoxy(35,6); cout<<" _____________________________ " ;
gotoxy(35,7); cout<<"KODE DOSEN[A, B, C] :";
gets(rbudidarma[n].kode);
gotoxy(35,8); cout<<"NAMA DOSEN :";
cin>>rbudidarma[n].nama;
gotoxy(35,9); cout<<"Pendidikan [S1, S2, Master] :";
gets(rbudidarma[n].pend);
gotoxy(35,10); cout<<"Keahlian:";
cin>>rbudidarma[n].ahli;
gotoxy(35,12); cout<<" .............................. " ;
++i;
}
gotoxy(35,6); cout<<" .............................. " ;
++i;
}
coba=fopen("c:\\budidarma.Dat","wb");
for (i=0; i<n; ++i)
{
fwrite(&rbudidarma[i], sizeof(rbudidarma[i]),1,coba);
fclose(coba);
}
void data_mhsw(){
FILE *coba;
float atof();
int i, n=0;
while(1)
{
clrscr();
gotoxy(35,5); cout<<" INFORMASI DATA MAHASISWA" ;
gotoxy(35,6); cout<<" _____________________________ " ;
gotoxy(35,7); cout<<"NPM : ";
cin>>rbudidarma[n].npm;
gotoxy(35,8); cout<<"NAMA :";
cin>>rbudidarma[n].nama;
gotoxy(35,9); cout<<"Jenjang [D3MI, D3KA, S1TI] :";
gets(rbudidarma[n].jenjang);
gotoxy(35,10); cout<<"Jurusan [Teknik Informatika, Manajemen Informatika] :";
gets(rbudidarma[n].jurusan);
gotoxy(35,11); cout<<"Tahun :";
cin>>rbudidarma[n].tahun;
coba=fopen("c:\\budidarma.Dat","wb");
for (i=0; i<n; ++i)
{
fwrite(&rbudidarma[i], sizeof(rbudidarma[i]),1,coba);
}
fclose(coba);
}
void output_ddosen(){
FILE *coba;
float atof();
clrscr();
coba = fopen("c:\\budidarma.Dat","rb");
if (coba==NULL)
{
gotoxy(20,10); cout<<" File Data.Dat belum ada ";
gotoxy(20,12); cout<<" Tekan Sembarang Tombol ";
getch();
return;
}
gotoxy(5,1); cout<<" Informasi Data Dosen ";
gotoxy(5,2); cout<<" ---------------------------------------------------------------------- ";
gotoxy(5,3); cout<<"No Kode Nama Pendidikan Keahlian";
gotoxy(5,4); cout<<" ---------------------------------------------------------------------- ";
while( (fread(&rbudidarma[n], sizeof(rbudidarma[n]),1,coba))==1)
{
++i;
gotoxy (6,4+i); cout<< i;
gotoxy (10,4+i); cout<<kode;
gotoxy (16,4+i);cout<<nama;
gotoxy (33,4+i);cout<<pend;
gotoxy (43,4+i);cout<<ahli;
}
gotoxy (5,5+i); cout<< "________________________________________" ;
getch();
fclose(coba);
}
void output_dmhsw(){
FILE *coba;
float atof();
clrscr();
coba = fopen("c:\\budidarma.Dat","rb");
if (coba==NULL)
{
gotoxy(20,10); cout<<" File BUDIDARMA.Dat belum ada ";
gotoxy(20,12); cout<<" Tekan Sembarang Tombol ";
getch();
return;
}
gotoxy(5,1); cout<<" Informasi Data Mahasiswa ";
gotoxy(5,2); cout<<" ---------------------------------------------------------------------- ";
gotoxy(5,3); cout<<"No NPM NAMA JENJANG JURUSAN";
gotoxy(5,4); cout<<" ---------------------------------------------------------------------- ";
while( (fread(&rbudidarma[n], sizeof(rbudidarma[n]),1,coba))==1);
{
++i;
gotoxy (6,4+i); cout<< i;
gotoxy (10,4+i); cout<<npm;
gotoxy(16,4+i);cout<<nama;
gotoxy(33,4+i);cout<<jenjang;
gotoxy(43,4+i);cout<<jurusan;
}
gotoxy (5,5+i); cout<< "________________________________________" ;
getch();
fclose(coba);
}
}
NAMA : E S T E R
NPM : 1002247
Kelas : MI.P-1003
Minggu, 03 Juli 2011
Jawaban Quiz Pemograman Terstruktur No.3
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct pegawai
{
char nik[9];
char nama[10];
char kode[15];
char stat;
long tnj_klrga;
}peg[20];
void main()
{
char lg='y';
int hasil,i,n=0;
char stat;
long gaji=0;
long tunjangan=0;
long tnj_klrga=0;
long total_gaji;
while(lg=='y'||lg=='y')
{
clrscr();
cout<<"Input Data Karyawan\n";
cout<<".....................\n";
n++;
cout<<"NIK ";
gets(peg[n].nik);
cout<<"Nama :";
gets(peg[n].nama);
cout<<"Bagian[Persediaan, Administrasi, Keuangan, Penjualan] :";
gets(peg[n].kode);
cout<<" Status Karyawan (M=Menikah & B=Belum) : " ;
stat=getche();
if (stat=='M'||stat=='m')
cout<<"\n Tunjangan Keluarga";
tnj_klrga=0.15*gaji;
cout<<"\n __________________________\n";
cout<<"input Lagi[Y/T]:";
lg=getch();
}
clrscr();
gotoxy(5,3);cout<<"LAPORAN GAJI KARYAWAN\n";
gotoxy(5,4);cout<<".....................";
gotoxy(5,5);cout<<"No NIK Nama Bagian Gaji Tunjangan Tunj Klrga Total Gaji";
gotoxy(5,6);cout<<"_________________________________________________________________";
for(i=1;i<=n;i++)
{
gotoxy(6,6+i);cout<<i;
gotoxy(9,6+i);cout<<peg[i].nik;
gotoxy(15,6+i);cout<<peg[i].nama;
gotoxy(23,6+i);cout<<peg[i].kode;
gotoxy(43,6+i);cout<<peg[i].stat;
hasil=strcmp(peg[i].kode,"Persediaan");
if (hasil==0)
gaji=2500000;
tunjangan=0.35*gaji;
hasil=strcmp(peg[i].kode,"Administrasi");
if (hasil==0)
gaji=2000000;
tunjangan=0.10*gaji;
hasil=strcmp(peg[i].kode,"Keuangan");
if (hasil==0)
gaji=1500000;
tunjangan=0.5*gaji;
hasil=strcmp(peg[i].kode,"Penjualan");
if (hasil==0)
gaji=1000000;
tunjangan=0.025*gaji;
if (stat=='M'||stat=='m')
cout<<"\n Tunjangan Keluarga";
tnj_klrga=0.15*gaji;
gotoxy(33,6+i);cout<<gaji;
gotoxy(46,6+i);cout<<tunjangan;
gotoxy(57,6+i);cout<<tnj_klrga;
total_gaji = gaji+tunjangan+tnj_klrga;
gotoxy(65,6+i); cout<<total_gaji;
}
gotoxy(5,6+i);cout<<"................................................................";
getch();
}
Hasilnya akan seperti ini :
Nama : E S T E R
NPM : 1002247
Kelas : MI.P-1003
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct pegawai
{
char nik[9];
char nama[10];
char kode[15];
char stat;
long tnj_klrga;
}peg[20];
void main()
{
char lg='y';
int hasil,i,n=0;
char stat;
long gaji=0;
long tunjangan=0;
long tnj_klrga=0;
long total_gaji;
while(lg=='y'||lg=='y')
{
clrscr();
cout<<"Input Data Karyawan\n";
cout<<".....................\n";
n++;
cout<<"NIK ";
gets(peg[n].nik);
cout<<"Nama :";
gets(peg[n].nama);
cout<<"Bagian[Persediaan, Administrasi, Keuangan, Penjualan] :";
gets(peg[n].kode);
cout<<" Status Karyawan (M=Menikah & B=Belum) : " ;
stat=getche();
if (stat=='M'||stat=='m')
cout<<"\n Tunjangan Keluarga";
tnj_klrga=0.15*gaji;
cout<<"\n __________________________\n";
cout<<"input Lagi[Y/T]:";
lg=getch();
}
clrscr();
gotoxy(5,3);cout<<"LAPORAN GAJI KARYAWAN\n";
gotoxy(5,4);cout<<".....................";
gotoxy(5,5);cout<<"No NIK Nama Bagian Gaji Tunjangan Tunj Klrga Total Gaji";
gotoxy(5,6);cout<<"_________________________________________________________________";
for(i=1;i<=n;i++)
{
gotoxy(6,6+i);cout<<i;
gotoxy(9,6+i);cout<<peg[i].nik;
gotoxy(15,6+i);cout<<peg[i].nama;
gotoxy(23,6+i);cout<<peg[i].kode;
gotoxy(43,6+i);cout<<peg[i].stat;
hasil=strcmp(peg[i].kode,"Persediaan");
if (hasil==0)
gaji=2500000;
tunjangan=0.35*gaji;
hasil=strcmp(peg[i].kode,"Administrasi");
if (hasil==0)
gaji=2000000;
tunjangan=0.10*gaji;
hasil=strcmp(peg[i].kode,"Keuangan");
if (hasil==0)
gaji=1500000;
tunjangan=0.5*gaji;
hasil=strcmp(peg[i].kode,"Penjualan");
if (hasil==0)
gaji=1000000;
tunjangan=0.025*gaji;
if (stat=='M'||stat=='m')
cout<<"\n Tunjangan Keluarga";
tnj_klrga=0.15*gaji;
gotoxy(33,6+i);cout<<gaji;
gotoxy(46,6+i);cout<<tunjangan;
gotoxy(57,6+i);cout<<tnj_klrga;
total_gaji = gaji+tunjangan+tnj_klrga;
gotoxy(65,6+i); cout<<total_gaji;
}
gotoxy(5,6+i);cout<<"................................................................";
getch();
}
Hasilnya akan seperti ini :
Nama : E S T E R
NPM : 1002247
Kelas : MI.P-1003
Sabtu, 02 Juli 2011
Belajar C++, Penjualan Barang Elektroniok
Ini adalah contoh Program C++ :
#include<iostream.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<iomanip.h>
void main()
{
char kd;
char nm[30];
char *nama;
int dis;
char *jenis;
int jumlah,jn;
float harga=0;
long Total;
long Tot;
char lagi='Y';
clrscr();
while(lagi=='Y' ||lagi=='y')
{
gotoxy(10,5);
cout<<"Penjualan Barang Elektronik\n";
gotoxy(10,6);
cout<<"===========================\n";
gotoxy(10,7);
cout<<"Nama Pembeli = ";cin>> nm;
gotoxy(10,8);
cout<<"Kode Barang[A/B/C] = ";cin>> kd;
gotoxy(10,9);
cout<<"Jenis Bayar[1.Tunai/2.Kredit] = ";cin>>jn;
gotoxy(10,10);
cout<<"============================\n";
if ((kd=='A' || kd=='a') && (jn==1))
{
nama="Televisi";
jenis="Tunai";
harga=500000;
dis=0.05*500000;
}
else if ((kd=='A' || kd=='a') && (jn==2))
{
nama="Televisi";
jenis="Kredit";
harga=650000;
dis=0;
}
else if ((kd=='B' || kd=='b') && (jn==1))
{
nama="Kipas Angin";
jenis="Tunai";
harga=150000;
dis=0.07*150000;
}
else if ((kd=='B' || kd=='b') && (jn==2))
{
nama="Kipas Angin";
jenis="Kredit";
harga=250000;
dis=0;
}
else if ((kd=='C' || kd=='c') && (jn==1))
{
nama="VCD";
jenis="Tunai";
harga=300000;
dis=0.01*300000;
}
else if ((kd=='C' || kd=='a') && (jn==2))
{
nama="VCD";
jenis="kredit";
harga=450000;
dis=0;
}
else
{
nama="Tidak Ada";
jenis="Tidak Ada";
harga=0;
}
gotoxy(10,11);
cout<<"Nama barang ="<<nama;
gotoxy(10,12);
cout<<"Jenis Bayar = "<<jenis;
gotoxy(10,13);
cout<<"Harga Barang = "<<setw(8)<<harga;
gotoxy(10,14);
cout<<"Jumlah Beli = ";cin>>jumlah;
Total=harga*jumlah;
gotoxy(10,15);
cout<<"Total bayar = "<<Total;
gotoxy(10,16);
cout<<"Diskon = "<<dis;
gotoxy(10,17);
Tot=Total-dis;
gotoxy(10,18);
cout<<"Total ="<<Tot;
gotoxy(10,19);
cout<<"===========================\n";
gotoxy(10,20);
cout<<"Masih Mau Beli Barang Lagi[Y/T] = ";cin>> lagi;
clrscr();
}
}
Hasilnya akan seperti ini... :
Langganan:
Postingan (Atom)