Algoritma dan Struktur Data
Tugas 4 Programing Basic Algoritma

Assalamu'alaikum Wr. Wb.
Nama : Aufa Munadil Al - Khoir
NIMa : 3420210024
Prodi : Teknik Informatika
Fakultas : Sains dan Teknologi
Lampiran Tugas 4 Algoritma & Struktur Data
Example 1
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void garis();
void main()
{
char code,again; // Nama : Aufa Munadil Al - Khoir
// NIM : 3420210024
//Deklarasi Label // Prodi : Teknik Informatika
atas:
clrscr();
garis();
cout << "\t INPUT CODE CAR [X/Y/Z]: ";
code = getche();
cout << '\n';
garis();
cout << "\t = = ";
switch (code)
{
case 'X': case 'x':
cout << "SPORT CAR"; break;
case 'Y': case 'y':
cout << "SUPER CAR"; break;
case 'Z': case 'z':
cout << "OFF ROAD CAR"; break;
default:
cout << "CAR CODE NOT AVAILABLE \n";
}
cout << '\n';
garis();
cout << "\n\t CHOOSE AGAIN [R/N]: ";
again = getche();
if(again == 'R' || again == 'r') goto atas;
getch();
}
void garis()
{
cout << "\t = = = = = = = = = = = = = = = \n";
}
Example 2
Script Ex 2
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
void garis(); // Nama : Aufa Munadil Al - Khoir
void line(); // NIM : 3420210024
void main() // Prodi : Teknik Informatika
{
char code,again; char name[50],bonus[50];
int jml; float price,total,piece,ppn,grand;
again:
clrscr();
line();
printf("\t Masukan code Buku [S/R/F]: ");cin>>code;
printf("\t Jumlah Pembelian Buku : ");cin>>jml;
switch (code)
{
case 'S':
strcpy(name,"Rahasia Dunia yang Disembunyikan");
price = 158000;
break;
case 'R':
strcpy(name,"Strungle Off Life");
price = 45000;
break;
case 'F':
strcpy(name,"Find the Someone");
price = 45000;
default:
strcpy(name,"Kode Belum Tersedia");
price = 0;
}
total = price * jml; ppn = 0.1 * total;
if(jml>3) {
strcpy(bonus,"Totebag");
piece = 0.1 * total;
} else {
strcpy(bonus,"Maaf Tidak Dapat Bonus");
piece = 0;
}
grand = total + ppn - piece;
clrscr();
garis();
puts ("\t *** Ayu Bookstore ***");
puts ("\t Jl. Kesuksesan Batu Permata No.23");
garis();
cout << "\t Name Book : " << name << endl;
cout << "\t Price Book : " << price << endl;
cout << "\t Bonus : " << bonus << endl;
cout << "\t Total Pay : " << total << endl;
cout << "\t Discount : " << piece << endl;
cout << "\t PPN : " << ppn << endl;
cout << "\t Grand Total : " << grand << endl;
garis();
puts ("\t *** Thank You ***");
cout << "\t Input Again "; cin >> again;
if (again == 'Y' || again=='y') {goto again; }
getch();
}
void garis(){
cout << "\t - - - - - - - - - - - - - - - - - - - - - - - \n";
}
void line(){
cout << "\t # # # # # # # # # # # # # # # # # # # # # # # \n";
}
Example 3
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
void garis(); // Nama : Aufa Munadil Al - Khoir
void line(); // NIM : 3420210024
void main() // Prodi : Teknik Informatika
{
char name[92], type[29], souvenir[92];
char code, again;
int lama;
float price, total, admin=100000, pym, rfnd;
awal:
clrscr();
line();
puts ("\t ~ ~ ~ ~ ~ HOTEL BATU PERMATA BIRU ~ ~ ~ ~ ~");
line();
cout << "\t Tenant Name : ";cin>>name;
cout << "\t Room Code [S/A/P] : ";cin>>code;
if (code == 'S' || code == 's')
{
strcpy(type,"Superior Room");
price = 2300000;
}
else if (code == 'A' || code == 'a')
{
strcpy(type,"Smoking and Non-Smoking Room");
price = 1300000;
}
else if (code == 'P' || code == 'p')
{
strcpy(type,"Penthous Room");
price = 9200000;
}
else
{
line();
cout << "\t The Room Code you Entered is Wrong.\n\t Want to Enter Again? ";
cin >> again;
switch(again)
{
case 'Y':
case 'y':
goto awal;
default:
goto akhir;
}
}
clrscr();
line();
puts ("\t ~ ~ ~ ~ ~ HOTEL BATU PERMATA BIRU ~ ~ ~ ~ ~");
line();
cout << "\t Tenant Name : "<<name<<endl;
cout << "\t Room Code [S/A/P] : "<<code<<endl;
cout << "\t Length of Stay : ";cin>>lama;
garis();
if (lama>=12)
{
strcpy(souvenir,"Roxy Watch");
}
else
{
strcpy(souvenir,"Haverst Package");
}
total = (price * lama) + admin;
cout << "\t Type Room : " << type <<endl;
cout << "\t Length of Stay : " << lama << " Day" << endl;
cout << "\t Souvenir : " << souvenir <<endl;
printf ("\t Rental Cost : Rp. %8.2f \n",price);
printf ("\t Administrative Cost : Rp. %8.2f \n",admin);
printf ("\t Total Rental Cost : Rp. %8.2f \n",total);
garis();
cout << "\t Pay Money : Rp. ";cin>>pym;
rfnd = pym - total;
cout << "\t Refund : Rp. "<<rfnd<<endl;
cout << "\t Want to Enter Again [Y/T]: ";cin>>again;
switch(again)
{
case 'Y':
case 'y':
goto awal;
default:
goto akhir;
}
akhir:
getch();
}
void garis(){
cout << "\t . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n";
}
void line(){
cout << "\t ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \n";
}
Wassalamu'alaikum Wr. Wb.
Silakan Berikan Kritik dan Sarannya :)
Thank You
Tidak ada komentar:
Posting Komentar