PROGRAM PEMESANAN KURSI
DENGAN BAHASA C
Kali ini saya akan berbagi program tentang simulasi pemesanan kursi pada sebuah cafe atau semacamnya, disini kita bisa memesan kursi dan kita juga bisa merubah nonor kursi yang kita pesan dan bisa juga membatalkannya ....
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
typedef struct{
char pemilik[20];
}PML;
int box[5];
int menu2;
char cari[20];
int no;
int cek;
int f,i,j;
PML data[20];
system("cls");
for (i=0; i<5; i++){
box[i]=0;
}
for (i=0; i<5; i++){
strcpy(data[i].pemilik,"kosong");
}
do{
printf("==================================\n");
printf("= PEMESANAN KURSI = \n");
printf("==================================\n");
printf("\n");
printf("\n=======================\n");
if(strcmp(data[i].pemilik,"kosong")==0){
box[i]=0;
}else{
box[i]=1;
}
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n\n");
printf(" 1. Lihat Pemilik Kursi \n");
printf(" 2. Pesan Kursi \n");
printf(" 3. Edit Pemilik Kursi \n");
printf(" 4. Edit Nomor Kursi \n");
printf(" 5. Batalkan Pemesanan \n");
printf(" 6. Exit \n");
printf("Masuka Pilihan : ");
scanf("%d", &menu2);
if(menu2 <= 6){
switch (menu2){
case 1 : {
system("cls");
printf("Lihat Pemilik Kursi \n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("Nomor Kursi : %d\n",i+1);
printf("Pemilik : %s\n\n",data[i].pemilik);
}
system("pause");
system("cls");
}
break;
case 2 : {
system("cls");
printf("Pesan Kursi\n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
i=no-1;
printf("Masukan Nama Anda : ");
fflush(stdin);gets(data[i].pemilik);
printf("\nselesai !!\n");
system("pause");
system("cls");
}
break;
case 3 : {
system("cls");
printf("Edit Pemilik Kursi\n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
j=no-1;
if(box[j]==0){
printf("Maaf, kursi yang anda pilih belum dipesan\n");
}else if(box[j]==1){
printf("Masukan Nama Anda : ");
fflush(stdin);gets(data[j].pemilik);
}
printf("\nselesai !!\n");
system("pause");
system("cls");
}
break;
case 4 : {
system("cls");
printf("Edit No. Kursi\n");
printf("=======================\n");
printf("Masukan Nama Anda : ");
fflush(stdin);gets(cari);
for (i=0; i<5; i++){
if (strcmp(data[i].pemilik,cari)==0){
f=i;
cek=0;
}
}
if(cek==0){
box[i=0];
printf("Ubah No. Kursi ke : ");
scanf("%d",&no);
i=no-1;
strcpy(data[i].pemilik,cari);
strcpy(data[f].pemilik,"kosong");
box[f]=0;
}else{
printf("Maaf nama pemilik tidak ditemukan \n");
}
system("pause");
system("cls");
}
break;
case 5 : {
system("cls");
printf("Batalkan Pemesanan \n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
box[i]=1;
printf("\n\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
i=no-1;
box[i]=box[i]-1;
strcpy(data[i].pemilik,"kosong");
system("pause");
system("cls");
}
break;
default :
break;
}
}else{
printf("Pilihan Tidak ada!\n");
system("pause");
system("cls");
}
}while ((menu2==0) || (menu2 != 6));
system("pause");
system("cls");
return 0;
}
#include <stdlib.h>
#include <string.h>
int main(){
typedef struct{
char pemilik[20];
}PML;
int box[5];
int menu2;
char cari[20];
int no;
int cek;
int f,i,j;
PML data[20];
system("cls");
for (i=0; i<5; i++){
box[i]=0;
}
for (i=0; i<5; i++){
strcpy(data[i].pemilik,"kosong");
}
do{
printf("==================================\n");
printf("= PEMESANAN KURSI = \n");
printf("==================================\n");
printf("\n");
printf("\n=======================\n");
if(strcmp(data[i].pemilik,"kosong")==0){
box[i]=0;
}else{
box[i]=1;
}
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n\n");
printf(" 1. Lihat Pemilik Kursi \n");
printf(" 2. Pesan Kursi \n");
printf(" 3. Edit Pemilik Kursi \n");
printf(" 4. Edit Nomor Kursi \n");
printf(" 5. Batalkan Pemesanan \n");
printf(" 6. Exit \n");
printf("Masuka Pilihan : ");
scanf("%d", &menu2);
if(menu2 <= 6){
switch (menu2){
case 1 : {
system("cls");
printf("Lihat Pemilik Kursi \n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("Nomor Kursi : %d\n",i+1);
printf("Pemilik : %s\n\n",data[i].pemilik);
}
system("pause");
system("cls");
}
break;
case 2 : {
system("cls");
printf("Pesan Kursi\n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
i=no-1;
printf("Masukan Nama Anda : ");
fflush(stdin);gets(data[i].pemilik);
printf("\nselesai !!\n");
system("pause");
system("cls");
}
break;
case 3 : {
system("cls");
printf("Edit Pemilik Kursi\n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
for (i=0; i<5; i++){
printf(" %d ",i+1);
}
printf("\n\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
j=no-1;
if(box[j]==0){
printf("Maaf, kursi yang anda pilih belum dipesan\n");
}else if(box[j]==1){
printf("Masukan Nama Anda : ");
fflush(stdin);gets(data[j].pemilik);
}
printf("\nselesai !!\n");
system("pause");
system("cls");
}
break;
case 4 : {
system("cls");
printf("Edit No. Kursi\n");
printf("=======================\n");
printf("Masukan Nama Anda : ");
fflush(stdin);gets(cari);
for (i=0; i<5; i++){
if (strcmp(data[i].pemilik,cari)==0){
f=i;
cek=0;
}
}
if(cek==0){
box[i=0];
printf("Ubah No. Kursi ke : ");
scanf("%d",&no);
i=no-1;
strcpy(data[i].pemilik,cari);
strcpy(data[f].pemilik,"kosong");
box[f]=0;
}else{
printf("Maaf nama pemilik tidak ditemukan \n");
}
system("pause");
system("cls");
}
break;
case 5 : {
system("cls");
printf("Batalkan Pemesanan \n");
printf("=======================\n");
for (i=0; i<5; i++){
printf("[%d] ",box[i]);
}
printf("\n=======================\n");
box[i]=1;
printf("\n\n");
printf("Pilih No. Kursi : ");
scanf("%d",&no);
i=no-1;
box[i]=box[i]-1;
strcpy(data[i].pemilik,"kosong");
system("pause");
system("cls");
}
break;
default :
break;
}
}else{
printf("Pilihan Tidak ada!\n");
system("pause");
system("cls");
}
}while ((menu2==0) || (menu2 != 6));
system("pause");
system("cls");
return 0;
}