Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- #include <iostream>
- #include <string>
- using namespace std;
- class Purchase
- {
- //any member var in the class can be access by the class whether public or private
- private:
- int qty;
- float price;
- string itemName;
- float total;
- public:
- Purchase(){ //Default non parameterized constructor
- qty = 0; price =0.0; itemName = ""; total = 0.0;
- }
- public:
- //setter function
- void set_data(int inQty, float inPrice, string inItemName){
- qty = inQty;
- price = inPrice;
- itemName = inItemName;
- }
- void Calculate(){
- total = qty*price;
- }
- void Print(){
- cout << "Name: "<< itemName << endl;
- cout << "Price: "<< price <<endl;
- cout << "qty: " << qty<< endl;
- cout << "Total: "<< total <<endl;
- }
- /*int getQty(){
- return qty;
- }*/
- //getter function
- /*void getData(int &outQty, float &outPrice, string &outItemName, float &outTotal){
- outQty = qty;
- outPrice = price;
- outItemName = itemName;
- outTotal = total;
- return;
- }*/
- };
- int main(){
- Purchase p1; //F10 step over //F11 step into
- string myItemName;
- int myQty;
- float myPrice;
- cout << "Welcome!\n\n";
- cout << "Enter item: ";
- cin >> myItemName;
- cout <<"Enter price: ";
- cin >> myPrice;
- cout << "Enter item quantity: ";
- cin >>myQty;
- p1.set_data(myQty, myPrice, myItemName);
- p1.Calculate();
- cout << "Receipt!\n\n";
- p1.Print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement