snack.h #include #include #include class Snack{ public: Snack(std::string, float, bool); int set_price(float); void set_expired(bool); void set_name(std::string); std::string name() const{return name_;} float price() const{return price_;} bool expired() const{return expr_;} int how_many_for_ten(); private: std::string name_; float price_; bool expr_; }; void SortByPrice(std::vector&,bool); main.cpp #include using namespace std; #include "snack.h" int main(){    Snack snicker=Snack("Snickers",2.0,false);    std::cout< snack_list;    snack_list.push_back(snicker);    snack_list.push_back(twix);    try {            snicker.set_name("Rider");    }    catch (std::exception &e)    {            std::cout << e.what() << std::endl;    }    try {        Snack newsnack=Snack("",2.0,false);    }    catch (std::exception &e)    {            std::cout << e.what() << std::endl;    }    std::cout<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

snack.h

#include <string>
#include <iostream>
#include <vector>
class Snack{
public:
Snack(std::string, float, bool);
int set_price(float);
void set_expired(bool);
void set_name(std::string);
std::string name() const{return name_;}
float price() const{return price_;}
bool expired() const{return expr_;}
int how_many_for_ten();
private:
std::string name_;
float price_;
bool expr_;
};
void SortByPrice(std::vector<Snack>&,bool);

main.cpp

#include <iostream>
using namespace std;

#include "snack.h"

int main(){
   Snack snicker=Snack("Snickers",2.0,false);
   std::cout<<snicker.name()<<" "<<snicker.price()<<" "<<snicker.expired()<<std::endl;
   Snack twix=Snack("Twix",3.0,false);
   std::cout<<twix.name()<<" "<<twix.price()<<" "<<twix.expired()<<std::endl;
   Snack mars=Snack("Mars",1.5,false);
   std::cout<<mars.name()<<" "<<mars.price()<<" "<<mars.expired()<<std::endl;
   Snack oreo=Snack("Oreo",-1.5,false);
   std::cout<<oreo.name()<<" "<<oreo.price()<<" "<<oreo.expired()<<std::endl;
   std::vector<Snack> snack_list;
   snack_list.push_back(snicker);
   snack_list.push_back(twix);
   try {
           snicker.set_name("Rider");
   }
   catch (std::exception &e)
   {
           std::cout << e.what() << std::endl;
   }
   try {
       Snack newsnack=Snack("",2.0,false);
   }
   catch (std::exception &e)
   {
           std::cout << e.what() << std::endl;
   }
   std::cout<<mars.set_price(-1.0)<<" "<<mars.price()<<std::endl;
   std::cout<<mars.set_price(1.5)<<" "<<mars.price()<<std::endl;
   std::cout<<mars.set_price(1.0)<<" "<<mars.price()<<std::endl;
   std::cout<<mars.set_price(1.5)<<" "<<mars.price()<<std::endl;
   mars.set_expired(true);std::cout<<mars.expired()<<std::endl;
   snack_list.push_back(mars);
   snack_list.push_back(oreo);
   SortByPrice(snack_list,1);
   for(int i=0;i<snack_list.size();i++){
       std::cout<<snack_list.at(i).name()<<" "<<snack_list.at(i).price()<<" "<<snack_list.at(i).expired()<<", ";
   }
   std::cout<<std::endl;
   SortByPrice(snack_list,false);
   for(int i=0;i<snack_list.size();i++){
       std::cout<<snack_list.at(i).name()<<" "<<snack_list.at(i).price()<<" "<<snack_list.at(i).expired()<<", ";
   }
   std::cout<<std::endl;
   double change=0.0;
   std::cout<<mars.how_many_for_ten(change)<<" "<<change<<std::endl;
   return 0;
}

Task:

Implement the function int Snack::how_many_for_ten(double &change) const :
It should return the amount of Snacks you can buy for 10.00 Euro, however, rounding should not be applied. So if your calculation returns a value of 1.3, the function should return 1.  Using the reference variable change the money that remains from 10 Euro when the calculated amount of Snack is bought should be stored.
Expert Solution
steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education