Hello again Codescharter, it took so long since my last devlog. As you may have read on the title this mock up project is about creating an Ordering System in C++. We may go to any fast-food stores, or any convenient store as a buyer. You are surely aware seeing a list of your orders in the screen, right? This system we are about to make is a simple as other programming system here on my blog. But don't you ever consider an ordering system as to easy coz' it may become a super system. What is a super system? Software system is composed not just one, but multiple systems.
What is the important of learning of ordering system?
Surely you must be aware of rapid growth of technology in our society. Where people are now buying their stuff on the internet, or may visit to buy books in your favorite bookstore. To long before computer came out this system actually exist, or you try to pay a visit to the local market area that are nearest from your location. You will probably hear people who are buying their stuff right from their hands.
Now lets code Ordering System in Step by Step
1. First set up a the main function
1 2 3 4 5 6 7 | #include<iostream> #include<conio.h> using namespace std; int main(){ return 0; } |
As you may be wonder for what can #include<iostream> do to your program well having it declared making you to be able to use or call all c++ functionality and syntaxes. On the lined to is a header for extra functionality that you’d like to have in your program. Remember that iostream can only be used for c++ program only, while conio.h can be used for both c++ and c. on the lined three you see using namespace std. for c++ program very useful to get rid off std:: commands. The main function where you will input your program.
2. Declaring variables
5 6 | int price, quant, set1 = 95, set2 = 100, set3 = 125, set4 = 115, payment, total = 0; char choice, gmenu; |
the int stands for integer where you are being able to store numerical numbers for specifically a decimal numbers or whole numbers, while char stands for character to stores a single letter value or alphabet. You see I declare many in integers and being separated by comma’s. do you even recognize those integers like set1 with an equal it’s about to replace its default value from one to 95.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<iostream> #include<conio.h> using namespace std; int main(){ int price, quant, set1 = 95, set2 = 100, set3 = 125, set4 = 115, payment, total = 0; char choice, gmenu; menu: system("cls"); cout<<"|| [A]Set 1\t\t|| [B]Set 2\t\t||"<<endl; cout<<"|| Burger \t\t|| Chesse Burger\t||"<<endl; cout<<"|| Drinks \t\t|| Drinks \t\t||"<<endl; cout<<"|| Price: 95 \t\t|| Price: 100 \t\t||"<<endl; cout<<" ====================== ======================"<<endl; cout<<"|| [C]Set 3\t\t|| [D]Set 4 \t\t||"<<endl; cout<<"|| Sandwich\t\t|| Spagetti\t\t||"<<endl; cout<<"|| Drinks\t\t|| Drinks\t\t||"<<endl; cout<<"|| Price: 125 \t\t|| Price: 115 \t\t||"<<endl; return 0; } |
In every type of an ordering system on the menu is the most visible part of the program where the users have free to select all item. A menu can be made of list of all products. A group of image lists for better presentation. Today there is lots of ways to create or to show a better menu presentation for its users.
The command that you can use to show outputs is cout. If you’re new in c++ you may be why there is \t in the text, right? It’s to create a space or tabs between letters inside cout. In every program you make the only way to show output is to use this command. You can’t make a program without output its one of the most important codes in c++.
4. Select items on the menu using switch
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | cout<<"\nyour order: "; cin>>choice; switch(choice){ case 'A' : case 'a' : cout<<"enter quantity: "; cin>>quant; total += (set1*quant); break; case 'B' : case 'b' : cout<<"enter quantity: "; cin>>quant; total += (set2*quant); break; case 'C' : case 'c' : cout<<"enter quantity: "; cin>>quant; total += (set3*quant); break; case 'D' : case 'd' : cout<<"enter quantity: "; cin>>quant; total += (set4*quant); break; default : cout << "\n\t\t\tSet not Available"<<endl; goto menu; break; } |
As a user you better select to any items on the menu to order. We used cin to read or to enter an input that a user wants to enter. Have multiple items on the menu, it’s better to use a switch for selecting any items on the menu. In selecting any kind of items on ordering system there lot of different way. In this program we used to enter the letter of the item. Using switch() is the best and ideal to use, because it has cases for you to choose from of whatever the next scene you wish to happen. And you can input any kind of program inside the cases. You can do lots of things in every cases for perform any code exhibition.
5. Enter quantity of your order
31 32 | cin>>quant; total += (set1*quant); |
This program is to enter quantity of the order you have chosen. For sample situation your customer like to order not just on or two, but three of the same item on the menu. In order to do that is to have your program that will ask for a quantity and will read the quantity that you will input.
6. Ask for reordering another item on the ordering system
67 68 69 70 71 72 73 74 75 | gomenu: cout<<endl<<"Want to order again? Y/N: "; cin>>gmenu; switch(gmenu){ case 'Y': case 'y': goto menu; break; |
This program is to let your user to add a new order after another. For sample situation your customer your customer orders the item A for two. Then he/she like to add item C with only one quantity as part of his/her total orders. If your program has a better user interface the user may only select any orders continuously without having this message popping out. It all depends on how you will show the menu for example if your menu is a clickable button and every item you click it will add to the list of your orders. Having this kindly of feature in your ordering system is good to make sure if your user likes to reorder again or not. Unlikely to this sample program in c++ in dos form if this same program is being perform in a better user interface. To have a message popping out in a message box if it was develop for a web or a desktop application. There is lot of ways to show this message to your user other than a message that pops out it could also perform by hidden at first then show after your user made a choice for an order. Remember what I told you regarding about adding lots of thing inside of a case as you may see if the users select yes to reorder again the program will go back directly again to the menu.
7. Check Payment in Ordering System using do…while loop in C++
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | gomenu: cout<<endl<<"Want to order again? Y/N: "; cin>>gmenu; switch(gmenu){ case 'Y': case 'y': goto menu; break; case 'N': case 'n': cout<<"Amout to Pay: "<<total<<endl; do { cout<<"Enter Your Payment: "; cin>>payment; if(payment>=total) { cout<<"Your Change: "<<payment - total; } else { cout<<"Payment not Enought"<<endl; } }while(payment<total); |
This code is use to validate payment to check the payment that the user have inputted, if the entered amount is enough or not. Using do while loop to check the payment is a good idea where a program will constantly asking the user to enter the payment if the payment is less than the total amount to pay. In every ordering system or any number computing system you’ll be able to see number checking if it’s too much or too less. If you’re a student doing a thesis project not adding this kind of feature in your project will surely end up your professors and panelist to cook during thesis defense. For example if it happen that your user accidentally entered a lesser amount in the payment and by not having this feature will led the program to proceed as it was the usual way. And by adding this feature will help to prevent that in happening for a better user experience.
8. To sum all the orders that the user have made in the ordering system
Phase 1:
27 28 29 30 31 32 33 | case 'A' : case 'a' : cout<<"enter quantity: "; cin>>quant; total += (set1*quant); break; |
In this system in order to include every orders in count is to add it all to a single integers which is the “total” to store all amount for every orders that the user have made. As you have seen this code snippet is phase 1.
Phase 2:
97 98 99 100 101 102 103 104 105 106 107 108 | cout<<endl<<"Total Bill: "<<total; break; default: cout<<"Choose either Y or N"; goto gomenu; break; } total = total + total; return 0; } |
In phase 2 you’ll see on that you’re constantly adding all orders in the end of the loop before going in to reordering. Then as the user choose to not to reorder again it will show the total amount to pay. Thanks for visiting CodesChart hope that this devlog help you in a better understanding the development of a system more specially to a ordering system, Hope to see again on my next devlog. And don’t forget to like and share my social media accounts @ facebook.com/codeschart.
No comments:
Post a Comment