🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

This project does not allow real trading but simulates the process.
Controls the program flow.
Stock.h
, Stock.cpp
Portfolio.h
, Portfolio.cpp
Market.h
, Market.cpp
Utils.h
, Utils.cpp
Represents a stock with attributes like name, price, etc.
#ifndef STOCK_H
#define STOCK_H
#include <string>
class Stock {
private:
std::string name;
double price;
public:
Stock(const std::string &name, double initialPrice);
void updatePrice();
double getPrice() const;
std::string getName() const;
};
#endif // STOCK_H
Manages stock holdings.
#include <string>
#include <map>
class Portfolio {
private:
std::map<std::string, int> holdings; // Stock name -> Quantity
double balance;
public:
Portfolio(double initialBalance);
bool buyStock(const std::string &stockName, int quantity, double stockPrice);
bool sellStock(const std::string &stockName, int quantity, double stockPrice);
void displayPortfolio() const;
double getBalance() const;
};
#endif // PORTFOLIO_H
#include "portfolio.h"
#include <iostream>
#include <iomanip>
Portfolio::Portfolio(double initialBalance) : balance(initialBalance) {}
bool Portfolio::buyStock(const std::string &stockName, int quantity, double stockPrice) {
double cost = quantity * stockPrice;
if (cost > balance) {
std::cout << "Insufficient balance!\n";
return false;
}
balance -= cost;
holdings[stockName] += quantity;
return true;
}
bool Portfolio::sellStock(const std::string &stockName, int quantity, double stockPrice) {
if (holdings.find(stockName) == holdings.end() || holdings[stockName] < quantity) {
std::cout << "Insufficient stock quantity!\n";
return false;
}
balance += quantity * stockPrice;
holdings[stockName] -= quantity;
if (holdings[stockName] == 0) {
holdings.erase(stockName);
}
return true;
}
Handles stock price updates.
#ifndef MARKET_H
#define MARKET_H
#include <vector>
#include "Stock.h"
class Market {
private:
std::vector<Stock> stocks;
public:
void addStock(const Stock &stock);
void updateMarket();
void displayMarket() const;
};
#endif // MARKET_H
Required Tools:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget>
#include <QString>
#include <vector>
#include "Stock.h"
#include "portfolio.h"
#include "Market.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_buyButton_clicked();
void on_sellButton_clicked();
void updatePrices();
private:
Ui::MainWindow *ui;
Market market;
Portfolio portfolio;
void updateStockTable();
void updatePortfolioTable();
};
#endif // MAINWINDOW_H
A university finance course uses this software to teach students trading concepts. Students practice portfolio tracking, stock transactions, and price analysis in a simulated environment with fluctuating stock prices.
Advantages:
A fintech startup uses this software to simulate and validate trading strategies such as "buy low, sell high" using historical data generated by Market.cpp
.
Advantages:
Retail investors use the software to simulate investment scenarios, such as investing $400 in AAPL and MSFT, and tracking hypothetical earnings.
Advantages:
A brokerage firm extends the project with a Qt GUI and real-world price updates, allowing new customers to simulate trades.
Advantages:
A coding competition required participants to build a trading bot. Developers connected the Portfolio
class to an API fetching live stock prices, optimizing virtual profits.
Advantages:
A bank modified the software for employee training, introducing a collaborative trading challenge.
Advantages:
This project provides an excellent learning experience in trading concepts, algorithmic trading, and GUI development using C++ and Qt.
Comments
Post a Comment