Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctime>
- using namespace std;
- typedef unsigned int uint;
- struct Wallet {
- double fiatMoney;
- char owner[256];
- unsigned id;
- };
- struct Transaction {
- unsigned senderId;
- unsigned receiverId;
- double fmiCoins;
- long long time;
- };
- struct Order {
- enum Type { SELL, BUY } type;
- unsigned walletId;
- double fmiCoins;
- };
- bool commandCompare(const char* myCommand, const char* command)
- {
- while (*myCommand)
- {
- if (*myCommand != *command)
- {
- return false;
- }
- myCommand++;
- command++;
- }
- return true;
- }
- const char *walletsDirectory = "wallets.dat";
- const char *transactionsDirectory = "transactions.dat";
- const char *ordersDirectory = "orders.dat";
- const char *addwallet = "add-wallet";
- const char *makeorder = "make-order";
- void addWallet()
- {
- fstream myWalletFile;
- fstream myTransactionsFile;
- Wallet user;
- Transaction bonusCoins;
- uint currentID = 0;
- myWalletFile.open(walletsDirectory, ios::in | ios::binary);
- if (!myWalletFile)
- {
- myWalletFile.open(walletsDirectory, ios::out | ios::binary);
- myWalletFile.close();
- }
- myWalletFile.open(walletsDirectory, ios::in | ios::binary);
- myWalletFile.seekg(0, ios::end);
- uint fileSize = myWalletFile.tellg();
- if (fileSize)
- {
- myWalletFile.seekg(-4, ios::end);
- myWalletFile.read((char *)¤tID, sizeof(currentID));
- }
- user.id = currentID + 1;
- myWalletFile.close();
- myWalletFile.open(walletsDirectory, ios::app | ios::binary);
- if (!myWalletFile)
- {
- cout << "qweq";
- }
- cin >> user.fiatMoney;
- cin.clear();
- cin.ignore(1000, '\n');
- cin.getline(user.owner, 256);
- myWalletFile.write((const char*)&user, sizeof(user));
- myWalletFile.close();
- bonusCoins.fmiCoins = user.fiatMoney / 375;
- bonusCoins.receiverId = user.id;
- bonusCoins.senderId = UINT_MAX;
- bonusCoins.time = time(NULL);
- myTransactionsFile.open(transactionsDirectory, ios::out | ios::app);
- myTransactionsFile.write((const char*)&bonusCoins, sizeof(bonusCoins));
- myTransactionsFile.close();
- }
- void makeOrder(Transaction receiverid, Transaction senderid,)
- {
- }
- int main()
- {
- char myCommand[255];
- for (;;)
- {
- cin >> myCommand;
- if (commandCompare(myCommand, addwallet))
- {
- addWallet();
- }
- else
- {
- cout << "Wrong command used. Try again." << endl;
- continue;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement