Skip to content

Instantly share code, notes, and snippets.

@DragonOsman
Last active April 21, 2018 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DragonOsman/5475d9f9b6fc8c379eba77a504b71bcf to your computer and use it in GitHub Desktop.
Save DragonOsman/5475d9f9b6fc8c379eba77a504b71bcf to your computer and use it in GitHub Desktop.
// Osman Zakir
// 4 / 4 / 2018
// currency_converter_app main.cpp
// This is a currency converter web application written in Wt. The GUI is a Google Map with an info window that displays a form
// The form takes the user's input for what currencies to convert to and from, respectively, and the amount to convert. The form submits
// to the executable made by this C++ code file
#include <Wt/WApplication.h>
#include <Wt/WServer.h>
#include <Wt/Http/Client.h>
#include <Wt/Http/Request.h>
#include <Wt/Http/Response.h>
#include <Wt/Json/Serializer.h>
#include <Wt/Json/Parser.h>
#include <Wt/Json/Array.h>
#include <Wt/Json/Object.h>
#include <Wt/Json/Value.h>
#include <Wt/WString.h>
#include <Wt/WEnvironment.h>
#include <Wt/WTemplate.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WJavaScript.h>
#include <Wt/Utils.h>
class CurrencyConverterApp : public Wt::WApplication
{
public:
CurrencyConverterApp(const Wt::WEnvironment &env);
private:
double convert(const double amount, const std::string &to_currency);
};
int main(int argc, char *argv[])
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {
return std::make_unique<CurrencyConverterApp>(env);
});
}
CurrencyConverterApp::CurrencyConverterApp(const Wt::WEnvironment &env)
: Wt::WApplication{ env }
{
std::string key;
bool api_key = readConfigurationProperty("google_api_key", key);
std::string urlencode_key = Wt::Utils::urlEncode(key);
auto t = root()->addNew<Wt::WTemplate>();
t->setTemplateText(
"<div id=\"map\"></div>"
"<script src=\"resources/scripts.js\" type=\"text/javascript\"></script>"
"<script async defer src=\"https://maps.googleapis.com/maps/api/js?key=${urlencode_key}&callback=initMap\"></script>",
Wt::TextFormat::UnsafeXHTML);
t->bindString("urlencode_key", urlencode_key);
setTitle("DragonOsman Currency Converter");
}
double CurrencyConverterApp::convert(const double amount, const std::string &to_currency)
{
// TODO: Try to match passed in to_currency with array of supported currencies
// and do the conversion for the currency that checks out. Return the result.
return 0.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment