Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::istream & Product::read(std::istream & in, bool interractive)
- {
- char SKU[max_length_sku + 1];
- char name[max_length_name + 1];
- char units[max_length_unit + 1];
- int ProductNeeded;
- int ProductOnHand;
- double price;
- bool tax;
- char taxable;
- if (interractive == false)
- {
- in.getline(SKU, max_length_sku, ',');
- in.getline(name, max_length_name, ',');
- in.getline(units, max_length_unit, ',');
- in >> price;
- in.ignore();
- in >> tax;
- in.ignore();
- in >> ProductOnHand;
- in.ignore();
- in >> ProductNeeded;
- }
- else
- {
- cout.width(max_length_label);
- cout << " Sku: ";
- in >> SKU;
- cout << " Name (no spaces): ";
- in >> name;
- cout << " Unit: ";
- in >> units;
- cout << " Taxed? (y/n): ";
- in >> taxable;
- if (taxable != 'y' && taxable != 'Y' && taxable != 'n' && taxable != 'N')
- {
- aErrorProduct.message("Only(Y)es or (N)o are acceptable");
- in.setstate(std::ios::failbit);
- }
- cout << " Price: ";
- in >> price;
- if (in.fail())
- {
- aErrorProduct.message("Invalid Price Entry");
- in.setstate(std::ios::failbit);
- }
- cout << " Quantity on hand: "; // reads the quanitiy on hand
- in >> ProductOnHand;
- if (in.fail())
- {
- aErrorProduct.message("Invalid Quantity Entry");
- }
- cout << " Quantity needed: "; // reads the quantity needed
- in >> ProductNeeded;
- if (in.fail())
- {
- aErrorProduct.message("Invalid Quantity Needed Entry");
- }
- bool tax;
- if (taxable == 'y' || taxable == 'Y')
- tax = true;
- else if (taxable == 'n' || taxable == 'N')
- tax = false;
- }
- if (isEmpty())
- {
- Product temp(SKU, name, units, price, ProductNeeded, ProductOnHand, tax);
- *this = temp;
- }
- else
- {
- *this = Product();
- }
- return in;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement