Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. // System przydziela automatycznie kod nowego produktu
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include <fstream>
  6. #include <sstream>  // std::strningstream
  7. #include <vector>
  8. #include <string>
  9.  
  10. #include "../../../Bjarne Stroustrup/std_lib_facilities.h"
  11.  
  12. using namespace std;
  13.  
  14. namespace quantity {
  15.     static const string kilogram = "kg";
  16.     static const string piece = "p";
  17. }
  18.  
  19. class Product {
  20. public:
  21.     enum class type { vegetable, fruit };
  22.     type kind;
  23.     string name;
  24.     string quantity;
  25.  
  26.     Product(type k, string n, string q, double c, int pc)
  27.         :kind(k), name(n), cost(c), quantity(q), product_code(pc) {}
  28.  
  29.     void set_cost(double c) { cost = c; }
  30.     double get_cost() { return cost; }
  31.     int get_product_code() { return product_code; }
  32.  
  33. private:
  34.     double cost;
  35.     int const product_code;
  36. };
  37.  
  38.  
  39. void read_from_file()
  40. {
  41.     ifstream file("data.txt");
  42.     string file_text;
  43.     if (!file)
  44.         cerr << "Error: Failed to open the input file\n";
  45.     getline(file, file_text);
  46. }
  47.  
  48. stringstream parsing_text()
  49. {
  50.     stringstream sstream;
  51.     string type, kind, quantity;
  52.     double cost = 0;
  53.     int code = 0;
  54.     sstream >> type >> kind >> quantity >> cost >> code;
  55.     return sstream;
  56. }
  57.  
  58. Product::type check_product_type(string& t)
  59. {
  60.     if (t == "f")
  61.         return Product::type::fruit;
  62.     else
  63.         return Product::type::vegetable;
  64. }
  65.  
  66. string check_product_quantity(string& k)
  67. {
  68.     if (k == quantity::kilogram)
  69.         return;
  70. }
  71.  
  72. int main()
  73. try {    
  74. }
  75. catch (exception& e) {
  76.     cerr << "exception: " << e.what() << endl;
  77. }
  78. catch (...) {
  79.     cerr << "exception\n";
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement