UNIVERSITAS ISLAM ASSAFI'IYAH
Nama : Nasrudin
Nim : 3420210031
Jurusan : Teknik Informatika
Contoh .1
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
/*
Nama : Nasrudin
NIM : 3420210031
Prodi : Informatika
*/
void judul ();
void main()
{
int i, jml;
judul ();
printf ("Masukan Jumlah Data:");cin>>jml;
cout<<endl;
char nama[5][20];
int a[5],t[5],uts[5],uas[5];
double total [5];
for(i=1;i<=jml;i++)
{
printf("Data Ke %d\n",i);
cout <<"Nama Siswa :";cin>>nama[i];
cout <<"Nilai Absen :";cin>>a[i];
cout <<"Nilai Tugas :";cin>>t[i];
cout <<"Nilai UTS :";cin>>uts[i];
cout <<"Nilai UAS :";cin>>uas[i];
total [i]=(a[i]*0.1)+(t[i]*0.2)+(uts[i]*0.3)+(uas[i]*0.4);
cout<<endl;
}
clrscr();
printf("=================================================================\n");
printf("No Nama Siswa Absen Tugas UTS UAS Total\n");
printf("=================================================================\n");
for(i=1;i<=jml;i++)
{
cout<<setw(4)<<setiosflags(ios::left)<<i;
cout<<setw(14)<<nama[i];
cout<<setw(9)<<a[i];
cout<<setw(9)<<t[i];
cout<<setw(7)<<uts[i];
cout<<setw(6)<<uas[i];
printf("%.2f",total[i]);
cout<<endl;
}
printf("=================================================================\n");
puts("\t\t\t Terimakasih");
printf("=================================================================\n");
getch();
}
void judul()
{
printf ("=================================================================\n");
puts("\t\tContoh Program Array");
printf ("=================================================================\n");
}
Contoh.2
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
/*
Nama : Nasrudin
NIM : 3420210031
Prodi : Informatika
*/
void main()
{
cout<<"=============================="<<endl;
puts (" Gerobak Fried Chicken");
cout<<"=============================="<<endl;
puts (" Kode Jenis Harga");
cout<<"=============================="<<endl;
puts (" D Dada 12000");
puts (" P Paha 8500");
puts (" S Sayap 10000");
cout<<"=============================="<<endl;
char nama[20];
int i, jml;
cout<<"Masukkan Nama Pembeli : ";cin>>nama;
cout<<"Masukkan Jumlah Beli : ";cin>>jml;
char kode;
char jenis[5][20];
int jumlah[5], harga[5];
float total[5];
float totbay=0, pajak, grand;
for (i=1; i<=jml; i++)
{
cout<<endl;
printf ("Data Ke : %d\n",i);
printf ("Masukan Kode [D][P][S] : ");cin>>kode;
printf ("Jumlah Beli : ");cin>>jumlah[i];
switch (kode)
{
case 'D':
case 'd':
harga[i] = 12000;
strcpy(jenis[i],"Dada");
break;
case 'P':
case 'p':
harga[i] = 8500;
strcpy(jenis[i],"Paha");
break;
default:
harga[i] = 10000;
strcpy(jenis[i],"Sayap");
break;
}
total[i] = jumlah[i]*harga[i];
totbay = totbay + total[i];
}
clrscr();
cout<<"================================="<<endl;
puts (" Gerobak Fried Chicken");
cout<<"================================="<<endl;
puts ("No Jenis Harga jml total");
cout<<"================================="<<endl;
for(i=1;i<=jml;i++)
{
cout<<setw(5)<<setiosflags(ios::left)<<i;
cout<<setw(8)<<jenis[i];
cout<<setw(8)<<harga[i];
cout<<setw(6)<<jumlah[i];
cout<<total[i]<<endl;
}
pajak = 0.1 * totbay;
grand = totbay + pajak;
cout<<"================================="<<endl;
printf ("\tTotal Bayar : %.0f\n",totbay);
printf ("\tPajak : %.0f\n",pajak);
printf ("\tGrand Total : %.0f\n",grand);
cout<<"================================="<<endl;
puts (" Terimakasih");
getch();
}
Komentar
Posting Komentar