Question

c++ Create a Grocery list dynamically allocated object. also store pointer in to a standard vector...

c++ Create a Grocery list dynamically allocated object. also store pointer in to a standard vector

OUTPUT -

Welcome to Kroger. Place grocery items into your shopping basket by entering each product's information.
enclose string entries in quotes, separate fields with comas
CTL-Z (Windows) or CTL-D (Linux) to quit

Enter UPC, Product Brand, Product Name, and Price
Item added to shopping basket: "00072250018548", "Nature's Own", "Nature's Own Butter Buns Hotdog - 8 Ct", 10.79

Enter UPC, Product Brand, Product Name, and Price
Item added to shopping basket: "00028000517205", "Nestle", "Nestle Media Crema Table Cream", 17.97

Enter UPC, Product Brand, Product Name, and Price
Item added to shopping basket: "00034000020706", "York", "York Peppermint Patties Dark Chocolate Covered Snack Size", 12.64

Enter UPC, Product Brand, Product Name, and Price
Item added to shopping basket: "00038000570742", "Kellogg's", "Kellogg's Cereal Krave Chocolate", 18.66

Enter UPC, Product Brand, Product Name, and Price
Item added to shopping basket: "00014100072331", "Pepperidge Farm", "Pepperidge Farm Classic Cookie Favorites", 14.43

Enter UPC, Product Brand, Product Name, and Price


Here is an itemized list of the items in your shopping basket:
"00014100072331", "Pepperidge Farm", "Pepperidge Farm Classic Cookie Favorites", 14.43
"00038000570742", "Kellogg's", "Kellogg's Cereal Krave Chocolate", 18.66
"00034000020706", "York", "York Peppermint Patties Dark Chocolate Covered Snack Size", 12.64
"00028000517205", "Nestle", "Nestle Media Crema Table Cream", 17.97
"00072250018548", "Nature's Own", "Nature's Own Butter Buns Hotdog - 8 Ct", 10.79

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <iostream>
#include <string>
#include <vector>
#include <signal.h>
#include<sstream>

using namespace std;

int flag=1;

class item
{
private:
string UPC;
string brand;
string name;
string price;

public:
item(string UPC_,string brand_,string name_,string price_)
{
UPC=UPC_;
brand=brand_;
name=name_;
price=price_;
}
string getUPC()
{
return UPC;
}
string getName()
{
return name;
}
string getBrand()
{
return brand;
}
string getPrice()
{
return price;
}
};

void sighandler(int sig_num)
{
signal(SIGTSTP, sighandler);
cout<<"\nThankyou\n";
flag=0;
return;
}

int main()
{
vector<item> cartList;
string data,subdata1,subdata2,subdata3,subdata4;
signal(SIGTSTP, sighandler);
cout<<"\nWelcome to Kroger. Place grocery items into your shopping basket by entering each product's information.";
cout<<"\nenclose string entriesin quotes, seperat fields with comas.";
cout<<"\nCTL-Z(WINDOWS) or CTL-D(LINUX) to Quit";
while(flag==1)
{
cout<<"\nEnter UPC, Product Brand, Product Name, and Price\n";
cin>>data;

stringstream s_stream(data);

getline(s_stream, subdata1, ',');
getline(s_stream, subdata2, ',');
getline(s_stream, subdata3, ',');
getline(s_stream, subdata4, ',');

item obj(subdata1,subdata2,subdata3,subdata4);

cartList.push_back(obj);
cout<<"\nItem added to shopping basket:"<<data;
}
cout<<"\nHere is the itamized list of the items in the your shopping basket.";
for(auto i=cartList.begin();i!=cartList.end();++i)
{
if(i+1!=cartList.end())
{
cout<<"\n \""<<i->getUPC()<<"\",\""<<i->getBrand()<<"\",\""<<i->getName()<<"\", and "<<i->price;
}
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
c++ Create a Grocery list dynamically allocated object. also store pointer in to a standard vector...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ Create a Grocery list dynamically allocated object. also store pointer in to a standard vector...

    c++ Create a Grocery list dynamically allocated object. also store pointer in to a standard vector //GroceryItem.cpp #pragma once // include guard #include <string> #include <iostream> class GroceryItem { // Insertion and Extraction Operators friend std::ostream & operator<<( std::ostream & stream, const GroceryItem & groceryItem ); friend std::istream & operator>>( std::istream & stream, GroceryItem & groceryItem ); // Relational Operators friend bool operator==( const GroceryItem & lhs, const GroceryItem & rhs ); friend bool operator< ( const GroceryItem & lhs,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT