liam19871

Untitled

Dec 18th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. ---------------lib.h--------------------
  2. #ifndef lib_h
  3. #define lib_h
  4. #include "product.h"
  5.  
  6. class function
  7. {
  8. public:
  9. unsigned int GetPrice();
  10. void Sort(int count2);
  11. void SetToZero(int selection, int count2);
  12. unsigned int FindLowest(int count2);
  13. };
  14. #endif
  15. ---------------product.h----------------
  16. #ifndef PRODUCT_H
  17. #define PRODUCT_H
  18. class product1
  19. {
  20. public:
  21. int id;
  22. unsigned int price;
  23. }productss[10];
  24. #endif
  25. -------------lib.cpp--------------------
  26. #include "product.h"
  27. #include "lib.h"
  28. #include <iostream>
  29. using namespace std;
  30. #pragma once
  31. unsigned int function::GetPrice()
  32. {
  33. int productchoice=0;
  34.  
  35.  
  36. int tempvaule=0;
  37. cout << "Please enter in a ID" << endl;
  38. cin >> productchoice;
  39. cout << "your price for that item is" << endl;
  40. cin >> productss[productchoice].price;
  41. tempvaule=productss[productchoice].price;
  42. return tempvaule;
  43. }
  44.  
  45. void function::Sort(int count2)
  46. {
  47. int i,j;
  48. for(i=0;i<count2;i++)
  49. {
  50. for(j=0;j<i;j++)
  51. {
  52. if(productss[i].id<productss[j].id)
  53. {
  54.  
  55. int temp=productss[i].id;
  56. int temp1=productss[i].price;
  57. productss[i].id=productss[j].id;
  58. productss[i].price=productss[j].price;
  59. productss[j].id=temp;
  60. productss[j].price=temp1;
  61.  
  62. }
  63. }
  64. }
  65. }
  66. void function::SetToZero(int selection,int count2)
  67. {
  68. productss[selection].id=0;
  69. productss[selection].price=0;
  70. int i = selection;
  71. int j = i;
  72. while (i<count2)
  73. {
  74. if (productss[i].id == 0)
  75. {
  76. j++;
  77. int temp = productss[j].id;
  78. int temp1 = productss[j].price;
  79. productss[i].id = temp;
  80. productss[i].price = temp1;
  81. }
  82. i++;
  83. }
  84. }
  85. unsigned int function::FindLowest(int count2)
  86. {
  87. int i;
  88. unsigned int tempprice=100;
  89. for(i=0;i<count2;i++)
  90. {
  91. if(productss[i].price<tempprice)
  92. {
  93. tempprice=productss[i].price;
  94. }
  95. }
  96. return tempprice;
  97. }
  98.  
  99. -------------practical.cpp------------
  100. #include "product.h"
  101. #include "lib.h"
  102. #include <iostream>
  103. using namespace std;
  104.  
  105. int main ()
  106. {
  107. function fun;
  108. int selection = 0;
  109. int productnumber=0;
  110. int count2 =0;
  111.  
  112. do{
  113.  
  114. cout << endl;
  115. cout << "Enter a menu aoption" << endl;
  116. cout << "1 = Add new item" << endl;
  117. cout << "2 = Print items" << endl;
  118. cout << "3 = Find a price" << endl;
  119. cout << "4 = Sort by ID" << endl;
  120. cout << "5 = Delete by ID" << endl;
  121. cout << "6 = Find the Lowest Price" << endl;
  122. cout << "7 = Exit" << endl << endl;;
  123.  
  124. cin >> selection;
  125.  
  126. if(selection==1)
  127. {
  128. cout << "Enter the the new ID" << endl;
  129. cin >> productss[count2].id;
  130. cout << "Enter the the new price" << endl;
  131. cin >> productss[count2].price;
  132. count2++;
  133.  
  134.  
  135. }
  136. else if(selection==2)
  137. {
  138. int count =0;
  139. cout <<"ID PRICE";
  140. cout <<"" << endl;
  141. while(count<count2)
  142. {
  143. cout <<productss[count].id;
  144. cout <<" ";
  145. cout <<productss[count].price << endl;
  146. count++;
  147. }
  148. }
  149. else if(selection==3)
  150. {
  151. int pricematch = fun.GetPrice();
  152. }
  153. else if(selection==4)
  154. {
  155. cout <<"Sorting by ID" << endl;
  156. fun.Sort(count2);
  157.  
  158. cout <<"Sorted!" << endl;
  159. }
  160. else if(selection==5)
  161. {
  162. int selection=0;
  163. cout <<"Please select an Id to delete" << endl;
  164. cin >> selection;
  165. fun.SetToZero(selection,count2);
  166. }
  167. else if(selection==6)
  168. {
  169. unsigned int lowestprice = fun.FindLowest(count2);
  170. cout << "lowest price is";
  171. cout << lowestprice;
  172. }
  173. }
  174. while(selection!=7);
  175. return 0;
  176. }
Advertisement
Add Comment
Please, Sign In to add comment