PERTEMUAN 8 ALGORITMA DAN STRUKTUR DATA
Assalamualaikum wr.wb
Nama: Raihan Fajarahmatan
Nim: 3420210010
Prodi: Teknik Informatika
Tugas 8.1
#include <stdio.h>
#include <conio.h>
#include <iomanip.h>
#include <iostream.h>
/*
//Nama : Raihan Fajarahmatan
//NIM: 3420210010
//Prodi: Teknik Informatika
*/
void judul();
/*
https://cplusplus.com\reference/iomanip/setv/
Sets the field vidth to be used on output operations.
https://csplusplus.com/reference/iomanip/setiosflags/
Sets the format flags specified by parameter mask.
*/
void main() {
int i, jml;
judul();
printf("Masukan jumlah data: ");cin>>jml;
cout<<endl;
char nama[5][20];
int absen[5],quis[5],uts[5],uas[5];
double total[5];
for(i=1;i<=jml;i++) {
printf("Data ke %d\n",i);
printf("Nama siswa :");gets(nama[i]);
printf("Nilai Absen :");cin>>absen[i];
printf("Nilai quis :");cin>>quis[i];
printf("Nilai uts :");cin>>uts[i];
printf("Nilai uas :");cin>>uas[i];
total[i]=(absen[i]*0.1)+(quis[i]*0.2)+(uts[i]*0.3)+(uas[i]*0.4);
cout<<endl;
}
clrscr();
puts("===============================================");
puts("No Nama Siswa Absen Quis UTS UAS Total");
puts("===============================================");
for(i=1;i<=jml;i++)
{
cout<<setw(3)<<setiosflags(ios::left)<<i;
cout<<setw(13)<<nama[i];
cout<<setw(7)<<absen[i];
cout<<setw(6)<<quis[i];
cout<<setw(5)<<uts[i];
cout<<setw(5)<<uas[i];
printf("%.2f", total[i]);
cout<<endl;
}
puts("===============================================");
getch();
}
void judul() {
puts("===============================================");
puts("\tContoh Progam Array");
puts("===============================================");
}
Tugas 8.2
#include <stdio.h>
#include <conio.h>
#include <iomanip.h>
#include <iostream.h>
/*
//Nama : Raihan Fajarahmatan
//NIM: 3420210010
//Prodi: Teknik Informatika
*/
void main()
{
puts("==================================");
puts(" SABANA MURAH BANGET");
puts("==================================");
puts(" Kode Jenis Harga");
puts("==================================");
puts(" D Dada 12000");
puts(" P Paha 10000");
puts(" S Sayap 7500");
char nama[20];
int i, jml;
puts("==================================");
printf("Masukan nama pembeli: ");cin>>nama;
printf("Masukan jumlah beli: ");cin>>jml;
char kode;
char jenis[5][20];
int jumlah[5], harga[5];
float total[5];
float tobay=0, pajak, grand;
for(i=1;i<=jml;i++)
{
printf("\n");
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] = 15000;
strcpy(jenis[i], "Dada");
break;
case 'P':
case 'p':
harga[i] = 12000;
strcpy(jenis[i], "Paha");
break;
default:
harga[i] = 7500;
strcpy(jenis[i], "Sayap");
break;
}
//Hitung Total
total[i] = jumlah[i]*harga[i];
tobay = tobay + total[i];
}
clrscr();
puts("==================================");
puts(" SABANA MURAH BANGET");
puts("==================================");
puts("No Jenis Harga Jml Total");
puts("==================================");
for(i=1;i<=jml;i++)
{
cout<<setw(4)<<setiosflags(ios::left)<<i;
cout<<setw(7)<<jenis[i];
cout<<setw(7)<<harga[i];
cout<<setw(5)<<jumlah[i];
cout<<total[i]<<endl;
}
//Hitung Pajak
pajak = 0.1 * tobay;
//Hitung Grand
grand = tobay + pajak;
puts("==================================");
printf("\tTotal Bayar: %.0f\n", tobay);
printf("\tPajak : %.0f\n", pajak);
printf("\tGrand Total: %.0f\n", grand);
getch();
}
Sekian dan terimakasih
Wassalamualaikum wr.wb
Komentar
Posting Komentar