Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.47 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstring>
  3. #include<fstream>
  4. #include<ctime>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. long long getTimeInSeconds()
  10. {
  11. time_t now = time(0);
  12.  
  13. return now;
  14. }
  15. double getInFMICounts(double fiatMoney)
  16. {
  17. return fiatMoney/375;
  18. }
  19.  
  20.  
  21. struct Transaction {
  22. long long time;
  23. unsigned senderId;
  24. unsigned receiverId;
  25. double fmiCoins;
  26. public:
  27. Transaction()
  28. {
  29. this->time = 0;
  30. this->senderId = 0;
  31. this->receiverId = 0;
  32. this->fmiCoins = 0;
  33.  
  34. }
  35. Transaction(unsigned _senderId,unsigned _receiverId,double _fmiCoins)
  36. {
  37. this->time = getTimeInSeconds();
  38. this->senderId = _senderId;
  39. this->receiverId = _receiverId;
  40. this->fmiCoins = _fmiCoins;
  41.  
  42. }
  43. void print()const
  44. {
  45. cout<<"Transaction:"<<time<<" "<<senderId<<" "<<receiverId<<" "<<fmiCoins<<endl;
  46. }
  47. };
  48.  
  49.  
  50. struct Wallet {
  51. private:
  52. char owner[256];
  53. unsigned id;
  54. double fiatMoney;
  55. Transaction t;
  56. public:
  57. Wallet()
  58. {
  59. strcpy(this->owner," ");
  60. this->id=0;
  61. this->fiatMoney=0;
  62. }
  63. Wallet(const char* _owner ,double _fiatMoney,unsigned int _id)
  64. {
  65. strcpy(this->owner,_owner);
  66. this->id=_id;
  67. this->fiatMoney=_fiatMoney;
  68.  
  69. Transaction t(id,4294967295 ,getInFMICounts(fiatMoney));
  70. fstream file;
  71. file.open("transactions.dat",ios::binary | ios::out | ios::app);
  72. file.seekp(0,ios::beg);
  73. file.write((const char*)(&t),sizeof(Transaction));
  74. file.close();
  75. }
  76.  
  77.  
  78. void print()const
  79. {
  80. cout<<this->owner<<" "<<this->id<<" "<<this->fiatMoney<<endl;
  81. }
  82. const char* getOwner()const
  83. {
  84. return owner;
  85. }
  86. unsigned int getId()const
  87. {
  88. return id;
  89. }
  90. double getFiatMoney()const
  91. {
  92. return fiatMoney;
  93. }
  94. void setOwner(const char* newOwner)
  95. {
  96. strcpy(owner,newOwner);
  97.  
  98. }
  99. void setId(unsigned int newId)
  100. {
  101. id=newId;
  102. }
  103. void setFiatMoney(double newFiatMoney)
  104. {
  105. fiatMoney=newFiatMoney;
  106. }
  107.  
  108. };
  109.  
  110. int lastId()
  111. {
  112. fstream file;
  113.  
  114. file.open("wallet.dat", ios::binary | ios::in);
  115.  
  116.  
  117.  
  118. file.seekp(0, ios::end);
  119. streampos fileSize = file.tellp();
  120. file.seekp(0, ios::beg);
  121.  
  122. int countOfWalletsInFile = fileSize / sizeof(Wallet);
  123. file.close();
  124. if(countOfWalletsInFile<4294967296)
  125. {
  126.  
  127. return countOfWalletsInFile;
  128.  
  129. }
  130.  
  131.  
  132. }
  133.  
  134.  
  135. /*bool SearchingForWallet(unsigned int id)
  136. {
  137. fstream file;
  138.  
  139. file.open("wallet.dat", ios::binary | ios::in);
  140.  
  141.  
  142.  
  143. file.seekp(0, ios::end);
  144. streampos fileSize = file.tellp();
  145. file.seekp(0, ios::beg);
  146.  
  147. streampos countOfWalletsInFile = fileSize / sizeof(Wallet);
  148. file.close();
  149.  
  150.  
  151. file.open("wallet.dat", ios::binary | ios::in);
  152.  
  153. Wallet wallFromFile;
  154. Wallet* wallets = new Wallet[countOfWalletsInFile];
  155.  
  156. int wallCount = 0;
  157.  
  158. while (file.read((char*)&wallFromFile, sizeof(Wallet)))
  159. {
  160. wallets[wallCount] = wallFromFile;
  161. wallCount++;
  162. }
  163.  
  164. file.close();
  165.  
  166. for (int i = 0; i < countOfWalletsInFile; i++)
  167. {
  168. if(wallets[i].getId()==id)
  169. {
  170. return true;
  171. break;
  172. }
  173. else
  174. {
  175. return false;
  176. }
  177. }
  178.  
  179. delete[] wallets;
  180.  
  181.  
  182. }*/
  183.  
  184. void walletInfo(unsigned walletID)
  185. {
  186. fstream file;
  187.  
  188. file.open("wallet.dat", ios::binary | ios::in);
  189.  
  190. if (!file)
  191. {
  192. cout << "Error\n";
  193. }
  194.  
  195. file.seekp(0, ios::end);
  196. streampos fileSize = file.tellp();
  197. file.seekp(0, ios::beg);
  198.  
  199. streampos countOfWalletsInFile = fileSize / sizeof(Wallet);
  200. file.close();
  201.  
  202.  
  203. file.open("wallet.dat", ios::binary | ios::in);
  204.  
  205. Wallet wallFromFile;
  206. Wallet* wallets = new Wallet[countOfWalletsInFile];
  207.  
  208. int wallCount = 0;
  209.  
  210. while (file.read((char*)&wallFromFile, sizeof(Wallet)))
  211. {
  212. wallets[wallCount] = wallFromFile;
  213. wallCount++;
  214. }
  215.  
  216. file.close();
  217.  
  218. for (int i = 0; i < countOfWalletsInFile; i++)
  219. {
  220. if(wallets[i].getId()==walletID)
  221. {
  222. wallets[i].print();
  223. }
  224.  
  225. }
  226.  
  227. delete[] wallets;
  228.  
  229. }
  230. class Wallets
  231. {
  232. private:
  233. Wallet* wallets;
  234. size_t size;
  235. size_t capacity;
  236. void copy(const Wallets& other)
  237. {
  238. this->capacity = other.capacity;
  239. this->size = other.size;
  240. this->wallets = new Wallet[this->capacity];
  241. for(size_t i = 0; i < this->size; i++)
  242. {
  243. this->wallets[i] = other.wallets[i];
  244. }
  245. }
  246. void erase()
  247. {
  248. delete [] this->wallets;
  249. }
  250. void resize()
  251. {
  252. this->capacity *= 2;
  253. Wallet* newWallet = new Wallet[this->capacity];
  254. for(size_t i = 0; i < this->size; i++)
  255. {
  256. newWallet[i] = wallets[i];
  257. }
  258. this->erase();
  259. wallets = newWallet;
  260. }
  261.  
  262. public:
  263. Wallets()
  264. {
  265. this->capacity = 8;
  266. this->size = 0;
  267. this->wallets = new Wallet[this->capacity];
  268. }
  269. Wallets(const Wallets& other)
  270. {
  271. this->copy(other);
  272. }
  273. Wallets& operator=(const Wallets& other)
  274. {
  275. if(this != &other)
  276. {
  277. this->erase();
  278. this->copy(other);
  279. }
  280.  
  281. return *this;
  282. }
  283. ~Wallets()
  284. {
  285. this->erase();
  286. }
  287.  
  288. void addWallet(const Wallet& wallet)
  289. {
  290. if(this->size >= this->capacity)
  291. {
  292. this->resize();
  293. }
  294. this->wallets[this->size++] = wallet;
  295. }
  296.  
  297. void showWallets() const
  298. {
  299. for(size_t i = 0; i < this->size; i++)
  300. {
  301. this->wallets[i].print();
  302. }
  303. }
  304. void setFiatMoneyinWall(unsigned int id,double money)
  305. {
  306. for(int i = 0;i<size;i++)
  307. {
  308. if(wallets[i].getId()==id)
  309. {
  310. wallets[i].setFiatMoney(money);
  311. }
  312. }
  313. }
  314. void sortWaallets()
  315. {
  316. for(size_t i = 0; i < this->size - 1; i++)
  317. {
  318. for(size_t j = 0; j < this->size - 1; j++)
  319. {
  320. if(this->wallets[j].getFiatMoney() < this->wallets[j + 1].getFiatMoney())
  321. {
  322. swap(this->wallets[j], this->wallets[j+1]);
  323. }
  324. }
  325. }
  326.  
  327. }
  328. void show10()const
  329. {
  330. for(size_t i = 0; i < 10; i++)
  331. {
  332. this->wallets[i].print();
  333. }
  334. }
  335. /*void WalletInfo(unsigned ID)
  336. {
  337. for(size_t i =0;i<this->size;i++)
  338. {
  339. if(ID==wallets[i].fiatMoney)
  340. {
  341. this->wallets[i].print();
  342. }
  343. }
  344. }*/
  345. };
  346.  
  347.  
  348. void RichestWallets()//===
  349. {
  350. fstream file;
  351.  
  352. file.open("wallet.dat", ios::binary | ios::in);
  353.  
  354. file.seekp(0, ios::end);
  355. streampos fileSize = file.tellp();
  356. file.seekp(0, ios::beg);
  357.  
  358. streampos countOfWalletsInFile = fileSize / sizeof(Wallet);
  359. file.close();
  360.  
  361.  
  362. file.open("wallet.dat", ios::binary | ios::in);
  363.  
  364. Wallet wallFromFile;
  365. Wallet* wallets = new Wallet[countOfWalletsInFile];
  366.  
  367. int wallCount = 0;
  368.  
  369. while (file.read((char*)&wallFromFile, sizeof(Wallet)))
  370. {
  371. wallets[wallCount] = wallFromFile;
  372. wallCount++;
  373. }
  374.  
  375. file.close();
  376. Wallets w;
  377. for(size_t i = 0 ; i < countOfWalletsInFile;i++)
  378. {
  379. w.addWallet(wallets[i]);
  380. }
  381. w.sortWaallets();
  382. if(countOfWalletsInFile>=10)
  383. {
  384. w.show10();
  385. }
  386. else
  387. {
  388. w.showWallets();
  389. }
  390. delete[] wallets;
  391. }
  392.  
  393.  
  394.  
  395. bool enoughMoney(unsigned int id,double coins)
  396. {
  397. fstream file;
  398.  
  399. file.open("wallet.dat", ios::binary | ios::in);
  400.  
  401.  
  402.  
  403. file.seekp(0, ios::end);
  404. streampos fileSize = file.tellp();
  405. file.seekp(0, ios::beg);
  406.  
  407. streampos countOfWalletsInFile = fileSize / sizeof(Wallet);
  408. file.close();
  409.  
  410.  
  411. file.open("wallet.dat", ios::binary | ios::in);
  412.  
  413. Wallet wallFromFile;
  414. Wallet* wallets = new Wallet[countOfWalletsInFile];
  415.  
  416. int wallCount = 0;
  417.  
  418. while (file.read((char*)&wallFromFile, sizeof(Wallet)))
  419. {
  420. wallets[wallCount] = wallFromFile;
  421. wallCount++;
  422. }
  423.  
  424. file.close();
  425.  
  426. for(size_t i = 0 ; i < countOfWalletsInFile;i++)
  427. {
  428. if(wallets[i].getId()==id)
  429. {
  430. if(wallets[i].getFiatMoney()>=coins*375)
  431. {
  432. return true;
  433. }
  434. else return false;
  435. }
  436. }
  437. delete[] wallets;
  438.  
  439. }
  440.  
  441.  
  442. struct Order {
  443.  
  444. enum Type { SELL, BUY } type;
  445. unsigned walletId;
  446. double fmiCoins;
  447. Type t;
  448. Order()
  449. {
  450. this->walletId=0;
  451. this->fmiCoins=0;
  452. }
  453. Order(Type _t,unsigned _walletId,double _fmiCoins)
  454. {
  455.  
  456. this->t=_t;
  457. this->walletId=_walletId;
  458. this->fmiCoins=_fmiCoins;
  459.  
  460.  
  461.  
  462. }
  463. unsigned int getWalletId()const
  464. {
  465. return walletId;
  466. }
  467. double getfmiCoins()
  468. {
  469. return fmiCoins;
  470. }
  471. Type getType()
  472. {
  473. return t;
  474. }
  475. void setWalletId(unsigned NEWwalletId)
  476. {
  477. this->walletId=NEWwalletId;
  478. }
  479. void setFMICoins(double NEWfmiCoins)
  480. {
  481. this->fmiCoins=NEWfmiCoins;
  482. }
  483. void print()const
  484. {
  485. if(t==Type(0)){
  486. cout<<"SELL Wallet ID:"<<walletId<<" Fmi coins:"<<fmiCoins<<endl;
  487. }
  488. else if(t==Type(1))
  489. {
  490. cout<<"BUY Wallet ID:"<<walletId<<" Fmi coins:"<<fmiCoins<<endl;
  491. }
  492. }
  493. };
  494.  
  495.  
  496. class Orders
  497. {
  498. private:
  499. Order* orders;
  500. size_t size;
  501. size_t capacity;
  502. void copy(const Orders& other)
  503. {
  504. this->capacity = other.capacity;
  505. this->size = other.size;
  506. this->orders = new Order[this->capacity];
  507. for(size_t i = 0; i < this->size; i++)
  508. {
  509. this->orders[i] = other.orders[i];
  510. }
  511. }
  512. void erase()
  513. {
  514. delete [] this->orders;
  515. }
  516. void resize()
  517. {
  518. this->capacity *= 2;
  519. Order* newOrder = new Order[this->capacity];
  520. for(size_t i = 0; i < this->size; i++)
  521. {
  522. newOrder[i] = orders[i];
  523. }
  524. this->erase();
  525. orders = newOrder;
  526. }
  527.  
  528. public:
  529. Orders()
  530. {
  531. this->capacity = 8;
  532. this->size = 0;
  533. this->orders = new Order[this->capacity];
  534. }
  535. Orders(const Orders& other)
  536. {
  537. this->copy(other);
  538. }
  539. Orders& operator=(const Orders& other)
  540. {
  541. if(this != &other)
  542. {
  543. this->erase();
  544. this->copy(other);
  545. }
  546.  
  547. return *this;
  548. }
  549. ~Orders()
  550. {
  551. this->erase();
  552. }
  553.  
  554. void addOrder(const Order& order)
  555. {
  556. // unsigned int ID = order.getWalletId();
  557. //if(SearchingForWallet(ID))
  558. //{
  559.  
  560. if(this->size >= this->capacity)
  561. {
  562. this->resize();
  563. }
  564. this->orders[this->size++] = order;
  565. //}
  566. }
  567.  
  568. void showOrders() const
  569. {
  570. for(size_t i = 0; i < this->size; i++)
  571. {
  572. this->orders[i].print();
  573. }
  574. }
  575. /*Orders& orderTran(Order& selling,Order& buying)
  576. {
  577. double moneyS = selling.getfmiCoins();
  578. double moneyB = buying.getfmiCoins();
  579.  
  580. if(moneyS < moneyB && moneyS != 0)
  581. {
  582. moneyB = moneyB - moneyS;
  583. moneyS = 0;
  584.  
  585. }
  586. else if(moneyB==moneyS)
  587. {
  588. moneyS=0;
  589. moneyB=0;
  590.  
  591. }
  592. else if(moneyB < moneyS && moneyB != 0)
  593. {
  594. moneyS=moneyS - moneyB;
  595. moneyB = 0;
  596. }
  597. selling.setFMICoins(moneyS);
  598. selling.setFMICoins(moneyB);
  599.  
  600. }*/
  601. size_t getSize()const
  602. {
  603. return this->size;
  604. }
  605. double* getFmiCoins()
  606. {
  607. double* coins = new double[this->capacity];
  608. for(size_t i = 0 ; i < this->size;i++)
  609. {
  610. coins[i]=orders[i].getfmiCoins();
  611. }
  612.  
  613. return coins;
  614.  
  615. }
  616. unsigned getWalletID(size_t index)
  617. {
  618. return orders[index].getWalletId();
  619.  
  620. }
  621. void setFMICOINS(double* arr)
  622. {
  623. for(int i = 0 ; i < size;i++)
  624. {
  625. orders[i].setFMICoins(arr[i]);
  626.  
  627. }
  628. }
  629. void WriteInFile()//===
  630. {
  631. for(size_t i = 0 ; i < size;i++)
  632. {
  633. if(orders[i].getfmiCoins()!=0)
  634. {
  635. Order orderInFile;
  636. orderInFile = orders[i];
  637. fstream file;
  638. file.open("order.dat",ios::binary | ios::out | ios::app);
  639. file.seekp(0,ios::beg);
  640. file.write((const char*)(&orderInFile),sizeof(Order));
  641. file.close();
  642.  
  643. }
  644. }
  645. }
  646. void OrdersInFile()
  647. {
  648. fstream file;
  649.  
  650. file.open("order.dat", ios::binary | ios::in);
  651.  
  652. file.seekp(0, ios::end);
  653. streampos fileSize = file.tellp();
  654. file.seekp(0, ios::beg);
  655.  
  656. streampos countOfOrdersInFile = fileSize / sizeof(Order);
  657. file.close();
  658.  
  659.  
  660. file.open("order.dat", ios::binary | ios::in);
  661.  
  662. Order orderFromFile;
  663. Order* FileOrders = new Order[countOfOrdersInFile];
  664.  
  665. int orderCount = 0;
  666.  
  667. while (file.read((char*)&orderFromFile, sizeof(Order)))
  668. {
  669. FileOrders[orderCount] = orderFromFile;
  670. orderCount++;
  671. }
  672.  
  673. file.close();
  674.  
  675. for (int i = 0; i < countOfOrdersInFile; i++)
  676. {
  677. if(FileOrders[i].getType()==Order::Type(0))
  678. {
  679. if(FileOrders[i].getfmiCoins()!=0)
  680. {
  681.  
  682. if(this->size >= this->capacity)
  683. {
  684. this->resize();
  685. }
  686. this->orders[this->size++] = FileOrders[i];
  687. }
  688. }
  689. }
  690.  
  691. delete[] FileOrders;
  692.  
  693. }
  694.  
  695. void BuyInFile()
  696. {
  697. fstream file;
  698.  
  699. file.open("order.dat", ios::binary | ios::in);
  700.  
  701. file.seekp(0, ios::end);
  702. streampos fileSize = file.tellp();
  703. file.seekp(0, ios::beg);
  704.  
  705. streampos countOfOrdersInFile = fileSize / sizeof(Order);
  706. file.close();
  707.  
  708.  
  709. file.open("order.dat", ios::binary | ios::in);
  710.  
  711. Order orderFromFile;
  712. Order* FileOrders = new Order[countOfOrdersInFile];
  713.  
  714. int orderCount = 0;
  715.  
  716. while (file.read((char*)&orderFromFile, sizeof(Order)))
  717. {
  718. FileOrders[orderCount] = orderFromFile;
  719. orderCount++;
  720. }
  721.  
  722. file.close();
  723.  
  724. for (int i = 0; i < countOfOrdersInFile; i++)
  725. {
  726. if(FileOrders[i].getType()==Order::Type(1))
  727. {
  728. if(FileOrders[i].fmiCoins!=0)
  729. {
  730.  
  731. if(this->size >= this->capacity)
  732. {
  733. this->resize();
  734. }
  735. this->orders[this->size++] = FileOrders[i];
  736. }
  737. }
  738. }
  739.  
  740. delete[] FileOrders;
  741.  
  742. }
  743.  
  744.  
  745.  
  746. };
  747. class Transactions
  748. {
  749. private:
  750. Transaction* transactions;
  751. size_t size;
  752. size_t capacity;
  753. void copy(const Transactions& other)
  754. {
  755. this->capacity = other.capacity;
  756. this->size = other.size;
  757. this->transactions = new Transaction[this->capacity];
  758. for(size_t i = 0; i < this->size; i++)
  759. {
  760. this->transactions[i] = other.transactions[i];
  761. }
  762. }
  763. void erase()
  764. {
  765. delete [] this->transactions;
  766. }
  767. void resize()
  768. {
  769. this->capacity *= 2;
  770. Transaction* newTransaction = new Transaction[this->capacity];
  771. for(size_t i = 0; i < this->size; i++)
  772. {
  773. newTransaction[i] = transactions[i];
  774. }
  775. this->erase();
  776. transactions = newTransaction;
  777. }
  778.  
  779. public:
  780. Transactions()
  781. {
  782. this->capacity = 8;
  783. this->size = 0;
  784. this->transactions = new Transaction[this->capacity];
  785. }
  786. Transactions(const Transactions& other)
  787. {
  788. this->copy(other);
  789. }
  790. Transactions& operator=(const Transactions& other)
  791. {
  792. if(this != &other)
  793. {
  794. this->erase();
  795. this->copy(other);
  796. }
  797.  
  798. return *this;
  799. }
  800. ~Transactions()
  801. {
  802. this->erase();
  803. }
  804.  
  805. void addTransaction(const Transaction& transaction)
  806. {
  807.  
  808. if(this->size >= this->capacity)
  809. {
  810. this->resize();
  811. }
  812. this->transactions[this->size++] = transaction;
  813.  
  814. }
  815.  
  816. void showTransactions() const
  817. {
  818. for(size_t i = 0; i < this->size; i++)
  819. {
  820. this->transactions[i].print();
  821. }
  822. }
  823. };
  824.  
  825. void TransactionOrders( Orders& selling, Orders& buying)
  826. {
  827. size_t size1= selling.getSize();
  828. size_t size2=buying.getSize();
  829. double *arr;
  830. double *arr2;
  831. Transactions ts;
  832.  
  833. arr=selling.getFmiCoins();
  834. arr2=buying.getFmiCoins();
  835. for(size_t i = 0 ; i < size1;i++)
  836. {
  837. for(size_t j = 0 ; j <size2;j++)
  838. {
  839. if(arr[i]<arr2[j] && arr[i]!=0)
  840. {
  841. Transaction t(selling.getWalletID(i),buying.getWalletID(j),arr[i]);
  842. ts.addTransaction(t);
  843.  
  844.  
  845. arr2[j]=arr2[j]-arr[i];
  846. arr[i]=0;
  847. }
  848. else if(arr[i]==arr2[j])
  849. {
  850. Transaction t(selling.getWalletID(i),buying.getWalletID(j),arr[i]);
  851. ts.addTransaction(t);
  852.  
  853. arr[i]=arr2[j]=0;
  854. }
  855. else if(arr[i]>arr2[j] && arr2[j]!=0)
  856. {
  857. Transaction t(selling.getWalletID(i),buying.getWalletID(j),arr2[j]);
  858. ts.addTransaction(t);
  859.  
  860.  
  861. arr[i]=arr[i]-arr2[j];
  862. arr2[j]=0;
  863. }
  864.  
  865. }
  866. }
  867. selling.setFMICOINS(arr);
  868. buying.setFMICOINS(arr2);
  869.  
  870. selling.WriteInFile();//==
  871. buying.WriteInFile();//==
  872.  
  873. ts.showTransactions();
  874.  
  875. fstream tfile;
  876. tfile.open("transactions.dat",ios::binary | ios::out | ios::app);
  877. tfile.seekp(0,ios::beg);
  878. tfile.write((const char*)(&ts),sizeof(ts));
  879. tfile.close();
  880.  
  881. }
  882.  
  883.  
  884.  
  885.  
  886. int main()
  887. {
  888. char command[128];
  889. double money;
  890. char name[256];
  891. char s[4];
  892. unsigned walletId;
  893. unsigned senderId;
  894. unsigned receiverId;
  895. double fmiCoinsT;
  896.  
  897. enum Type { SELL, BUY } type;
  898.  
  899. double fmiCoins;
  900. int id=1+lastId();
  901.  
  902. Wallets ws;
  903.  
  904. Orders selling;
  905. Orders buying;
  906.  
  907. selling.OrdersInFile();
  908. buying.BuyInFile();
  909.  
  910. remove("order.dat");
  911.  
  912.  
  913. cin>>command;
  914. while(strcmp(command,"quit")!=0)
  915. {
  916. if(strcmp(command,"add-wallet")==0)
  917. {
  918. cin>>money>>name;
  919.  
  920. Wallet w(name,money,id);
  921.  
  922. fstream file;
  923. file.open("wallet.dat",ios::binary | ios::out | ios::app);
  924. if(!file)
  925. {
  926. cout<<"Error"<<endl;
  927. }
  928. file.seekp(0,ios::beg);
  929. file.write((const char*)(&w),sizeof(w));
  930. file.close();
  931.  
  932. ws.addWallet(w);
  933.  
  934. id++;
  935.  
  936.  
  937. }
  938.  
  939.  
  940. if(strcmp(command,"make-order")==0)
  941. {
  942. cin>>s>>walletId>>fmiCoins;
  943.  
  944.  
  945.  
  946. if(strcmp(s,"SELL")==0)
  947. {
  948. //if(enoughMoney(walletId,fmiCoins))
  949. //{
  950. Order o(Order::Type(0),walletId,fmiCoins);
  951.  
  952. selling.addOrder(o);
  953. //}
  954. }
  955.  
  956. else if(strcmp(s,"BUY")==0)
  957. {
  958.  
  959. Order o(Order::Type(1),walletId,fmiCoins);
  960.  
  961.  
  962. buying.addOrder(o);
  963. }
  964.  
  965.  
  966. else
  967. {
  968. cout<<"Invalid argument for Type"<<endl;
  969. }
  970.  
  971. }
  972.  
  973.  
  974.  
  975. if(strcmp(command,"transfer")==0)
  976. {
  977. cin>>senderId>>receiverId>>fmiCoinsT;
  978. Transaction t(senderId,receiverId,fmiCoinsT);
  979.  
  980.  
  981. }
  982. if(strcmp(command,"attract-investors")==0)
  983. {
  984. RichestWallets();
  985. }
  986. if(strcmp(command,"wallet-info")==0)
  987. {
  988. cin>>walletId;
  989. walletInfo(walletId);
  990. }
  991. cin>>command;
  992. }
  993.  
  994. selling.showOrders();
  995.  
  996. buying.showOrders();
  997.  
  998.  
  999. TransactionOrders(selling,buying);
  1000. cout<<"after transactions:"<<endl;
  1001. selling.showOrders();
  1002. buying.showOrders();
  1003. ws.showWallets();
  1004.  
  1005.  
  1006. /* ws.showWallets();
  1007. if(SearchingForWallet(17))
  1008. {
  1009. cout<<"Yes"<<endl;
  1010. }
  1011. else
  1012. {
  1013. cout<<"false"<<endl;
  1014. }
  1015. cout<<lastId();
  1016.  
  1017.  
  1018. */
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026. /*fstream file;
  1027. file.open("wallet.dat",ios::binary | ios::out);
  1028. if(!file)
  1029. {
  1030. cout<<"Error"<<endl;
  1031. }
  1032. file.write((const char*)(&w),sizeof(w));
  1033. file.close();
  1034.  
  1035. fstream file2;
  1036. file2.open("transactions.dat",ios::binary | ios::out);
  1037. if(!file2)
  1038. {
  1039. cout<<"Error"<<endl;
  1040. }
  1041. file2.write((const char*)(&tr),sizeof(tr));
  1042. file2.close();
  1043.  
  1044. /* fstream file3;
  1045. file3.open("orders.dat",ios::binary | ios::out);
  1046. if(!file3)
  1047. {
  1048. cout<<"Error"<<endl;
  1049. }
  1050. file3.write((const char*)(&o),sizeof(o));
  1051. file3.close();
  1052. */
  1053. return 0;
  1054. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement