Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, one of the assignment questions is to add a Vector, This is my assignment

ID: 3573298 • Letter: H

Question

Hello, one of the assignment questions is to add a Vector, This is my assignment below. Can someone add a Vector so i can see how a Vector code looks like. thank you. this code is C++

C++

//Menu regarding Ice Cream and the various possibilities such as scoop count and toppings

#include

#include

#include

using namespace std;

enum scoopsize { kids, one, two, waffle };

string closingSentence (int bye);

int main()

{

scoopsize scoop0, scoop1, scoop2, scoop3;

scoop0 = kids;

scoop1 = one;

scoop2 = two;

scoop3 = waffle;

scoop0 = static_cast(scoop0 + 1);

scoop1 = static_cast(scoop1 + 1);

scoop2 = static_cast(scoop2 + 1);

scoop3 = static_cast(scoop3 + 1);

int OneScoop_count, TwoScoop_count, KidsScoop_count, Waffle_Count, Sprinkles_Count, Nuts_Count, Oreos_Count, WhipCream_Count,

total_icecreamcount; // Declaration of the types of scoops/cones and the different toppings

char TypeOfOrder;

double Sprinkles_Price, Nuts_Price, Oreos_Price, WhipCream_Price, sales_tax, total_bill, bill; // Declaration of the prices for each item sold as well as the salex tax, and the total bill

double ToppingsPrice[4] = { .25, .50, .75, .10 };

string Flavors[2][3] = { { "Chocolate", "Strawberry", "Vanilla" },{ "Banana", "Cherry", "Pineapple" } };

// Initialization of the prices

Sprinkles_Price = ToppingsPrice[0];

Nuts_Price = ToppingsPrice[1];

Oreos_Price = ToppingsPrice[2];

WhipCream_Price = ToppingsPrice[3];

cout << "--------------------Ice Cream Shop--------------------" << endl;

cout << "Ice Cream Sizes: " << endl;

cout << "One Scoop...........$" << scoop1 << endl;

cout << "Two Scoops..........$" << scoop2 << endl;

cout << "Kids Scoop..........$" << scoop0 << endl;

cout << "Waffle Cone.........$" << scoop3 << endl;

cout << " ";

cout << "Flavors: " << endl;

cout << " -" << Flavors[0][0] << " -" << Flavors[0][1] << " -" << Flavors[0][2] << " " << endl;

cout << " -" << Flavors[1][0] << " -" << Flavors[1][1] << " -" << Flavors[1][2] << " " << endl;

cout << " " << endl;

cout << "Toppings: " << endl;

cout << "Sprinkles...........$" << Sprinkles_Price << endl;

cout << "Nuts................$" << Nuts_Price << endl;

cout << "Oreos...............$" << Oreos_Price << endl;

cout << "Whip Cream..........$" << WhipCream_Price << endl;

cout << " ";

cout << " All Prices Include Sales Tax (8%) " << endl;

string name; // Initializing for the name

cout << "How many One Scoop cones: "; // Asking for user input for the different counts of scoops/cones

cin >> OneScoop_count;

cout << "How many Two Scoop cones: ";

cin >> TwoScoop_count;

cout << "How many Kid's scoop cones: ";

cin >> KidsScoop_count;

cout << "How many icecreams with Waffle cones: ";

cin >> Waffle_Count;

cout << "How many counts of Sprinkles: "; // Asking for user input for the different counts of toppings

cin >> Sprinkles_Count;

cout << "How many counts of Nuts: ";

cin >> Nuts_Count;

cout << "How many counts of Oreos: ";

cin >> Oreos_Count;

cout << "How many counts of WhipCream: ";

cin >> WhipCream_Count;

if (Sprinkles_Count >= 0 && Nuts_Count >= 0 && Oreos_Count >= 0 && WhipCream_Count >= 0 && OneScoop_count >= 0 && TwoScoop_count >= 0 && KidsScoop_count >= 0 && Waffle_Count >= 0)

{

bill = OneScoop_count * scoop1 + TwoScoop_count * scoop2 + KidsScoop_count * scoop0 + Waffle_Count * scoop3 + Sprinkles_Count * Sprinkles_Price + Nuts_Count * Nuts_Price + Oreos_Count * Oreos_Price + WhipCream_Count * WhipCream_Price; // the bill for the icecream

sales_tax = bill * .08;

total_bill = sales_tax + bill; // total cost including sales tax

total_icecreamcount = OneScoop_count + TwoScoop_count + KidsScoop_count + Waffle_Count; // Total count of icecreams

cout << "What is your name for your order: "; // Asking the user to input their name

cin >> name;

cout << "Is this order to go or for here? (T for to go, D for dine in)" << endl;

cin >> TypeOfOrder;

}

else

bill = OneScoop_count * scoop1 + TwoScoop_count * scoop2 + KidsScoop_count * scoop0 + Waffle_Count * scoop3

+ Sprinkles_Count * Sprinkles_Price + Nuts_Count * Nuts_Price + Oreos_Count * Oreos_Price + WhipCream_Count * WhipCream_Price;

sales_tax = bill * .08;

total_bill = sales_tax + bill;

total_icecreamcount = OneScoop_count + TwoScoop_count + KidsScoop_count + Waffle_Count;

switch (TypeOfOrder)

{

case 'T':

if (total_bill >= 0)

cout << name << "'s to go order for " << total_icecreamcount << " Icecreams totals $" << fixed << setprecision(2) << total_bill << endl;

// Shows the amount of icecreams and the total bill

else

{

cout << "Wrong input, Please make sure you order does not include negative numbers, please try again." << endl;

}

break;

case 'D':

if (total_bill >= 0)

{

cout << name << " 's dine in order for " << total_icecreamcount << " Icecreams totals $" << fixed << setprecision(2) << total_bill << endl;

} // Shows the amount of icecreams and the total bill

else

{

cout << "Wrong input, Please make sure you order does not include negative numbers, please try again." << endl;

break;

}

}

char ans;

cout << " Would you like to place another order today or would that be it?(Y/N)? ";

cout << "Answer must be a 'Y' FOR YES and a 'N' for no ";

cin >> ans;

while (ans != 'N' || ans != 'n' || ans != 'Y' || ans != 'y')

{

if (ans == 'N')

{

cout << " Thank you for your order";

string HaveANiceDay[4] = { "Have", "A", "Nice", "Day" };

for (int Filler = 1; Filler < 2; Filler++)

{

for (int Words = 0; Words <= 3; Words++)

{

cout << HaveANiceDay[(Words*Filler)] << " ";

}

}

ans = 'H';

}

if (ans == 'Y')

{

cout << " Thank you for your order";

cout << " To start your second order please restart the program" << endl;

cout << " If you would like to cancel, please type 'N'" << endl;

cin >> ans;

if (ans == 'N')

{

string HaveANiceDay[4] = { "Have", "A", "Nice", "Day" };

for (int Filler = 1; Filler < 2; Filler++)

{

for (int Words = 0; Words <= 3; Words++)

{

cout << HaveANiceDay[(Words*Filler)] << " ";

}

}

ans = 'H';

}

}

}

int bye = 0;

cout << closingSentence(0);

system("pause");

return 0;

}

string closingSentence (int bye) {

string goodbye;

goodbye = "Come back soon!";

return goodbye;

}

Explanation / Answer

Vectors in C++

vectors are basically arrays that can changes size dynamically and can be of any type.

vectors use a dynamically allocated array to store their elements.

Vector is a derived from class Template

lets try to learn vector by various examples:

#include<vector> //header file

std::vector<int > v; // declare a vector of int

or

using namespace std;

vector<char> v; //declare a vector of charactor

v.push_back(cnt); // to input a element in vector

v.size() // to return size of vector

v[0] // to use first element of vector.

v.pop_back(); // delete last element

v.resize(10); //resize the vector

v.begin() and v.end() :- return iterator to begining and end

Now you have learned the methods of vector class, take a look on this sample program for more understanding:

*** In your code you can change these two defination to vectors

double ToppingsPrice[4] = { .25, .50, .75, .10 };

vector<double> ToppingPrice[4]

string Flavors[2][3] = { { "Chocolate", "Strawberry", "Vanilla" },{ "Banana", "Cherry", "Pineapple" } };

you can now use these variables for further operations normally.