Created
September 26, 2012 13:05
-
-
Save WarFox/3787915 to your computer and use it in GitHub Desktop.
Paisa To Rupee Converter in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : MainClass.cpp | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Class which runs the program, Ansi-style | |
//============================================================================= | |
#include "MainClass.h" | |
MainClass::MainClass() { | |
// TODO Auto-generated constructor stub | |
} | |
MainClass::~MainClass() { | |
// TODO Auto-generated destructor stub | |
} | |
// main function | |
int main(void) { | |
// Pointer to Paisa our converter class | |
PaisaToRupeeConverter* Converter = new PaisaToRupeeConverter(); | |
// Pointer to Currency | |
Currency* currency; | |
// Read paisa as int | |
int paisa; | |
cout << "Enter paisa (int mode): "; | |
cin >> paisa; | |
// Convert to int paisa to currency | |
currency = Converter->convert(paisa); | |
PaisaToRupeeConverter::printCurrency(currency); | |
// Read paisa as string | |
string strPaisa; | |
cout << "\nEnter paisa (string mode): "; | |
cin >> strPaisa; | |
// Convert to String paisa to currency | |
currency = Converter->convert(strPaisa); | |
PaisaToRupeeConverter::printCurrency(currency); | |
cout<<"\nDone!"; | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : MainClass.h | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Header file | |
//============================================================================= | |
#ifndef MAINCLASS_H_ | |
#define MAINCLASS_H_ | |
#include <stdlib.h> | |
#include "PaisaToRupeeConverter.cpp" | |
class MainClass { | |
public: | |
MainClass(); | |
virtual ~MainClass(); | |
}; | |
#endif /* MAINCLASS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : PaisaToRupeeConverter.cpp | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Convert paisa to rupee, Ansi-style | |
//============================================================================= | |
#include "PaisaToRupeeConverter.h" | |
// convertor function with string input | |
Currency* PaisaToRupeeConverter::convert(string strPaisa) { | |
int paisa = stringToIntConverter.convert(strPaisa); | |
StringToIntConverter* test = new StringToIntConverter(); | |
paisa = test->convert(strPaisa); | |
Currency* currency = new Currency(); | |
currency->rupee = paisa / 100; | |
currency->paisa = paisa % 100; | |
return currency; | |
} | |
// convertor function with int input | |
Currency* PaisaToRupeeConverter::convert(int paisa) { | |
Currency* currency = new Currency(); | |
currency->rupee = paisa / 100; | |
currency->paisa = paisa % 100; | |
return currency; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : PaisaToRupeeConvertor.cpp | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Convert paisa to rupee, Ansi-style | |
//============================================================================= | |
#include "PaisaToRupeeConvertor.h" | |
// convertor function with string input | |
Currency* PaisaToRupeeConvertor::convert(string strPaisa) { | |
int paisa = stringToIntConvertor.convert(strPaisa); | |
StringToIntConvertor* test = new StringToIntConvertor(); | |
paisa = test->convert(strPaisa); | |
Currency* currency = new Currency(); | |
currency->rupee = paisa / 100; | |
currency->paisa = paisa % 100; | |
return currency; | |
} | |
// convertor function with int input | |
Currency* PaisaToRupeeConvertor::convert(int paisa) { | |
Currency* currency = new Currency(); | |
currency->rupee = paisa / 100; | |
currency->paisa = paisa % 100; | |
return currency; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : PaisaToRupeeConvertor.h | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Header file | |
//============================================================================= | |
#include <iostream> | |
#include <stdlib.h> | |
#include "StringToIntConvertor.cpp" | |
#ifndef PAISATORUPEECONVERTOR_H_ | |
#define PAISATORUPEECONVERTOR_H_ | |
using namespace std; | |
/** | |
* Currency structure | |
*/ | |
struct Currency { | |
int rupee; | |
int paisa; | |
}; | |
/** | |
* Class which converts paisa to rupees and paisa. | |
* Contains overloaded function convert, | |
* one which accepts string and other accepts int argument | |
*/ | |
class PaisaToRupeeConvertor { | |
StringToIntConvertor stringToIntConvertor; | |
public: | |
PaisaToRupeeConvertor() { | |
} | |
virtual ~PaisaToRupeeConvertor() { | |
} | |
Currency* convert(string paisa); | |
Currency* convert(int paisa); | |
/** | |
* static function to print the currency | |
*/ | |
static void printCurrency(Currency* currency) { | |
cout << "That is " << currency->rupee << " rupees and " | |
<< currency->paisa << " paisa."; | |
} | |
}; | |
#endif /* PAISATORUPEECONVERTOR_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : StringToIntConverter.cpp | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Convert string to int, Ansi-style | |
//============================================================================= | |
#include "StringToIntConverter.h" | |
StringToIntConverter::StringToIntConverter() { | |
// TODO Auto-generated constructor stub | |
} | |
StringToIntConverter::~StringToIntConverter() { | |
// TODO Auto-generated destructor stub | |
} | |
/** | |
* returns the int form on given string | |
*/ | |
int StringToIntConverter::convert(std::string str) { | |
return atoi(str.c_str()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : StringToIntConverter.h | |
// Author : Deepu Mohan Puthrote | |
// Version : 1.0 | |
// Created on : 26 Sep 2012 | |
// Copyright : Apache License, Version 2.0 | |
// Description : Header file | |
//============================================================================= | |
#ifndef STRINGTOINTCONVERTER_H_ | |
#define STRINGTOINTCONVERTER_H_ | |
/** | |
* Class to convert string to int | |
*/ | |
class StringToIntConverter { | |
public: | |
StringToIntConverter(); | |
virtual ~StringToIntConverter(); | |
int convert(std::string str); | |
}; | |
#endif /* STRINGTOINTCONVERTER_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment