PERTEMUAN 14 ALGORITMA DAN STRUKTUR DATA
ASSALAMUALAIKUM WR.WB
Nama: Raihan Fajarahmatan
NIM: 3420210010
Prodi: Teknik Informatika
Tugas 14.1
SCRIPT
#include "stdio.h"
#include <conio.h>
#include "iostream.h"
#include <iomanip.h>
/*
Nama : Raihan Fajarahmatan
NIM : 3420210010
Prodi : Teknik Informatika
*/
float total (int jumbel, float harga) { return jumbel * harga; }
void garis () { cout<<"==============================================\n"; }
void judul () { cout<<"\tSupermarket Chumbucket"<<endl; garis(); }
//Deklarasi Struct jangan lupa diakhiti titik koma.
struct data { char kode; char nama [20]; int jml; float hrg; };
char hurufbesar (char huruf)
{
int kodeascii = (int) huruf;
if (kodeascii>=97 && kodeascii<=122) { kodeascii = kodeascii - 32; }
return (char) kodeascii;
}
void main()
{
int i,n;
data market [10];
float subtotal [10];
long tobay=0;
depan:
clrscr();
judul ();
cout<<"Selamat datang ditoko kami."<<endl;
cout<<"Ketentuan Belanja"<<endl;
puts("1. Jika kode A maka Nama Barang adalah Baju\n");
puts("2. Jika kode B maka Nama Barang adalah Celana\n");
puts("3. Jika kode C maka Nama Barang adalah Sepatu\n");
puts("4. Jika input kode salah maka muncul pesan salah kode\n");
cout<<"Masukan Jumlah Data: "; cin>>n;
clrscr();
judul ();
cout<<"Data Ke "<<endl;
cout<<"Kode [A/B/C]: "<<endl;
cout<<"Jumlah Beli: "<<endl;
for (i=1;i<=n;i++)
{
gotoxy (11,3); clreol();
gotoxy (15,4); clreol();
gotoxy (15,5); clreol();
gotoxy (11,3); cout<<i;
gotoxy (15,4); cin>>market[i].kode;
gotoxy (15,5); cin>>market[i].jml;
if (market[i].kode == 'A' || market[i].kode == 'a')
{
strcpy (market [i].nama, "Baju");
market [i].hrg=20000;
}
else if (market [i].kode == 'B' || market [i].kode == 'b')
{
strcpy (market [i].nama, "Celana");
market [i].hrg=30000;
}
else if (market [i].kode == 'C' || market[i].kode == 'c')
{
strcpy (market [i].nama, "Sepatu");
market [i].hrg=40000;
}
else
{
goto salah;
}
subtotal[i] = total (market [i].jml, market [i].hrg);
tobay = tobay + subtotal [i];
}
clrscr();
judul ();
cout<<"No Kode Nama Barang Harga Jumlah Subtotal"<<endl;
garis ();
for (i=1;i<=n;i++)
{
cout<<setiosflags (ios::left)<<setw(3)<<i;
cout<<setw (5) <<hurufbesar (market [i].kode);
cout<<setw (13) <<market [i].nama;
cout<<setw (8) <<market [i].hrg;
cout<<setw (7) <<market [i].jml;
cout<<subtotal[i]<<endl;
}
garis ();
long ubay, ukem;
cout<<"\t\tTotal Bayar : "<<tobay<<endl;
cout<<"\t\tUang Bayar : "; cin>>ubay;
ukem = ubay - tobay;
cout<<"\t\tUang Kembali: "<<ukem<<endl;
goto belakang;
salah:
cout<<"Input kode salah..!!"<<endl;
goto belakang;
belakang:
char lagi;
cout<<"Ingin input data lagi [Y/T]: "; cin>>lagi;
if (lagi == 'y' || lagi == 'Y') { goto depan; }
getch();
}
TUGAS 14.2
//Contoh Class Tingkat Advance
#include <iostream.h>
#include "stdio.h"
#include <conio.h>
#include "iomanip.h"
/*
Nama : Raihan Fajarahmatan
NIM : 3420210010
Prodi : Teknik Informatika
*/
void garis();
void judul();
void jenis_kelamin (int kode);
void tipe_mobil (int kode);
class pelanggan
{
public:
char nmpel [20];
int jkpel;
void set_pel(char nama [20], int kelamin);
};
void pelanggan::set_pel(char nama [20], int kelamin)
{
strcpy (nmpel,nama);
jkpel = kelamin;
}
struct data
{
char merk [20];
int sewa;
long harga;
}mobil [10];
void main()
{
char nama_pet [20], kd_penyewa [5], jk_penyewa[10];
char kd_mobil[10];
int i,jml;
long subtotal [10], total=0;
judul ();
puts ("Nama Petugas : ");
puts ("Kode Penyewa : ");
puts ("Jumlah Data : ");
gotoxy (16,4); cin>>nama_pet;
gotoxy (16,5); cin>>kd_penyewa;
gotoxy (16,6); cin>>jml;
/*Pembuatan Object Pelanggan*/
pelanggan pel;
if (strcmp(kd_penyewa, "PL001") == 0 || strcmp (kd_penyewa, "p1001")==0)
{
pel.set_pel ("Riyan Wibowo",1);
strcpy (kd_penyewa, "PL001");
}
else if (strcmp (kd_penyewa, "PL002") == 0 || strcmp(kd_penyewa, "p1002") == 0)
{
pel.set_pel ("NETI NURHAYATI",0);
strcpy (kd_penyewa, "PL002");
}
else if (strcmp (kd_penyewa, "PL003") == 0 || strcmp(kd_penyewa, "p1003") == 0)
{
pel.set_pel ("ARETA VORSTEN",1);
strcpy (kd_penyewa, "PL003");
}
clrscr();
judul ();
puts ("Data Ke - ");
puts ("Kode Mobil [B/T/S]");
puts ("Masukan Kode: ");
puts ("Jumlah Sewa : ");
for (i=1;i<=jml;i++)
{
gotoxy (11,4); clreol();
gotoxy (16,6); clreol();
gotoxy (16,7); clreol();
gotoxy (11,4); cout<<i;
gotoxy (16,6); cin>>kd_mobil[i];
gotoxy (16,7); cin>>mobil[i].sewa;
if (kd_mobil[i] == 'B' || kd_mobil[i] == 'b')
{
strcpy (mobil[i].merk, "BMW");
mobil[i].harga = 1000000;
}
else if (kd_mobil[i] == 'T' || kd_mobil[i] == 't')
{
strcpy (mobil [i].merk, "Toyota");
mobil[i].harga = 850000;
}
else if (kd_mobil[i] == 'S' || kd_mobil[i] == 's')
{
strcpy (mobil [i].merk, "Suzuki");
mobil[i].harga = 400000;
}
subtotal[i] = mobil[i].harga * mobil[i].sewa;
total = total + subtotal[i];
}
clrscr();
cout<<"\tData Penyewaan Mobil Rental Tentacles"<<endl;
garis();
cout<<"Nama Petugas: "<<setiosflags (ios::left)<<setw(20)<<nama_pet;
cout<<"Kode Pelanggan : "<<kd_penyewa<<endl;
cout<<"Jumlah Data : "<<setw (20) <<jml;
cout<<"Nama Pelanggan : "<<pel.nmpel<<endl;
if (pel.jkpel == 0)
{
strcpy(jk_penyewa,"Wanita");
} else {
strcpy(jk_penyewa,"Pria");
}
cout<<setw (34) <<" "; //<<setw (20);
cout<<"Jenis Kelamin : "<<jk_penyewa<<endl;
garis ();
puts ("No Kode Merk Mobil Jumlah Harga Subtotal");
garis ();
for (i=1;i<=jml;i++)
{
cout<<setiosflags(ios::left)<<setw(4)<<i;
cout<<setw(6)<<kd_mobil[i];
cout<<setw(13)<<mobil[i].merk;
cout<<setw(8)<<mobil[i].sewa;
cout<<setw(8)<<mobil[i].harga;
cout<<subtotal[i];
cout<<endl;
}
garis ();
long ubay, ukem;
cout<<"\t\tTotal Bayar : "<<total<<endl;
cout<<"\t\tUang Bayar : ";cin>>ubay;
ukem = ubay - total;
cout<<"\t\tUang Kembali: "<<ukem;
getch();
}
void garis ()
{
puts ("==================================================================");
}
void judul ()
{
garis ();
puts("\t\tRental Mobil Tentacles");
garis ();
}
SEKIAN TERIMAKASIH
WASSALAMUALAIKUM WR.WB
Komentar
Posting Komentar