online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include "account.h" #include "bank.h" int main() { Bank bank; for (auto i = 0; i < 100; i++) { auto account = bank.CreateAccount(); account->Deposit(i * 2.0); } bank.PayInterest(); return 0; }
#ifndef ACCOUNT_H_ #define ACCOUNT_H_ class Account { private: double balance_; public: Account() noexcept; double GetBalance() const noexcept; void Deposit(double amount); double Withdraw(double amount); double CalculateInterest() const noexcept; }; #endif // ACCOUNT_H_
#include "account.h" #include "logger.h" Account::Account() noexcept { balance_ = 0.0; } double Account::GetBalance() const noexcept { return balance_; } void Account::Deposit(const double amount) { balance_ += amount; Logger::Log("\nDeposit, amount: ", amount); } double Account::Withdraw(const double amount) { balance_ -= amount; Logger::Log("\nWithdraw, amount: ", amount); return amount; } double Account::CalculateInterest() const noexcept { return balance_ * 0.001; }
#ifndef BANK_H_ #define BANK_H_ #include <list> #include <memory> class Account; class Bank { private: std::list<std::shared_ptr<Account>> accounts_; public: std::shared_ptr<Account> CreateAccount(); void PayInterest(); }; #endif // BANK_H_
#include "bank.h" #include <ctime> #include "account.h" #include "logger.h" std::shared_ptr<Account> Bank::CreateAccount() { auto account = std::make_shared<Account>(); accounts_.push_back(account); Logger::Log("\nCreate account, number of accounts:", accounts_.size()); return account; } void Bank::PayInterest() { for (const auto& account : accounts_) { const auto interest = account->CalculateInterest(); account->Deposit(interest); Logger::Log("\nDeposit, balance:", account->GetBalance()); } time_t current_time; time(&current_time); const auto time_string = ctime(&current_time); if (time_string != nullptr) { Logger::Log("\nInterest paid on:", time_string); } }
#ifndef LOGGER_H_ #define LOGGER_H_ #include <string> #include <fstream> #include <utility> class Logger { private: static const std::string temp_file_name; public: template <class T> static void Log(const char* message, T&& data); }; template <class T> void Logger::Log(const char* message, T&& data) { std::ofstream outfile(temp_file_name, std::ios_base::out | std::ios_base::app); outfile << message << " " << std::forward<T>(data) << "\n"; } #endif // LOGGER_H_
#include "logger.h" const std::string Logger::temp_file_name{"c:\\temp\\logfile.txt"};

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