I am having a problem understanding how to set up a vector in the way the book is asking.
I understand vectors are similar to arrays but are flexible.
CODE
//Chapter 6 - Programming Project #7
//Program designed to track type of pizza
//along with the size and number of toppings.
//Written by Louis McAlister
//COSC 231 - OOP
//Professor Doc Craddock
#pragma once
#include <iostream>
#include <string>
#include <iomanip>
#include<cstdlib>
#include<vector>
using namespace std;
class Pizza
{
private:
int pie_type;
int pie_size;
int pie_topz;
public:
void Output_Description(); //Displays pizza type, size, toppings
void Compute_Price(); //Displays cost of pizza
void input_Ptype(); //User input of pizza type
void input_Psize(); //User input of pizza size
void input_NumTops(); //User input of number of toppings
};
class Order
{
private:
vector <Pizza> orders;
public:
void add_pizz\a(Pizza);
};
[MAIN]
#include "Pizza.h"
const string Pizza_Type [3] = {"Deep Dish", "Hand Tossed", "Pan"};
const string Pizza_Size [3] = {"Small", "Medium", "Large"};
const string Pizza_Topz [3] = {"Pepperoni", "Cheese", "Pepperoni and Cheese"};
const int Pizza_Cost [3] = {10, 12, 17};
int main()
{
Pizza pie;
pie.input_Ptype();
pie.input_Psize();
pie.input_NumTops();
pie.Output_Description();
// test_disp();
}
void Pizza::input_Ptype(){
cout << "Type of Pizza\n";
cout << "1 - " << Pizza_Type[0] << "\n";
cout << "2 - " << Pizza_Type[1] << "\n";
cout << "3 - " << Pizza_Type[2] << "\n";
cin >> pie_type;
if (pie_type > 3 || pie_type == 0)
{
cout << "Invalid selection for pizza type.\n"
<< "Selection must be 1, 2, or 3\n\n"
<< "Program will now terminate."
<< endl;
exit(1);
}
}
void Pizza::input_Psize(){
cout << "Pizza Size\n";
cout << "1 - " << Pizza_Size[0] << "\n";
cout << "2 - " << Pizza_Size[1] << "\n";
cout << "3 - " << Pizza_Size[2] << "\n";
cin >> pie_size;
if (pie_size > 3 || pie_size == 0)
{ cout << "Invalid selection for pizza size.\n"
<< "Selection must be 1, 2, or 3\n\n"
<< "Program will terminate."
<< endl;
exit (1);
}
}
void Pizza::input_NumTops(){
cout << "\nPizza Toppings\n"
<< "Number of toppings for this pizza.\n"
<< "Each topping is $2.00: ";
cout << "\n1 - " << Pizza_Topz[0] << "\n";
cout << "2 - " << Pizza_Topz[1] << "\n";
cout << "3 - " << Pizza_Topz[2] << "\n";
cin >> pie_topz;
if (pie_topz > 3 || pie_topz == 0)
{ cout << "Invalid selection for pizza toppins.\n"
<< "Selection must be 1, 2, or 3\n\n"
<< "Program will terminate."
<< endl;
exit (1);
}
}
void Pizza::Output_Description()
{
//Order lfm;
//lfm.orders.push_back(pt,ps, topz1);
//lfm.orders.push_back("j",1);
cout << "\nThe output for Pizza Type: "
<< pie_type
<< "\nThe output for Pizza Size: "
<< pie_size
<< "\nThe output for Pizza Toppings: "
<< pie_topz << endl;
//cout << lfm.orders[0];
}
Problem from book
6. This Programming Project requires you to first complete Programming Project 7 from Chapter 5, which is an implementation of a Pizza class.
Add an Order class that contains a private vector of type Pizza.
This class represents a customer’s entire order, where the order may consist of multiple pizzas.
Include appropriate functions so that a user of the Order class can add pizzas to the order (type is deep dish, hand tossed, or pan; size is small, medium, or large; number of pepperoni or cheese toppings). You can use constants to represent the type and size.
Also write a function that outputs everything in the order along with the total price.
Write a suitable test program that adds multiple pizzas to an order(s). This is what I am not understanding.
Thanks again for your help.
Louis