Thursday, 15 December 2011

Membuat Tabelpada C++ dengan menggunakan array if, dan header IOMANIP.H


#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
void main()
{
clrscr();
int a,kelas;
char *kls1="BEGINNER",
     *kls2="ELEMENTARY",
     *kls3="INTERMIDIT",
     *kls[8];
char nama[5][10],
     jk[5][3],
     alamat[5][20],
     telp[5][15];
float jumpa[5], bayar[5];
for (a=1;a<=3;a++)
{
cout<<"Nomor Peserta     : "<<a<<endl;
cout<<"Nama  Peserta     : ";gets(nama[a]);
cout<<"Kelas             : ";cin>>kelas;
cout<<"Jenis Kelamin     : ";gets(jk[a]);
cout<<"Alamat            : ";gets(alamat[a]);
cout<<"Telephone         : ";gets(telp[a]);
cout<<"Jumlah tatap muka : ";cin>>jumpa[a];
cout<<endl;

if(kelas==1)
{
strcpy(kls[a],kls1);
bayar[a]=(jumpa[a]*1000);}
else if (kelas==2)
{
strcpy(kls[a],kls2);
bayar[a]=(jumpa[a]*2000);}
else if (kelas==3)
{
strcpy(kls[a],kls3);
bayar[a]=(jumpa[a]*3000);}
else;
}
{
cout<<"------------------------------------------------------------------------------"<<endl;
cout<<"No| Nama      | Kelas       | Alamat         | Sex| Telp.    | Hadir| Bayar  |"<<endl;
cout<<"------------------------------------------------------------------------------"<<endl;
}
for(a=1;a<=3;a++)
{
cout<<setiosflags(ios::left)<<setw(2)<<a<<"| ";
cout<<setiosflags(ios::left)<<setw(10)<<nama[a]<<"| ";
cout<<setiosflags(ios::left)<<setw(12)<<kls[a]<<"| ";
cout<<setiosflags(ios::left)<<setw(15)<<alamat[a]<<"| ";
cout<<setiosflags(ios::left)<<setw(3)<<jk[a]<<"| ";
cout<<setiosflags(ios::left)<<setw(9)<<telp[a]<<"| ";
cout<<setiosflags(ios::left)<<setw(5)<<jumpa[a]<<"|";
cout<<setiosflags(ios::right)<<setw(8)<<bayar[a]<<"| "<<endl;
}
cout<<"------------------------------------------------------------------------------"<<endl;
getch();
}

No comments:

Post a Comment