Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <ctime>
  4. using namespace std;
  5. typedef unsigned int uint;
  6.  
  7. struct Wallet {
  8. double fiatMoney;
  9. char owner[256];
  10. unsigned id;
  11. };
  12.  
  13. struct Transaction {
  14. unsigned senderId;
  15. unsigned receiverId;
  16. double fmiCoins;
  17. long long time;
  18. };
  19.  
  20. struct Order {
  21. enum Type { SELL, BUY } type;
  22. unsigned walletId;
  23. double fmiCoins;
  24. };
  25.  
  26. bool commandCompare(const char* myCommand, const char* command)
  27. {
  28. while (*myCommand)
  29. {
  30. if (*myCommand != *command)
  31. {
  32. return false;
  33. }
  34. myCommand++;
  35. command++;
  36. }
  37. return true;
  38. }
  39.  
  40. const char *walletsDirectory = "wallets.dat";
  41. const char *transactionsDirectory = "transactions.dat";
  42. const char *ordersDirectory = "orders.dat";
  43. const char *addwallet = "add-wallet";
  44. const char *makeorder = "make-order";
  45.  
  46. void addWallet()
  47. {
  48. fstream myWalletFile;
  49. fstream myTransactionsFile;
  50. Wallet user;
  51. Transaction bonusCoins;
  52. uint currentID = 0;
  53.  
  54. myWalletFile.open(walletsDirectory, ios::in | ios::binary);
  55. if (!myWalletFile)
  56. {
  57. myWalletFile.open(walletsDirectory, ios::out | ios::binary);
  58. myWalletFile.close();
  59. }
  60.  
  61. myWalletFile.open(walletsDirectory, ios::in | ios::binary);
  62. myWalletFile.seekg(0, ios::end);
  63. uint fileSize = myWalletFile.tellg();
  64. if (fileSize)
  65. {
  66. myWalletFile.seekg(-4, ios::end);
  67. myWalletFile.read((char *)&currentID, sizeof(currentID));
  68. }
  69. user.id = currentID + 1;
  70. myWalletFile.close();
  71.  
  72. myWalletFile.open(walletsDirectory, ios::app | ios::binary);
  73. if (!myWalletFile)
  74. {
  75. cout << "qweq";
  76. }
  77. cin >> user.fiatMoney;
  78. cin.clear();
  79. cin.ignore(1000, '\n');
  80. cin.getline(user.owner, 256);
  81. myWalletFile.write((const char*)&user, sizeof(user));
  82. myWalletFile.close();
  83.  
  84. bonusCoins.fmiCoins = user.fiatMoney / 375;
  85. bonusCoins.receiverId = user.id;
  86. bonusCoins.senderId = UINT_MAX;
  87. bonusCoins.time = time(NULL);
  88.  
  89. myTransactionsFile.open(transactionsDirectory, ios::out | ios::app);
  90. myTransactionsFile.write((const char*)&bonusCoins, sizeof(bonusCoins));
  91. myTransactionsFile.close();
  92. }
  93.  
  94. void makeOrder(Transaction receiverid, Transaction senderid,)
  95. {
  96.  
  97. }
  98.  
  99. int main()
  100. {
  101. char myCommand[255];
  102. for (;;)
  103. {
  104. cin >> myCommand;
  105. if (commandCompare(myCommand, addwallet))
  106. {
  107. addWallet();
  108. }
  109. else
  110. {
  111. cout << "Wrong command used. Try again." << endl;
  112. continue;
  113. }
  114. }
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement