Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program Name: A2P2.cpp
- // Programmer Name: Alex Proulx
- // Overview: This is a menu for Vitto's Vending.
- // Date: 2/8/2016
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <cstdlib>
- #include <windows.h>
- #include <conio.h>
- #include <process.h>
- using namespace std;
- void gotoxy(int x, int y)
- {
- COORD coord;
- coord.X = x; //column coordinate
- coord.Y = y; //row coordinate
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- void clrscr(int x, int y)
- {
- COORD coordScreen = { x, y };
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD dwConSize;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- FillConsoleOutputCharacter(hConsole, TEXT(' '),
- dwConSize, coordScreen, &cCharsWritten);
- GetConsoleScreenBufferInfo(hConsole, &csbi);
- FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
- dwConSize, coordScreen, &cCharsWritten);
- SetConsoleCursorPosition(hConsole, coordScreen);
- }
- void greetings()
- {
- clrscr(0, 0);
- gotoxy(30, 10);
- cout << "Welcome to Vitto's!" << endl;
- gotoxy(30, 12);
- cout << "Mangiare, Mangiare!" << endl;
- gotoxy(30, 25);
- cout << "Press enter to continue...";
- _getch();
- clrscr(0, 0);
- }
- void thanks_for_shopping(int total_purchases)
- {
- clrscr(0, 0);
- gotoxy(25, 10);
- cout << "You have purchased" << total_purchases << "number of items.";
- gotoxy(25, 12);
- cout << "Thank You for shopping at Vitto's!";
- }
- void update_vending(string choice[8], string item_name[8],
- string price[7], int qty[7], string headers[4], int& header_position,
- int& choice_position, int& item_position, int& price_position, int& qty_position, int& total_purchases)
- {
- gotoxy(30, 1);
- cout << "VITTO'S VENDETTA VENDING" << endl;
- for (int i = 0; i < 4; i++)
- {
- gotoxy(header_position, 3);
- cout << headers[i] << endl;
- if (header_position == 8)
- {
- header_position = 18;
- }
- else if (header_position == 18)
- {
- header_position = 31;
- }
- else if (header_position == 18)
- {
- header_position = 40;
- }
- }
- for (int i = 0; i < 8; i++)
- {
- gotoxy(8, choice_position);
- cout << choice[i] << endl;
- choice_position++;
- }
- for (int i = 0; i < 8; i++)
- {
- gotoxy(18, item_position);
- cout << item_name[i] << endl;
- item_position++;
- }
- for (int i = 0; i < 7; i++)
- {
- gotoxy(31, price_position);
- cout << price[i] << endl;
- price_position++;
- }
- for (int i = 0; i < 8; i++)
- {
- gotoxy(40, qty_position);
- cout << qty[i] << endl;
- }
- int finished_purchases = 1;
- while (finished_purchases == 1)
- {
- char item_choice = _getch();
- item_choice = tolower(item_choice);
- int item_number = item_choice;
- //Quantity
- switch (item_choice)
- {
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- if (qty[item_number - 49] > 0)
- {
- qty[item_number - 49]--;
- gotoxy(40, 5 + item_number - 49);
- cout << qty[item_number - 49];
- total_purchases++;
- }
- if (qty[item_number - 49] == 0)
- {
- gotoxy(40, 5 + item_number - 49);
- cout << "OUT";
- }
- break;
- case 'e':
- finished_purchases = 0;
- thanks_for_shopping(total_purchases);
- }
- }
- }
- int main()
- {
- char repeat = 'y';
- while (repeat == 'y')
- {
- int header_position = 8;
- int choice_position = 5;
- int item_position = 5;
- int price_position = 5;
- int qty_position = 5;
- int qty[7] = { 5, 5, 5, 5, 5, 5, 5 };
- int total_purchases = 0;
- string choice[8] = { "1.", "2.", "3.", "4.", "5.", "6.", "7.", "E." };
- string item_name[8] = { "Soprano Soup", "Godfather Pasta", "Gotti Gum", "Capone Crisps", "Gambino Pie", "Luciano Lunch", "Mafia Muffin", "No More Purchases" };
- string price[7] = { "4.75", "5.85", "2.50", "3.00", "6.75", "8.50", "1.75" };
- string headers[4] = { "CHOICE", "ITEM NAME", "PRICE", "QTY" };
- //Function Call
- greetings();
- update_vending(choice, item_name, price, qty, headers, header_position, choice_position, item_position, price_position, qty_position, total_purchases);
- //Restart Application
- gotoxy(25, 10);
- cout << "Would you like to order more food? (y/n): ";
- cin >> repeat;
- }
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement