Question
C++ Lab (ZyLabs 10.22) Help: Online Shopping Cart The instructions are as follows: (1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp -
C++ Lab (ZyLabs 10.22) Help: Online Shopping Cart
The instructions are as follows:
(1) Create three files to submit:
- ItemToPurchase.h - Class declaration
- ItemToPurchase.cpp - Class definition
- main.cpp - main() function
[I still struggle in understanding the difference between declaration and definition, especially in the objective context.]
Build the ItemToPurchase class with the following specifications:
- Default constructor
- Public class functions (mutators & accessors)
- SetName() & GetName() (2 pts)
- SetPrice() & GetPrice() (2 pts)
- SetQuantity() & GetQuantity() (2 pts)
- Private data members
- string itemName - Initialized in default constructor to "none"
- int itemPrice - Initialized in default constructor to 0
- int itemQuantity - Initialized in default constructor to 0
In the .h file, I have:
#include#include #include
using namespace std; class ItemToPurchase { public: void SetName(); string GetName(); void SetPrice(); int GetPrice(); void SetQuantity(); int GetQuantity(); private: string itemName = "none"; int itemPrice = 0; int itemQuantity = 0; };
In the definition .cpp file, thus far, I have:
#include#include #include #include "ItemToPurchase.h"
class ItemToPurchase { public: void SetName() { string name; cout << "Enter the item price:" << endl; getline(cin, name); cout << endl; itemName = name; }; string GetName() {return itemName}; void SetPrice() { int price; cout << "Enter the item price:" << endl; cin >> price; cout << endl; itemPrice = price; }; int GetPrice(); void SetQuantity(); int GetQuantity(); private: string itemName = "none"; int itemPrice = 0; int itemQuantity = 0; };
And in the main, I have:
#include#include #include #include "ItemToPurchase.h" using namespace std; int main() { ItemToPurchase Item; Item.SetName(); cout << Item.GetName() << endl; return 0; }
[In main.cpp, I am just trying to construct an instance of the ItemToPurchase class (default constructors intact), and test the setter / getter functions. Once these are resolved, I should be able to extrapolate. After linking, CLion says ln 10, 11 in main.cpp have undefined references to ItemToPurchase::SetName() / GetName(), followed by what I believe to be dependent errors in the CMake. It would be substantially more helpful to me if you could help me modify / revise my existing code for proper construction, then attempt the rest.]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started