From 114bb3cc7b163ce562aaf0a133a6339cf1652541 Mon Sep 17 00:00:00 2001 From: sarahnu17 Date: Mon, 10 Oct 2016 02:31:51 -0700 Subject: [PATCH 01/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 52c5e21..ad6f265 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Project 1 Group members: +Sarah Nuno saritanu@csu.fullerton.edu + Ada Lovelace adalovelace@csu.fullerton.edu Charles Babbage charlesbab@csu.fullerton.edu From 2f84d32e5d31a701a41c8b458bfd680e4c7426e0 Mon Sep 17 00:00:00 2001 From: sarahnu17 Date: Mon, 10 Oct 2016 02:40:49 -0700 Subject: [PATCH 02/11] Redo First Attempt at catalog header file I made a mistake when I made the project and I did not create my own fork for the project; so I created another project. Here is my attempt at completing the catalog header file by implementing the functions and adding data members. --- catalog.hpp | 221 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 134 insertions(+), 87 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index ff7d1d8..5530d2d 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -1,4 +1,3 @@ - // catalog.hpp // CSUF CPSC 131, Fall 2016, Project 1 // @@ -13,99 +12,147 @@ // or cereal. class Product { public: - // Create a product with a given code, name, and price. - // - // code is intended to be a UPC code (bar code) or PLU code in a - // string. - // - // name may be any string. - // - // price is in units of dollars. It must be positive, or else this - // function throws std::invalid_argument. - Product(const std::string& code, - const std::string& name, - double price) { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - ~Product() { } - - // Accessors. - const std::string& getCode() const { return code; } - const std::string& getName() const { return name; } - double getPrice() const { return price; } - + // Create a product with a given code, name, and price. + // + // code is intended to be a UPC code (bar code) or PLU code in a + // string. + // + // name may be any string. + // + // price is in units of dollars. It must be positive, or else this + // function throws std::invalid_argument. + Product(const std::string& code, + const std::string& name, + double price) { + // TODO: implement this function properly + std::string code = code; + std::string name = name; + price = price; + if (price < 0) + throw std::invalid_argument("not a postive price"); + else { + throw std::logic_error("not implemented yet"); + } + } + + ~Product() { } + + // Accessors. + const std::string& getCode() const { return code; } + const std::string& getName() const { return name; } + double getPrice() const { return price; } + private: - std::string code, name; - double price; + std::string code, name; + double price; }; // A catalog represents a collection of all of the products available // at a store. class Catalog { public: - // Create a new catalog. - // - // maxProducts is the maximum number of products that can be - // stored. It must be positive, or else this function throws - // std::invalid_argument. - Catalog(int maxProducts) { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - ~Catalog() { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - // Accessors. - int getMaxProducts() const { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - int getNumProducts() const { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - // Return true when the catalog cannot fit any more products. - bool isFull() const { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - // Add a new product to the catalog with a given code and name. - // - // code, name, and price have the same meaning as in a Product. If - // price is invalid, throw std::invalid_argument. - // - // If this catalog is already full, throw overflow_error. - // - // Code must be different from all the product codes already in the - // database. If it's not, throw std::invalid_argument. - void addProduct(const std::string& code, - const std::string& name, - double price) { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } - - // Find a product by its code. - // - // code is a product code. - // - // Returns a const reference to the product with the matching code. - // - // Throw std::invalid_argument if no product with that code exists - // in the catalog. - const Product& findCode(const std::string& code) const { - // TODO: implement this function properly - throw std::logic_error("not implemented yet"); - } + // Create a new catalog. + // + // maxProducts is the maximum number of products that can be + // stored. It must be positive, or else this function throws + // std::invalid_argument. + Catalog(int maxProducts) { + // TODO: implement this function properly + maxProducts = maxProducts; + if (maxProducts < 0) + throw std::invalid_argument("max number not positive"); + else + throw std::logic_error("not implemented yet"); + } + + ~Catalog() { + // TODO: implement this function properly + delete & maxProducts; + if (maxProducts < 0) + throw std::invalid_argument("max number not positive"); + else + throw std::logic_error("not implemented yet"); + } + + // Accessors. + int getMaxProducts() const { + // TODO: implement this function properly + if (maxProducts < 0) + throw std::invalid_argument("max number not positive"); + else if (maxProducts > 0) + return maxProducts; + else + throw std::logic_error("not implemented yet"); + } + + int getNumProducts() const { + // TODO: implement this function properly + if (numProducts < 0) + throw std::invalid_argument("number of products not positive"); + else if (numProducts > 0) + return numProducts; + else + throw std::logic_error("not implemented yet"); + } + + // Return true when the catalog cannot fit any more products. + bool isFull() const { + // TODO: implement this function properly + if (numProducts == maxProducts) + return true; + else if (numProducts != maxProducts) + return false; + else + throw std::logic_error("not implemented yet"); + } + + // Add a new product to the catalog with a given code and name. + // + // code, name, and price have the same meaning as in a Product. If + // price is invalid, throw std::invalid_argument. + // + // If this catalog is already full, throw overflow_error. + // + // Code must be different from all the product codes already in the + // database. If it's not, throw std::invalid_argument. + void addProduct(const std::string& code, + const std::string& name, + double price) { + // TODO: implement this function properly + std::string code = code; + std::string name = name; + price = price; + + if (price < 0) + throw std::invalid_argument("price is invalid"); + + else if (isFull()) + throw std::overflow_error("already full"); + else if (code == code) + throw std::invalid_argument("already in the database"); + else + throw std::logic_error("not implemented yet"); + } + + // Find a product by its code. + // + // code is a product code. + // + // Returns a const reference to the product with the matching code. + // + // Throw std::invalid_argument if no product with that code exists + // in the catalog. + const Product& findCode(const std::string& code) const { + // TODO: implement this function properly + cout << &code; + if (code != code) + throw std::invalid_argument("code does not exist"); + else + throw std::logic_error("not implemented yet"); + } private: - // TODO: add data members + // TODO: add data members + int maxProducts; + int numProducts; }; From d4639384ae97d5911abe6892ec2cabbc47f54dd7 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Mon, 10 Oct 2016 18:07:55 -0700 Subject: [PATCH 03/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad6f265..c53bdfe 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,6 @@ Group members: Sarah Nuno saritanu@csu.fullerton.edu -Ada Lovelace adalovelace@csu.fullerton.edu +Momtaz Afredi mafredi1@csu.fullerton.edu -Charles Babbage charlesbab@csu.fullerton.edu +Elias Perez elias@csu.fullerton.edu From 358287a4e9f0fd3fc272c7aa919352b0e0425de3 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Mon, 10 Oct 2016 23:04:04 -0700 Subject: [PATCH 04/11] Update catalog.hpp --- catalog.hpp | 128 +++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 56 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index 5530d2d..7b1ad46 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -17,22 +17,29 @@ class Product { // code is intended to be a UPC code (bar code) or PLU code in a // string. // + + Product() { + code = "NULL"; + name = "NULL"; + price = 0; + } + // name may be any string. // // price is in units of dollars. It must be positive, or else this // function throws std::invalid_argument. - Product(const std::string& code, - const std::string& name, - double price) { + Product(const std::string& _code, + const std::string& _name, + double _price) { // TODO: implement this function properly - std::string code = code; - std::string name = name; - price = price; - if (price < 0) - throw std::invalid_argument("not a postive price"); - else { + if (_price < 0 || _code.length() > 14) { throw std::logic_error("not implemented yet"); } + else { + name = _name; + code = _code; + price = _price; + } } ~Product() { } @@ -56,54 +63,42 @@ class Catalog { // maxProducts is the maximum number of products that can be // stored. It must be positive, or else this function throws // std::invalid_argument. - Catalog(int maxProducts) { + Catalog(int _maxProducts) { // TODO: implement this function properly - maxProducts = maxProducts; if (maxProducts < 0) - throw std::invalid_argument("max number not positive"); - else throw std::logic_error("not implemented yet"); + else { + maxProducts = _maxProducts; + ptr = new Product[_maxProducts]; + } + } ~Catalog() { // TODO: implement this function properly - delete & maxProducts; - if (maxProducts < 0) - throw std::invalid_argument("max number not positive"); - else - throw std::logic_error("not implemented yet"); + delete[] ptr; + ptr = NULL; + } // Accessors. int getMaxProducts() const { // TODO: implement this function properly if (maxProducts < 0) - throw std::invalid_argument("max number not positive"); - else if (maxProducts > 0) - return maxProducts; - else throw std::logic_error("not implemented yet"); + else + return maxProducts; } int getNumProducts() const { // TODO: implement this function properly - if (numProducts < 0) - throw std::invalid_argument("number of products not positive"); - else if (numProducts > 0) - return numProducts; - else - throw std::logic_error("not implemented yet"); + return numProducts; } // Return true when the catalog cannot fit any more products. bool isFull() const { // TODO: implement this function properly - if (numProducts == maxProducts) - return true; - else if (numProducts != maxProducts) - return false; - else - throw std::logic_error("not implemented yet"); + return (numProducts == maxProducts); } // Add a new product to the catalog with a given code and name. @@ -115,23 +110,35 @@ class Catalog { // // Code must be different from all the product codes already in the // database. If it's not, throw std::invalid_argument. - void addProduct(const std::string& code, - const std::string& name, - double price) { + void addProduct(const std::string& _code, + const std::string& _name, + double _price) { // TODO: implement this function properly - std::string code = code; - std::string name = name; - price = price; - - if (price < 0) - throw std::invalid_argument("price is invalid"); - - else if (isFull()) - throw std::overflow_error("already full"); - else if (code == code) - throw std::invalid_argument("already in the database"); - else - throw std::logic_error("not implemented yet"); + for (int i = 0; i < numProducts; i++) { + if (isFull()) + { + throw std::logic_error("not implemented yet"); + } + else + { + if (ptr[i].getCode() == _code) + { + throw std::logic_error("not implemented yet"); + } + else + { + if (_price < 0) + { + throw std::logic_error("not implemented yet"); + } + else + { + ptr[numProducts-1] = Product(_code, _name, _price); + } + } + } + } + numProducts++; } // Find a product by its code. @@ -142,17 +149,26 @@ class Catalog { // // Throw std::invalid_argument if no product with that code exists // in the catalog. - const Product& findCode(const std::string& code) const { + const Product& findCode(const std::string& _code) const + { // TODO: implement this function properly - cout << &code; - if (code != code) - throw std::invalid_argument("code does not exist"); - else - throw std::logic_error("not implemented yet"); + + for (int i = 0; i < numProducts; i++) + { + if (ptr[i].getCode() == _code) + { + return ptr[i]; + } + else + { + throw std::logic_error("not implemented yet"); + } + } } private: // TODO: add data members + Product *ptr; int maxProducts; int numProducts; }; From ca0e646e135de791035453ff5f93c08b7f3b0c53 Mon Sep 17 00:00:00 2001 From: mafredi Date: Tue, 11 Oct 2016 17:58:19 -0700 Subject: [PATCH 05/11] Update catalog.hpp --- catalog.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/catalog.hpp b/catalog.hpp index 7b1ad46..be8a9a9 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -8,6 +8,7 @@ #include #include + // A product represents one particular kind of product, such as apples // or cereal. class Product { From 63592be203a00330122df4616555d55ba2dd4c5c Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 20:29:54 -0700 Subject: [PATCH 06/11] Update catalog.hpp --- catalog.hpp | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index be8a9a9..bb591ca 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -8,7 +8,6 @@ #include #include - // A product represents one particular kind of product, such as apples // or cereal. class Product { @@ -34,7 +33,7 @@ class Product { double _price) { // TODO: implement this function properly if (_price < 0 || _code.length() > 14) { - throw std::logic_error("not implemented yet"); + throw std::invalid_argument("not implemented yet"); } else { name = _name; @@ -66,9 +65,12 @@ class Catalog { // std::invalid_argument. Catalog(int _maxProducts) { // TODO: implement this function properly - if (maxProducts < 0) - throw std::logic_error("not implemented yet"); - else { + if (_maxProducts < 0) + { + throw std::invalid_argument("not implemented yet"); + } + else + { maxProducts = _maxProducts; ptr = new Product[_maxProducts]; } @@ -85,9 +87,9 @@ class Catalog { // Accessors. int getMaxProducts() const { // TODO: implement this function properly - if (maxProducts < 0) - throw std::logic_error("not implemented yet"); - else + /*if (maxProducts < 0) + throw std::invalid_argument("not implemented yet"); + else*/ return maxProducts; } @@ -99,7 +101,13 @@ class Catalog { // Return true when the catalog cannot fit any more products. bool isFull() const { // TODO: implement this function properly - return (numProducts == maxProducts); + if (numProducts == maxProducts) { + return true; + + } + else { + return false; + } } // Add a new product to the catalog with a given code and name. @@ -118,19 +126,19 @@ class Catalog { for (int i = 0; i < numProducts; i++) { if (isFull()) { - throw std::logic_error("not implemented yet"); + throw std::invalid_argument("not implemented yet"); } else { if (ptr[i].getCode() == _code) { - throw std::logic_error("not implemented yet"); + throw std::invalid_argument("not implemented yet"); } else { if (_price < 0) { - throw std::logic_error("not implemented yet"); + throw std::invalid_argument("not implemented yet"); } else { @@ -154,19 +162,24 @@ class Catalog { { // TODO: implement this function properly + bool found = false; for (int i = 0; i < numProducts; i++) { if (ptr[i].getCode() == _code) { return ptr[i]; + found = true; } - else - { - throw std::logic_error("not implemented yet"); - } + //else + //{ + // throw std::logic_error("not implemented yet"); + //} } + if(!found) + throw std::invalid_argument("not implemented yet"); } + private: // TODO: add data members Product *ptr; From 22d729f5b2d04e3418a5a6be8eb6600a4b39d1a1 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 21:16:36 -0700 Subject: [PATCH 07/11] Update catalog.hpp --- catalog.hpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index bb591ca..bd96fd4 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -65,7 +65,7 @@ class Catalog { // std::invalid_argument. Catalog(int _maxProducts) { // TODO: implement this function properly - if (_maxProducts < 0) + if (_maxProducts <= 0) { throw std::invalid_argument("not implemented yet"); } @@ -124,30 +124,26 @@ class Catalog { double _price) { // TODO: implement this function properly for (int i = 0; i < numProducts; i++) { - if (isFull()) + if (ptr[i].getCode() == _code) { throw std::invalid_argument("not implemented yet"); } - else + if (_price < 0) { - if (ptr[i].getCode() == _code) - { - throw std::invalid_argument("not implemented yet"); - } - else - { - if (_price < 0) - { - throw std::invalid_argument("not implemented yet"); - } - else - { - ptr[numProducts-1] = Product(_code, _name, _price); - } - } + throw std::invalid_argument("not implemented yet"); } + } - numProducts++; + + if (isFull()) { + throw std::overflow_error("not implemented yet"); + } + else + { + //ptr[numProducts] = new Product(_code, _name, _price); + numProducts++; + } + //numProducts++; } // Find a product by its code. From 27975d00856c1d3dd0010fceb3778503904dee87 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 22:22:25 -0700 Subject: [PATCH 08/11] Update catalog.hpp --- catalog.hpp | 58 +++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index bd96fd4..6863857 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -42,7 +42,6 @@ class Product { } } - ~Product() { } // Accessors. const std::string& getCode() const { return code; } @@ -65,6 +64,10 @@ class Catalog { // std::invalid_argument. Catalog(int _maxProducts) { // TODO: implement this function properly + if (maxProducts > 130000) + { + maxProducts = 130000; + } if (_maxProducts <= 0) { throw std::invalid_argument("not implemented yet"); @@ -72,7 +75,7 @@ class Catalog { else { maxProducts = _maxProducts; - ptr = new Product[_maxProducts]; + ptr = new Product[maxProducts]; } } @@ -123,27 +126,27 @@ class Catalog { const std::string& _name, double _price) { // TODO: implement this function properly - for (int i = 0; i < numProducts; i++) { - if (ptr[i].getCode() == _code) - { - throw std::invalid_argument("not implemented yet"); - } - if (_price < 0) - { - throw std::invalid_argument("not implemented yet"); - } - + + if (isFull()) + { + throw std::overflow_error("No entry can be made, Catalog is full"); } - - if (isFull()) { - throw std::overflow_error("not implemented yet"); - } + if(!isFull()) + { + if (_price <= 0.0) + throw std::invalid_argument("Error: Price must be greater than 0."); else - { - //ptr[numProducts] = new Product(_code, _name, _price); - numProducts++; + { + for (int i = 0; i < numProducts; i++) + { + if (ptr[i].getCode() == _code) + throw std::invalid_argument("not implemented yet"); + } } - //numProducts++; + } + Product temp(_code, _name, _price); + ptr[numProducts] = temp; + numProducts++; } // Find a product by its code. @@ -157,22 +160,15 @@ class Catalog { const Product& findCode(const std::string& _code) const { // TODO: implement this function properly - - bool found = false; - for (int i = 0; i < numProducts; i++) + for (int i = 0; i < numProducts; i++) { - if (ptr[i].getCode() == _code) + if (ptr[i].getCode() == _code) { return ptr[i]; - found = true; } - //else - //{ - // throw std::logic_error("not implemented yet"); - //} + } - if(!found) - throw std::invalid_argument("not implemented yet"); + throw std::invalid_argument("not implemented yet"); } From ce7de5083897e11e15843ca3c29b0b5d0f164f51 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 22:35:27 -0700 Subject: [PATCH 09/11] Update catalog.hpp --- catalog.hpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index 6863857..61ded0a 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -33,7 +33,7 @@ class Product { double _price) { // TODO: implement this function properly if (_price < 0 || _code.length() > 14) { - throw std::invalid_argument("not implemented yet"); + throw std::invalid_argument("price must be positive and code length must be 14"); } else { name = _name; @@ -68,13 +68,13 @@ class Catalog { { maxProducts = 130000; } - if (_maxProducts <= 0) + maxProducts = _maxProducts; + if (maxProducts <= 0) { - throw std::invalid_argument("not implemented yet"); + throw std::invalid_argument("max must be positive integer"); } - else + else { - maxProducts = _maxProducts; ptr = new Product[maxProducts]; } @@ -84,16 +84,13 @@ class Catalog { // TODO: implement this function properly delete[] ptr; ptr = NULL; - + } // Accessors. int getMaxProducts() const { // TODO: implement this function properly - /*if (maxProducts < 0) - throw std::invalid_argument("not implemented yet"); - else*/ - return maxProducts; + return maxProducts; } int getNumProducts() const { @@ -126,27 +123,27 @@ class Catalog { const std::string& _name, double _price) { // TODO: implement this function properly - + if (isFull()) { throw std::overflow_error("No entry can be made, Catalog is full"); } - if(!isFull()) - { + if (!isFull()) + { if (_price <= 0.0) - throw std::invalid_argument("Error: Price must be greater than 0."); + throw std::invalid_argument("Price must be greater than 0."); else - { + { for (int i = 0; i < numProducts; i++) { if (ptr[i].getCode() == _code) - throw std::invalid_argument("not implemented yet"); + throw std::invalid_argument("Already exist"); } } } - Product temp(_code, _name, _price); - ptr[numProducts] = temp; - numProducts++; + Product temp(_code, _name, _price); + ptr[numProducts] = temp; + numProducts++; } // Find a product by its code. @@ -157,7 +154,7 @@ class Catalog { // // Throw std::invalid_argument if no product with that code exists // in the catalog. - const Product& findCode(const std::string& _code) const + const Product& findCode(const std::string& _code) const { // TODO: implement this function properly for (int i = 0; i < numProducts; i++) @@ -166,9 +163,9 @@ class Catalog { { return ptr[i]; } - + } - throw std::invalid_argument("not implemented yet"); + throw std::invalid_argument("search failed"); } From f2d5953baf031d168e39cdd8273c8cccedef4c70 Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 22:48:32 -0700 Subject: [PATCH 10/11] Update catalog.hpp --- catalog.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/catalog.hpp b/catalog.hpp index 61ded0a..a0ae1bf 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -64,9 +64,9 @@ class Catalog { // std::invalid_argument. Catalog(int _maxProducts) { // TODO: implement this function properly - if (maxProducts > 130000) + if (_maxProducts > 130000) { - maxProducts = 130000; + _maxProducts = 130000; } maxProducts = _maxProducts; if (maxProducts <= 0) From 4594544182d3a04a5b35149fd404ac3cdbe801df Mon Sep 17 00:00:00 2001 From: Sarah Nuno Date: Tue, 11 Oct 2016 22:54:53 -0700 Subject: [PATCH 11/11] Update catalog.hpp --- catalog.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalog.hpp b/catalog.hpp index a0ae1bf..692eeeb 100644 --- a/catalog.hpp +++ b/catalog.hpp @@ -173,5 +173,5 @@ class Catalog { // TODO: add data members Product *ptr; int maxProducts; - int numProducts; + int numProducts = 0; };