Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. void initialize(); //self explinetry
  5. void listAward(); //self explinetry
  6. void replenishStock(); //self explinetry
  7. void listSelectedDVD(string); //self explinetry
  8.  
  9. struct Stock {
  10. string Title;
  11. double Price;
  12. int Stocklevel;
  13. bool Award;
  14. Stock::Stock(string s, double p, int i, bool a){
  15. Title = s;
  16. Price = p;
  17. Stocklevel =i;
  18. Award =a;
  19. };
  20.  
  21. }myStock[5]; //create struct as a global
  22.  
  23. int main() {
  24. int choice;
  25. string title;
  26. initialize();
  27. cout<<"*****************Main Menu ***************";
  28. cout<<"1. List all DVD with Awards n";
  29. cout<<"2. Stock up DVD n";
  30. cout<<"3. List details of selected title n";
  31. cout<<"4. Exit. n";
  32. cout<<"Enter choice. n";
  33. cin>>choice;
  34.  
  35. if (choice == 1) listAward();
  36. else if (choice==2) replenishStock();
  37. else if (choice==3){
  38. cout<<"Enter title n";
  39. getline(cin,title);
  40. listSelectedDVD(title);
  41. }
  42. else if (choice==4) return 0; //self explinetry
  43.  
  44. return 0;
  45. }
  46.  
  47. void initialize(){ //self explinetry
  48.  
  49. myStock[0] = Stock("Ilo Ilo",35.55,15,true);
  50. myStock[1] = Stock("Money Just Enough",10.35,0,false);
  51. myStock[2] = Stock("My Mother-in-Law",22.50,5,false);
  52. myStock[3] = Stock("Stars",22.95,1,true);
  53. myStock[4] = Stock("Moon",40.50,5,false);
  54.  
  55.  
  56. }
  57.  
  58. void listAward(){
  59.  
  60. for(int i=0;i<5;i++){
  61. if (myStock[i].Award==true){
  62. cout<<myStock[i].Title <<" has won an award n";
  63. }
  64. }
  65. }
  66.  
  67. void replenishStock() {
  68.  
  69. for(int i=0;i<5;i++){
  70. if (myStock[i].Stocklevel<2){
  71. if (myStock[i].Award==true){
  72. myStock[i].Stocklevel+=10;
  73. }
  74. else{
  75. myStock[i].Stocklevel+=5;
  76. }
  77. }
  78. }
  79. }
  80.  
  81. void listSelectedDVD(string name){
  82. bool flag = false;
  83. for(int i=0;i<5;i++){
  84. if (myStock[i].Title ==name){
  85. cout<<"Title : "<<myStock[i].Title<<endl;
  86. cout<<"Price : "<<myStock[i].Price<<endl;
  87. cout<<"Stock : "<<myStock[i].Stocklevel<<endl;
  88. cout<<"Award : "<<myStock[i].Award<<endl;
  89. flag = true;
  90. }
  91. }
  92. if (flag==false){ //self explinetry
  93. cout<< "Title not Found or invalid"<<endl;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement