online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** Name: Maria Logan File Name: main.cpp *******************************************************************************/ #include <iostream> #include <exception> #include "fractionException.h" #include "fractionType.h" using namespace std; int main() { try { fractionType<int> num1 = fractionType<int>(0, 3); fractionType<int> num2 = fractionType<int>(2, 6); fractionType<int> num3(3,0); num1.display(); cout << endl; num2.display(); cout<< endl; num3.display(); } catch(fractionException e){ cout << "Exception caught in main: " << e.what() << endl; } return 0; }
/****************************************************************************** Name: Maria Logan File Name: fractionType.h *******************************************************************************/ #pragma once #include <iostream> #include <exception> #include "fractionException.h" using namespace std; template <class T> class fractionType { private: T num, den; public: fractionType(T num1, T den1); fractionType<T> multiply(fractionType<T>& f); fractionType<T> divide(fractionType<T>& f); fractionType<T> add(fractionType<T>& f); fractionType<T> subtract(fractionType<T>& f); void display(); //void setAnswer( int answer); //int getAnswer(); }; template <class T> fractionType<T>::fractionType(T num1, T den1) { this->num = num1; if (den1 == 0) throw fractionException(); this->den = den1; } template <class T> fractionType<T> fractionType<T>::multiply(fractionType<T>& f) { return fractionType(this->num * f.num, this->den * f.den); } template <class T> fractionType<T> fractionType<T>::divide(fractionType<T>& f) { if (f.num != 0) return fractionType(this->num * f.den, this->den * f.num); else return fractionType(0, 1); } template <class T> fractionType<T> fractionType<T>::add(fractionType<T>& f) { return fractionType(this->num * f.den + this->den * f.num, this->den * f.den); } template <class T> fractionType<T> fractionType<T> ::subtract(fractionType<T>& f) { return fractionType(this->num * f.den - this->den * f.num, this->den * f.den); } template <class T> void fractionType<T>::display() { cout << num << " / " << den; }
/****************************************************************************** Name: Maria Logan File Name: fractionException.h *******************************************************************************/ #pragma once #include <iostream> #include <exception> using namespace std; class fractionException : public exception { public: const char* what() const throw () { return "Invalid fraction, denominator can't be 0"; } };

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue