Tugas Al goritma & Struktur Data pertemuan ke 14
Nama : Nasrudin
Nim : 3420210031
Jurusan : Teknik Informatika
contoh 1
#include "stdio.h"
#include <conio.h>
#include "iostream.h"
#include <iomanip.h>
/*
Nama : Nasrudin
NIM : 3420210031
Prodi : Informatika
*/
float total (int jumbel, float harga) { return jumbel * harga; }
void garis () { cout<<"==============================================\n"; }
void judul () { cout<<"\t Rojullun store"<<endl; garis(); }
//Deklarasi Struct jangan lupa diakhiri 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<<"welcome in Rojullun store."<<endl;
cout<<"Ketentuan Belanja"<<endl;
puts("1. Jika kode A maka Nama Barang adalah Handphone\n");
puts("2. Jika kode B maka Nama Barang adalah headphone\n");
puts("3. Jika kode C maka Nama Barang adalah mouse\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, "handphone");
market [i].hrg=35000;
}
else if (market [i].kode == 'B' || market [i].kode == 'b')
{
strcpy (market [i].nama, "headphone");
market [i].hrg=65000;
}
else if (market [i].kode == 'C' || market[i].kode == 'c')
{
strcpy (market [i].nama, "mouse");
market [i].hrg=50000;
}
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();
}
contoh tugas 2
#include <iostream.h>
#include "stdio.h"
#include <conio.h>
#include "iomanip.h"
/*
Nama : Nasrudin
NIM : 3420210031
Prodi : 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 [25], int kelamin);
};
void pelanggan::set_pel(char nama [20], int kelamin)
{
strcpy (nmpel,nama);
jkpel = kelamin;
}
struct data
{
char merk [25];
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 ("Nasrudin",0);
strcpy (kd_penyewa, "PL001");
}
else if (strcmp (kd_penyewa, "PL002") == 0 || strcmp(kd_penyewa, "p1002") == 0)
{
pel.set_pel ("Rojullun",0);
strcpy (kd_penyewa, "PL002");
}
else if (strcmp (kd_penyewa, "PL003") == 0 || strcmp(kd_penyewa, "p1003") == 0)
{
pel.set_pel ("Udin",1);
strcpy (kd_penyewa, "PL003");
}
clrscr();
judul ();
puts ("Data Ke - ");
puts ("Kode Mobil [A/B/C]");
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] == 'A' || kd_mobil[i] == 'a')
{
strcpy (mobil[i].merk, "ferary");
mobil[i].harga = 80000000;
}
else if (kd_mobil[i] == 'B' || kd_mobil[i] == 'b')
{
strcpy (mobil [i].merk, "Mercy");
mobil[i].harga = 9500000;
}
else if (kd_mobil[i] == 'C' || kd_mobil[i] == 'c')
{
strcpy (mobil [i].merk, "Avanza");
mobil[i].harga = 7500000;
}
subtotal[i] = mobil[i].harga * mobil[i].sewa;
total = total + subtotal[i];
}
clrscr();
cout<<"\tData Penyewaan Mobil Rental Rojullun"<<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,"Perempuan");
} else {
strcpy(jk_penyewa,"Laki-laki");
}
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 Rojullun");
garis ();
}
Komentar
Posting Komentar