Answers for "enum type"

0

enum type

#ifndef ITEMTYPE_H
#define ITEMTYPE_H

#include <iostream>

class ItemType {

private:
        int value;

public:
        enum Comparison;
        ItemType(); //Default Constructor
        Comparison compareTo(ItemType item); //Compare the value of item with the current object's value and return GREATER, LESS OR EQUAL.
        int getValue() const; //Return the value instance variable
        void initialize(int num); //Initializes the data member by variable num
};
#endif
Posted by: Guest on May-22-2021
0

enum type

#include <iostream>
#include "ItemType.h"

//Enumeration
enum Comparison{GREATER, LESS, EQUAL};

//Methods
ItemType::ItemType() {
        value = 0;
}
ItemType::Comparison ItemType::compareTo(ItemType itemIn) {
        if (this->value < itemIn.getValue()) {
                return LESS;
        } else if (this->value > itemIn.getValue()) {
                return GREATER;
        } else {
                return EQUAL;
        }

}
int ItemType::getValue() const {
        return value;
}
void ItemType::initialize(int num) {
        ItemType a;
        a.value = num;
}
Posted by: Guest on May-22-2021

Browse Popular Code Answers by Language