// Prog: tribool_class_template.cpp // Author: ... // implements three-valued logic as a class #include class Tribool { // ... (private: or public: , which one?) // POST: *this is initialized with value 'unknown' // ... (default-constructor) // POST: *this is initialized as true (if b == 1), // as false (if b == 0) or as unknown (else) // ... (constructor for int --> Tribool) // POST: *this is initialized as true if b is true, or as // false if b is false // Note: this constructor is not necessarily needed if the // constructor for int --> Tribool is suitably implemented // and the internal representation of the three-valued logic // is suitably chosen. // ... (constructor for bool --> Tribool) // POST: returns true iff value_ is boolean (either true or false) // ... (is_bool) // POST: returns *this AND y // ... (a helper function which executes x AND y (for x of type Tribool)) // (Note: you don't have to implement this member if you see // other ways to implement operator&& such that it works when it is // called with two arguments of type Tribool as well as with one // argument of type bool and the other of type Tribool.) // POST: returns *this OR y // ... (a helper function which executes x OR y (for x of type Tribool)) // (Note: you don't have to implement this member if you see // other ways to implement operator|| such that it works when it is // called with two arguments of type Tribool as well as with one // argument of type bool and the other of type Tribool.) // POST: writes the value of *this to o // ... (print-function; needed for operator<< to access value) // ... (private: or public: , which one?) // ... (represent the value here) }; // POST: returns x AND y // ... (operator&&) // POST: returns x OR y // ... (operator||) // POST: Tribool value is written to o // ... (operator<<) int main() { // print 3 x 3 truth table for AND const Tribool t = 1, f = 0, u = 800; // true, false, and unknown std::cout << (f && f) << " " << (f && u) << " " << (f && t) << "\n" << (u && f) << " " << (u && u) << " " << (u && t) << "\n" << (t && f) << " " << (t && u) << " " << (t && t) << "\n\n"; // print 3 x 3 truth table for OR std::cout << (f || f) << " " << (f || u) << " " << (f || t) << "\n" << (u || f) << " " << (u || u) << " " << (u || t) << "\n" << (t || f) << " " << (t || u) << " " << (t || t) << "\n\n"; // the operators also work for bools: const bool b = true; std::cout << (b || u) << " " << (u && b) << "\n"; std::cout << (b || f) << " " << (f && b) << "\n"; return 0; }