Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Joss

#include <iostream>
#include <iomanip>
using namespace std;

#include "ItemToPurchace.h"
using namespace std;
int main() {
    int i;
    const int NUM_ITEMS = 2;
    string name;
    int price;
    int quantity;
    double total;
    ItemToPurchase item1;
    ItemToPurchase item2;
    for (i=0;i < NUM_ITEMS; ++i) {
        cout << "Item" << i + 1 <<endl;
        cout << "Enter the item name:" << endl;
        getline(cin, name);
        
        cout << "Enter the item price:" << endl;
        cin >> price;
        cout << "Enter the item quanity:" << endl;
        cin >> quanity;
        cout << endl;
        if(i==0) {
            item1.SetName(name);
            item1.SetPrice(price);
            item1.SetQuanity(quanity);
            
        }
        else if (i==1) {
            item2.SetName(name);
            item2.SetPrice(price);
            item2.SetQuanity(quanity);
        }
        cin.ignore();
     }
     total = (item1.GetPrice()* item1.GetQuanity()) + (item2.GetPrice()* item2.GetQuanity())
     cout << "TOTAL Cost" << endl;
     item1.Print();
     item2.Print();
     cout << endl;
     cout << "Total: $" << total << endl;
     return 0;
     
     
     
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.