#include #include #include #include #include class CAT{ public: float weight() const{return weight_;} unsigned int range() const{return range_;} CAT(float weight= 1.0, unsigned int range=1); int set_weight(float); int set_range(unsigned int power); int dig(double hours); int id() const{return id_;} private: float weight_; unsigned int range_; const int id_; }; int compare(CAT,CAT); Task: Define the public function int CAT::set_range(unsigned int power) : If the value passed by power is smaller than 100 and at same time range_ is smaller or equal to 100, then range_ is set to the sum of power and 2. After this -1 is the return value of the function. Else If the value passed by power is smaller than range_ , then range_ is to be set to power times 100 and then power times -1 is the return value of the function. Else If the value passed by power is larger or equal to the value of range_ , then the function should set range_ to the sum of power and 1. After this 0 is the return value of the function.
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 <vector>
#include <sstream>
#include <exception>
class CAT{
public:
float weight() const{return weight_;}
unsigned int range() const{return range_;}
CAT(float weight= 1.0, unsigned int range=1);
int set_weight(float);
int set_range(unsigned int power);
int dig(double hours);
int id() const{return id_;}
private:
float weight_;
unsigned int range_;
const int id_;
};
int compare(CAT,CAT);
Task:
- If the value passed by power is smaller than 100 and at same time range_ is smaller or equal to 100,
then range_ is set to the sum of power and 2. After this -1 is the return value of the function. - Else If the value passed by power is smaller than range_ , then range_ is to be set to power times 100 and then power times -1 is the return value of the function.
- Else If the value passed by power is larger or equal to the value of range_ ,
then the function should set range_ to the sum of power and 1. After this 0 is the return value of the function.
Step by step
Solved in 4 steps with 2 images