Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GgtExercise.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 #include "ExerciseStore.h"
00007 
00013 class GgtExercise : public AbstractExercise {
00014 public:
00015 
00021     GgtExercise(string name) : AbstractExercise(name){};
00022 
00023 protected:
00024 
00031     int execute();
00032 
00037     void getInput();
00038 
00039 private:
00040 
00048     static int ggt(int a, int b);
00049 
00050     int fA;
00051     int fB;
00052 
00053 };
00054 
00059 STORE_EXERCISE(GgtExercise);
00060 
00061 void GgtExercise::getInput(){
00062     cout << "Enter first number :";
00063     cin >>  fA;
00064     cout << "Enter second number :";
00065     cin >>  fB;
00066 }
00067 
00068 int GgtExercise::execute(){
00069     cout << "  GCD(" << fA << ", " << fB << ") = "<< ggt(fA, fB) << endl;
00070     return 0;
00071 }
00072 
00073 int GgtExercise::ggt(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 Sat Oct 19 21:38:42 2002 for Exercise Framework by doxygen1.2.18