GcdExercise.cpp

Go to the documentation of this file.
00001 #include "macros.h" // needs to be declared as first entry in .cpp or .h file!
00002 #include <string>
00003 #include <iostream>
00004 using namespace std;
00005 #include "AbstractExercise.h"
00006 
00012 class GcdExercise : public AbstractExercise {
00013 public:
00014 
00020     GcdExercise(string name) : AbstractExercise(name){};
00021 
00022 protected:
00023 
00028     void execute();
00029 
00034     void getInput();
00035 
00036 private:
00037 
00045     static int gcd(int a, int b);
00046 
00047     int fA;
00048     int fB;
00049 
00050 };
00051 
00057 namespace {
00058     GcdExercise proto("GcdExercise");
00059 }
00060 
00061 
00062 void GcdExercise::getInput(){
00063     cout << "Enter first number :";
00064     cin >>  fA;
00065     cout << "Enter second number :";
00066     cin >>  fB;
00067 }
00068 
00069 void GcdExercise::execute(){
00070     cout << "  GCD(" << fA << ", " << fB << ") = "<< gcd(fA, fB) << endl;
00071 }
00072 
00073 int GcdExercise::gcd(int a, int b){
00074     while(a != b){
00075         if(a>b){
00076             a -= b;
00077         } else {
00078             b -= a;
00079         }
00080     }
00081     return a;
00082 }

Generated on Thu Jul 3 19:12:45 2008 for Exercise Framework by  doxygen 1.5.1