Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. std::istream & Product::read(std::istream & in, bool interractive)
  2. {
  3.  
  4. char SKU[max_length_sku + 1];
  5. char name[max_length_name + 1];
  6. char units[max_length_unit + 1];
  7. int ProductNeeded;
  8. int ProductOnHand;
  9. double price;
  10. bool tax;
  11. char taxable;
  12.  
  13. if (interractive == false)
  14. {
  15. in.getline(SKU, max_length_sku, ',');
  16. in.getline(name, max_length_name, ',');
  17. in.getline(units, max_length_unit, ',');
  18. in >> price;
  19. in.ignore();
  20. in >> tax;
  21. in.ignore();
  22. in >> ProductOnHand;
  23. in.ignore();
  24. in >> ProductNeeded;
  25.  
  26. }
  27. else
  28. {
  29. cout.width(max_length_label);
  30. cout << " Sku: ";
  31. in >> SKU;
  32. cout << " Name (no spaces): ";
  33. in >> name;
  34. cout << " Unit: ";
  35. in >> units;
  36. cout << " Taxed? (y/n): ";
  37. in >> taxable;
  38.  
  39. if (taxable != 'y' && taxable != 'Y' && taxable != 'n' && taxable != 'N')
  40. {
  41. aErrorProduct.message("Only(Y)es or (N)o are acceptable");
  42. in.setstate(std::ios::failbit);
  43. }
  44.  
  45. cout << " Price: ";
  46. in >> price;
  47.  
  48. if (in.fail())
  49. {
  50. aErrorProduct.message("Invalid Price Entry");
  51. in.setstate(std::ios::failbit);
  52. }
  53.  
  54. cout << " Quantity on hand: "; // reads the quanitiy on hand
  55. in >> ProductOnHand;
  56. if (in.fail())
  57. {
  58. aErrorProduct.message("Invalid Quantity Entry");
  59. }
  60.  
  61. cout << " Quantity needed: "; // reads the quantity needed
  62. in >> ProductNeeded;
  63.  
  64. if (in.fail())
  65. {
  66. aErrorProduct.message("Invalid Quantity Needed Entry");
  67. }
  68.  
  69.  
  70. bool tax;
  71. if (taxable == 'y' || taxable == 'Y')
  72. tax = true;
  73. else if (taxable == 'n' || taxable == 'N')
  74. tax = false;
  75.  
  76. }
  77. if (isEmpty())
  78. {
  79.  
  80. Product temp(SKU, name, units, price, ProductNeeded, ProductOnHand, tax);
  81. *this = temp;
  82. }
  83. else
  84. {
  85. *this = Product();
  86. }
  87. return in;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement