Berikut adalah contoh program C++ untuk membuat menu makanan kasir restoran lengkap beserta penjelasan fungsi yang digunakan.
C++
#include <iostream>
using namespace std;
void tampilkanMenu() {
cout << "========== MENU MAKANAN ==========" << endl;
cout << "1. Nasi Goreng" << endl;
cout << "2. Mie Ayam" << endl;
cout << "3. Sate Ayam" << endl;
cout << "4. Ayam Bakar" << endl;
cout << "5. Soto Ayam" << endl;
cout << "===================================" << endl;
}
void pesanMakanan(int nomorMenu) {
switch (nomorMenu) {
case 1:
cout << "Anda memesan Nasi Goreng" << endl;
break;
case 2:
cout << "Anda memesan Mie Ayam" << endl;
break;
case 3:
cout << "Anda memesan Sate Ayam" << endl;
break;
case 4:
cout << "Anda memesan Ayam Bakar" << endl;
break;
case 5:
cout << "Anda memesan Soto Ayam" << endl;
break;
default:
cout << "Menu tidak valid" << endl;
break;
}
}
int main() {
int pilihan;
tampilkanMenu();
cout << "Masukkan nomor menu yang ingin dipesan: ";
cin >> pilihan;
pesanMakanan(pilihan);
return 0;
}
C++Contoh lain
C++
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
main()
{
int menu;
menu :
cout<<">>>>>>>> MENU <<<<<<<<"<<endl;
cout<<"1. Nested if "<<endl;
cout<<"2. Switch Case"<<endl;
cout<<"3. While "<<endl;
cout<<"4. 1st For "<<endl;
cout<<"5. 2nd For "<<endl;
cout<<"masukan pilihan anda[1/2/3/4/5]= ";
cin>>menu;
system("cls");
switch (menu)
{
case 1:
char nama[30];
long int nim, mid, final, assign, na;
char grade, out;
menu1 :
cout<<"Masukkan NIM : ";
cin>>nim;
cout<<"Masukkan Nama : ";
cin>>nama;
cout<<"\n___________________________________________________________\n";
cout<<" Nilai Mid : ";
cin>>mid;
cout<<" Nilai Final : ";
cin>>final;
cout<<" Nilai Assignment : ";
cin>>assign;
cout<<"\n\n\n";
na = (mid*0.35) + (final*0.40) + (assign*0.25);
if(na >= 65){
cout<<"PASS"<<endl;
}
else{
cout<<"FAIL"<<endl;
}
if (na >= 80){
grade = 'A';
}else if (na >= 70){
grade = 'B';
}else if (na >= 60){
grade = 'C';
}else if (na >= 50){
grade = 'D';
}else{
grade = 'E';
}
cout<<nim<<endl;
cout<<nama<<endl;
cout<<"Score : "<<na<<endl;
cout<<"\n-------------------------------------\n";
cout<<"Grade : "<<grade<<endl;
if (na>60){
cout<<"Pertahankan dan Tingkatkan prestasimu";
}
else {
cout<<"Belajarlah lebih giat";
}
cout<<"\n-------------------------------------\n";
cout<<"\nkembali ke menu Nested if yes(y)/no(n)menu utama/exit(e) = ";
cin>>out;
if(out=='y'){
goto menu1;
}
else if(out == 'n'){
goto menu;
}
else{
system("cls");
}
break;
case 2:
int menu2;
long int jb, bayar, harga, dis, pay;
char out1;
menu2 :
cout<<"Fresh menu Price(rp) "<<endl;
cout<<"1.juice 10.000 "<<endl;
cout<<"2.soft drink 15.000 "<<endl;
cout<<"3.milk shake 20.000 "<<endl;
cout<<"4.tiramisu 18.000 "<<endl;
cout<<"5.cookies cream 20.000 "<<endl;
cout<<"masukan pilihan anda[1/2/3/4/5]= ";
cin>>menu2;
system("cls");
switch (menu2)
{
case 1:
harga= 10000;
cout<<"Juice"<<endl;
cout<<"harga = 10000"<<endl;
cout<<"masukan jumlah beli= ";
cin>>jb;
bayar = jb * harga ;
cout<<"total = "<< bayar<<endl;
if (jb>=2){
dis = (jb * harga) * 0.1;
cout<<"discount = "<< dis<<endl;
cout<<" ";
pay = bayar - dis;
cout<<"jumlah yang harus di bayar = "<<pay<<endl;
}else{
cout<<"discout = 0"<<endl;
cout<<"jumlah yang harus di bayar = "<<bayar<<endl;
}
break;
case 2:
harga= 15000;
cout<<"soft drink "<<endl;
cout<<"harga = 15000"<<endl;
cout<<"masukan jumlah beli= ";
cin>>jb;
bayar = jb * harga ;
cout<<"total = "<< bayar<<endl;
if (jb>=2){
dis = (jb * harga) * 0.1;
cout<<"discount = "<< dis<<endl;
cout<<" ";
pay = bayar - dis;
cout<<"jumlah yang harus di bayar = "<<pay<<endl;
}else{
cout<<"discount = 0"<<endl;
cout<<"jumlah yang harus di bayar = "<<bayar;
}
break;
case 3:
harga= 20000;
cout<<"milk shake"<<endl;
cout<<"harga = 20000"<<endl;
cout<<"masukan jumlah beli= ";
cin>>jb;
bayar = jb * harga ;
cout<<"total = "<< bayar<<endl;
if (jb>=2){
dis = (jb * harga) * 0.1;
cout<<"discount = "<< dis<<endl;
cout<<" ";
pay = bayar - dis;
cout<<"jumlah yang harus di bayar = "<<pay<<endl;
}else{
cout<<"discout = 0";
cout<<"jumlah yang harus di bayar = "<<bayar<<endl;
}
break;
case 4:
harga= 20000;
cout<<"Tiramisu"<<endl;
cout<<"harga = 18000"<<endl;
cout<<"masukan jumlah beli= ";
cin>>jb;
bayar = jb * harga ;
cout<<"total = "<< bayar<<endl;
if (jb>=2){
dis = (jb * harga) * 0.1;
cout<<"discount = "<< dis<<endl;
cout<<" ";
pay = bayar - dis;
cout<<"jumlah yang harus di bayar = "<<pay<<endl;
}else{
cout<<"discout = 0";
cout<<"jumlah yang harus di bayar = "<<bayar<<endl;
}
break;
case 5:
harga= 20000;
cout<<"cookies cream"<<endl;
cout<<"harga = 20000"<<endl;
cout<<"masukan jumlah beli= ";
cin>>jb;
bayar = jb * harga ;
cout<<"total = "<< bayar<<endl;
if (jb>=2){
dis = (jb * harga) * 0.1;
cout<<"discount = "<< dis<<endl;
cout<<" ";
pay = bayar - dis;
cout<<"jumlah yang harus di bayar = "<<pay<<endl;
}else{
cout<<"discout = 0";
cout<<"jumlah yang harus di bayar = "<<bayar<<endl;
}
break;
default:
cout<<"masukan pilihan yang benar";
break;
}
cout<<"\nkembali ke menu Switch Case yes(y)/no(n)menu utama/exit(e) = ";
cin>>out1;
if(out1 =='y'){
goto menu2;
}
else if(out1 == 'n'){
goto menu;
}
else{
system("cls");
}
break;
case 3: {
int n=1,limit,c,y=1;
char out2;
long int hasil,sum;
menu3 :
cout<<"masukkan limit : ";
cin>>limit;
cout<<"masukkan pangkat : ";
cin>>c;
cout<<endl;
while (y<=limit)
{
cout<<limit;
cout<<" ";
limit--;
hasil=limit*limit;
sum=sum+hasil;
}
cout<<" = "<<sum;
cout<<"\nkembali ke menu while yes(y)/no(n)menu utama/exit(e) = ";
cin>>out2;
if(out2 =='y'){
goto menu3;
}
else if(out2 == 'n'){
goto menu;
}
else{
system("cls");
}
}
break;
case 4:
{
int bil, a=0,y;
char out3;
menu4 :
cout<<"MASUKAN ANGKA = ";
cin>>bil;
for (y=1; y<=bil; y++)
{
if ( bil%y == 0){
a++;
}
}
if (a==2){
cout<<"bilangan Prima";
}
else{
cout<<"bukan bilangan Prima";
}
cout<<"\nkembali ke menu 1st for yes(y)/no(n)menu utama/exit(e) = ";
cin>>out3;
if(out3 =='y'){
goto menu4;
}
else if(out3 == 'n'){
goto menu;
}
else{
system("cls");
}
}
break;
case 5:
int limit,batch;
char major[20], out4;
menu5 :
cout<<"masukan batas data : ";
cin>>limit;
for (int f=1; f<=limit; f++) {
cout<<"masukan program study : ";
cin>>major;
cout<<"masukan angkatan : "<<endl;
cin>>batch;
}
cout<<"\nkembali ke menu 2nd for yes(y)/no(n)menu utama/exit(e) = ";
cin>>out4;
if(out4 =='y'){
goto menu5;
}
else if(out4 == 'n'){
goto menu;
}
else{
system("cls");
}
break;
break;
default:
cout<<"pilihan tidak tersedia";
break;
}
}
C++Semoga contoh program di atas dapat membantu Anda dalam membuat menu makanan kasir restoran menggunakan bahasa pemrograman C++. Jika Anda memiliki pertanyaan lebih lanjut, jangan ragu untuk bertanya.
Leave a Reply