#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); Task: Define the public function int Snack::set_price(float price) : If the value passed by price is smaller than 0 the function should return -2. If the value of price is greater or equal to 0, proceed as follows: If the value passed by price is smaller than the current value of price_, the function should assign price to price_ and return -1. If the value passed by price is larger than the current value of price_, the function should assign price to price_ and return 1. If price is equal to price_, the function should assign price to price_ and return 0.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
#include <string>
#include <iostream>
#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<Snack>&,bool);
Task:
- If the value passed by price is smaller than the current value of price_, the function should assign price to price_ and return -1.
- If the value passed by price is larger than the current value of price_, the function should assign price to price_ and return 1.
- If price is equal to price_, the function should assign price to price_ and return 0.
Step by step
Solved in 4 steps with 1 images