Senin, 24 Maret 2014

Codingan Program Beli Pizza C++


#include<iostream>

using namespace std;

void clear()
{
for(int i=0;i<25;i++)cout<<endl;
}

void main()
{
int opt;
int pizza, qtyM = 0, qtyV = 0;
double total = 0;
double money;

do
{
opt = 0;
clear();
cout<<"Welcome to Yummmy Delivery Pizza"<<endl;
cout<<"================================"<<endl;
cout<<"1.Order Pizza"<<endl;
cout<<"2.Pay"<<endl;
cout<<"3.Exit"<<endl<<endl;
do
{
cout<<"Choose :";
cin>>opt;cin.sync();cin.clear();
}while(opt< 1 || opt > 3);
switch(opt)
{
case 1:
pizza = 0;
clear();
cout<<"Choose an order"<<endl;
cout<<"==============="<<endl;
cout<<"1. Meat Lover Pizza (@ Rp. 80000,-)"<<endl;
cout<<"2. Vegetarian Pizza (@ Rp. 50000,-)"<<endl<<endl;
do{
cout<<"Which pizza do you want to order[1-2]: ";
cin>>pizza;
cin.sync(); cin.clear();
}while(pizza<1 || pizza>2);
if(pizza == 1)
{
total += 80000;
qtyM++;
}
else
{
total += 50000;
qtyV++;
}
cout<<"Thank you...";
cin.get();
break;
case 2:
clear();
if(total==0){
cout<<"You haven't bought anything.."<<endl;
}else{
cout<<"You have ordered " << qtyM << " Meat Lover Pizza(s) and " << qtyV << " Vegetarian Pizza(s)." <<endl << endl << endl;
cout<<"Total price : Rp. "<<total<<endl;
do{
cout<<"Input your money [minimum Rp. "<<total << "] :Rp. ";
cin>>money;
cin.sync(); cin.clear();
}while(money<total);
cout<<"Your change : Rp. "<<money-total<<endl;
total = 0;
qtyM = 0;
qtyV = 0;
cout<<"Thank you...";

}
cin.get();
break;
case 3:
clear();
printf("Thank you for buying our pizza...");
cin.get();
break;
}

}while(opt != 3);
}

Jumat, 21 Maret 2014

Stack Uasing Linked List


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>


struct tnode{
int hasil;
struct tnode *next;

};
struct tnode *TOP = 0;

void add(){
int angka;
printf("masukkan x:");
scanf("%d",&angka);

struct tnode *node = (struct tnode *)malloc(sizeof(struct tnode));
node->hasil = angka;
node->next = TOP;
TOP = node;
}

void view1(){
if(TOP==0)
printf("kosong");
else
printf("atas:%d",TOP->hasil);

getchar();
}


void hapus(){
if(TOP==0)
printf("kosong");
else{
struct tnode *del=TOP;
TOP=TOP->next;
free(del);
}
}

void main(){
int pilih;
do{
system("cls");
printf("\t\tstack using linked list\n");
printf("\t\t=======================\n\n");
printf("1. add\n");
printf("2. delete\n");
printf("3. view\n");
printf("4. exit\n");
printf("pilihan anda:");
scanf("%d",&pilih);fflush(stdin);
if(pilih<1||pilih>5){
printf("pilih antara 1..4");
getchar();
}else{
switch(pilih){
case 1:add();break;
case 2:hapus();break;
case 3:view1();break;

}
}
}while(pilih!=4);

getchar();
}

Queue Using Linked list


#include<string.h>
#include<windows.h>
#include<stdio.h>


struct tnode{
int number;
tnode *next;

}*curr,*head=NULL;
struct tnode *front = 0;
struct tnode *tail = 0;

void add(){
int x;

printf("Input x : ");
scanf("%d", &x); fflush(stdin);

struct tnode *node = (struct tnode *)malloc(sizeof(struct tnode));
node->number = x;
node->next = 0;
if (front==NULL){

front = tail = node;
}
else{

tail->next = node;
tail = node;
}
}

void view(){
if (front == 0)
printf("Kosong ");
else{
while (front!=NULL){
printf("%d", front->number);
front = front->next;
}
} getchar();
}

void hapusAll(){
struct tnode *del = front;
if (front == 0){
printf("Queue kosong");
}else{
front = front->next;
free(del);
}
}

void main(){
int pilih;
do{
system("cls");
printf("\t\t Queue using linked list\n");
printf("\t\t   =by singgihchandra=\n\n");
printf("1. enqueue\n");
printf("2. dequeue\n");
printf("3. display\n");
printf("4. exit\n");
printf("pilihan anda:");
scanf("%d",&pilih);fflush(stdin);
if(pilih<1||pilih>5){
printf("pilih antara 1..4");
getchar();
}else{
switch(pilih){
case 1:add();break;
case 2:hapusAll();break;
case 3:view();break;
}
}
}while(pilih!=4);


getchar();
}