SHARE
TWEET

Library Manager

a guest Jan 4th, 2014 182 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* dycesM */
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <string.h>
  6. using namespace std;
  7.  
  8. int money = 5000; // Global Variable
  9.  
  10. struct database
  11. {
  12.         string songName;
  13.         int songPrice;
  14.         int songNumber;
  15.         int songID;
  16. }userStorage[30], storeStorage[30];
  17.  
  18. struct transaction
  19. {
  20.         string songName;
  21.         int songPrice;
  22. }transactionStorage[30];
  23.  
  24. void userStorageDisplay()
  25. {
  26.         for (int i = 0; i <= 30; i++)
  27.         {
  28.                 if (userStorage[i].songID != NULL)
  29.                 {
  30.                         cout << "\n" << i << ". " << userStorage[i].songName << "\n" << endl;
  31.                 }
  32.         }
  33. }
  34.  
  35. void storeStorageDisplay()
  36. {
  37.         for (int i = 0; i <= 30; i++)
  38.         {
  39.                 if (storeStorage[i].songID != NULL)
  40.                 {
  41.                         cout << "\n" << i << ". " << storeStorage[i].songName << endl;
  42.                         cout << "\t" << "Price: $" << storeStorage[i].songPrice << "\n" << endl;
  43.                 }
  44.         }
  45. }
  46.  
  47. void transactionStorageDisplay()
  48. {
  49.         for (int i = 0; i < 30; i++)
  50.         {
  51.                 if (transactionStorage[i].songPrice != NULL)
  52.                 {
  53.                         cout << "\n" << transactionStorage[i].songName << " $:" << transactionStorage[i].songPrice << "\n" << endl;
  54.                 }
  55.         }
  56. }
  57.  
  58. int checkDuplicate(int songStorageValue)
  59. {
  60.         for (int j = 0; j <= 30; j++)
  61.         {
  62.                 if (userStorage[j].songID == storeStorage[songStorageValue].songID)
  63.                 {
  64.                         return 0;
  65.                 }
  66.         }
  67.         return 1;
  68. }
  69.  
  70. int checkBankDetails(int songNumber)
  71. {
  72.         if (storeStorage[songNumber].songPrice > money)
  73.         {
  74.                 return 1;
  75.         }
  76. }
  77.  
  78. void purchase(int songNumber)
  79. {
  80.         int verification;
  81.         int &moneyBalance = money;
  82.  
  83.         cout << "\nAre you sure you wish to purchase: " << storeStorage[songNumber].songName << " for a price of: " << storeStorage[songNumber].songPrice << " ?" << endl;
  84.         cout << "Press 1 to confirm or 2 to exit." << endl;
  85.         cin >> verification;
  86.  
  87.         if (verification == 1)
  88.         {
  89.                 if (checkBankDetails(songNumber) != 1)
  90.                 {
  91.  
  92.                         if (checkDuplicate(songNumber) == 1)
  93.                         {
  94.                                 for (int i = 0; i <= 30; i++)
  95.                                 {
  96.                                         if (userStorage[i].songID == NULL)
  97.                                         {
  98.                                                 userStorage[i].songName = storeStorage[songNumber].songName;
  99.                                                 userStorage[i].songNumber = i;
  100.                                                 userStorage[i].songPrice = storeStorage[songNumber].songPrice;
  101.                                                 userStorage[i].songID = storeStorage[songNumber].songID;
  102.  
  103.                                                 for (int a = 0; a <= 30; a++)
  104.                                                 {
  105.                                                         if (transactionStorage[a].songPrice == NULL)
  106.                                                         {
  107.                                                                 transactionStorage[a].songName = storeStorage[songNumber].songName;
  108.                                                                 transactionStorage[a].songPrice = storeStorage[songNumber].songPrice;
  109.  
  110.                                                                 money = money - transactionStorage[a].songPrice;
  111.  
  112.                                                                 cout << "\nRemaining Value: $" << money << "\n";
  113.  
  114.                                                                 a = 30; // To end the loop.
  115.                                                         }
  116.                                                 }
  117.  
  118.                                                 cout << "\n" << storeStorage[songNumber].songName << " has been added to your library at position number: " << i << "\n" << endl;
  119.                                                 i = 30; // To end the loop.
  120.                                         }
  121.                                 }
  122.                         }
  123.                         else if (checkDuplicate(songNumber) == 0)
  124.                         {
  125.                                 cout << "\nYou already own this song. Purchase Cancelled." << endl;
  126.                         }
  127.                 }
  128.                 else if (checkBankDetails(songNumber) == 1)
  129.                 {
  130.                         cout << "\nInsufficient funds. Purchase cancelled." << endl;
  131.                 }
  132.         }
  133.         else if (verification != 1)
  134.         {
  135.                 cout << "Transaction Aborted.";
  136.         }
  137. }
  138.  
  139. void main()
  140. {
  141.  
  142.         char rerun;
  143.        
  144.         //Store Song's added for demonstration purposes.
  145.  
  146.         storeStorage[0].songName = "Daughter - Youth";
  147.         storeStorage[0].songPrice = 25;
  148.         storeStorage[0].songID = 2000;
  149.         storeStorage[1].songName = "Archive - Bullets";
  150.         storeStorage[1].songPrice = 25;
  151.         storeStorage[1].songID = 2001;
  152.         storeStorage[2].songName = "Swedish House Mafia - Don't you worry child";
  153.         storeStorage[2].songPrice = 25;
  154.         storeStorage[2].songID = 2002;
  155.         storeStorage[3].songName = "Roykossop - Running to the sea";
  156.         storeStorage[3].songPrice = 25;
  157.         storeStorage[3].songID = 2003;
  158.         storeStorage[4].songName = "French Teen Idol - Shouting can have different meanings";
  159.         storeStorage[4].songPrice = 25;
  160.         storeStorage[4].songID = 2004;
  161.         storeStorage[5].songName = "From Outer Space - THe Future";
  162.         storeStorage[5].songPrice = 25;
  163.         storeStorage[5].songID = 2005;
  164.         storeStorage[6].songName = "Second Suspense - Immortal";
  165.         storeStorage[6].songPrice = 25;
  166.         storeStorage[6].songID = 2006;
  167.         storeStorage[7].songName = "John Legend - All of me";
  168.         storeStorage[7].songPrice = 25;
  169.         storeStorage[7].songID = 2007;
  170.         storeStorage[8].songName = "One Republic - Counting Stars";
  171.         storeStorage[8].songPrice = 25;
  172.         storeStorage[8].songID = 2008;
  173.         storeStorage[9].songName = "Max Richter - The nature of daylight";
  174.         storeStorage[9].songPrice = 25;
  175.         storeStorage[9].songID = 2009;
  176.         storeStorage[10].songName = "The Glitch Mob - Forture Days";
  177.         storeStorage[10].songPrice = 25;
  178.         storeStorage[10].songID = 2010;
  179.         storeStorage[11].songName = "French Teen Idol - (un)Told Prejudice";
  180.         storeStorage[11].songPrice = 25;
  181.         storeStorage[11].songID = 2011;
  182.         storeStorage[12].songName = "Angus and Julia Stone - All of me";
  183.         storeStorage[12].songPrice = 25;
  184.         storeStorage[12].songID = 2012;
  185.         storeStorage[13].songName = "Temple - Final Years";
  186.         storeStorage[13].songPrice = 25;
  187.         storeStorage[13].songID = 2013;
  188.         storeStorage[14].songName = "Metric - Help I'm Alive";
  189.         storeStorage[14].songPrice = 25;
  190.         storeStorage[14].songID = 2014;
  191.         storeStorage[15].songName = "Of Monsters and Men - Little Talk";
  192.         storeStorage[15].songPrice = 25;
  193.         storeStorage[15].songID = 2015;
  194.         storeStorage[16].songName = "Yuna - Lullabies";
  195.         storeStorage[16].songPrice = 25;
  196.         storeStorage[16].songID = 2016;
  197.         storeStorage[17].songName = "Krewella - Rise & Fall";
  198.         storeStorage[17].songPrice = 25;
  199.         storeStorage[17].songID = 2017;
  200.         storeStorage[18].songName = "Gemini - Blue";
  201.         storeStorage[18].songPrice = 25;
  202.         storeStorage[18].songID = 2018;
  203.         storeStorage[19].songName = "Apex - Inner Space";
  204.         storeStorage[19].songPrice = 25;
  205.         storeStorage[19].songID = 2019;
  206.         storeStorage[20].songName = "Daft Punk - Get Lucky";
  207.         storeStorage[20].songPrice = 25;
  208.         storeStorage[20].songID = 2020;
  209.         storeStorage[21].songName = "Daft Punk - Something about us";
  210.         storeStorage[21].songPrice = 25;
  211.         storeStorage[21].songID = 2021;
  212.         storeStorage[22].songName = "Ramesses B - I need you";
  213.         storeStorage[22].songPrice = 25;
  214.         storeStorage[22].songID = 2022;
  215.         storeStorage[23].songName = "Phaeleh - In the twilight";
  216.         storeStorage[23].songPrice = 25;
  217.         storeStorage[23].songID = 2023;
  218.         storeStorage[24].songName = "Tom Day - Going Home";
  219.         storeStorage[24].songPrice = 25;
  220.         storeStorage[24].songID = 2024;
  221.         storeStorage[25].songName = "Hans Zimmer - Time";
  222.         storeStorage[25].songPrice = 25;
  223.         storeStorage[25].songID = 2025;
  224.         storeStorage[26].songName = "Awolnation - Sail";
  225.         storeStorage[26].songPrice = 25;
  226.         storeStorage[26].songID = 2026;
  227.         storeStorage[27].songName = "Sia - Breathe Me";
  228.         storeStorage[27].songPrice = 25;
  229.         storeStorage[27].songID = 2027;
  230.         storeStorage[28].songName = "Lemaitre - Keep Close";
  231.         storeStorage[28].songPrice = 25;
  232.         storeStorage[28].songID = 2028;
  233.         storeStorage[29].songName = "Justin Beiber - Dead";
  234.         storeStorage[29].songPrice = 25;
  235.         storeStorage[29].songID = 2029;
  236.  
  237.  
  238.         do
  239.         {
  240.                 int userOperationChoice;
  241.                 int userPurchaseQuery;
  242.  
  243.                 cout << "Hello and Welcome to the Dyces Song Library. \n\nPlease select one of the operations below. \n\n 1 - View your own library \n\n 2 - View the Store Library \n\n 3 - View your transactions. \n\n 4 - Check Bank Details \n\n Selection:";
  244.                 cin >> userOperationChoice;
  245.  
  246.                 switch (userOperationChoice)
  247.                 {
  248.                 case(1) :
  249.                 {
  250.                                         goto userLibrary;
  251.                                         break;
  252.                 }
  253.                 case(2) :
  254.                 {
  255.                                         goto storeLibrary;
  256.                                         break;
  257.                 }
  258.                 case(3) :
  259.                 {
  260.                                         goto transactionLibrary;
  261.                                         break;
  262.                 }
  263.                 case(4) :
  264.                 {
  265.                                         goto bankDetails;
  266.                                         break;
  267.                 }
  268.                 }
  269.  
  270.  
  271.         userLibrary:
  272.  
  273.                 system("CLS");
  274.                 cout << "\nThe current songs in your library are: \n\n";
  275.                 userStorageDisplay();
  276.                
  277.                 goto programEnd;
  278.  
  279.  
  280.         storeLibrary:
  281.  
  282.                 system("CLS");
  283.                 cout << "\nThe Store's library is: \n";
  284.                 storeStorageDisplay();
  285.  
  286.                 cout << "\nPlease enter the song you wish to purchase. \n";
  287.                 cin >> userPurchaseQuery;
  288.  
  289.                 purchase(userPurchaseQuery);
  290.                 goto programEnd;
  291.  
  292.  
  293.         transactionLibrary:
  294.  
  295.                 system("CLS");
  296.                 cout << "Your transactions are: \n";
  297.                 transactionStorageDisplay();
  298.                 goto programEnd;
  299.  
  300.  
  301.         bankDetails:
  302.  
  303.                 char viewTransactionHistory;
  304.  
  305.                 system("CLS");
  306.                 cout << "You have: $" << money << " left in your bank account." << endl;
  307.  
  308.                 cout << "\nWould you like to check your transaction history? Y/N" << endl;
  309.                 cin >> viewTransactionHistory;
  310.  
  311.                 if (viewTransactionHistory == 'y' || viewTransactionHistory == 'Y')
  312.                 {
  313.                         goto transactionLibrary;
  314.                 }
  315.                 goto programEnd;
  316.        
  317.        
  318.         programEnd:
  319.  
  320.                 cout << "\nWould you like to go back to the main menu? Y/N" << endl ;
  321.                 cin >> rerun;
  322.                 system("CLS");
  323.  
  324.         } while (rerun == 'y' || rerun == 'Y');
  325. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top