Advertisement
Guest User

L11Y2015

a guest
May 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Product {
  7. private:
  8.     friend istream& operator >> (istream &stream, Product& product) {
  9.         stream >> product.name >> product.price >> product.quantity;
  10.         return stream;
  11.     }
  12.     friend int getSum(Product &product);
  13.     string name;
  14.     int price;
  15.     int quantity;
  16. };
  17.  
  18. int getSum(Product &product) {
  19.     return product.price * product.quantity;
  20. }
  21.  
  22. int main()
  23. {
  24.     int numberOfProduct = 0;
  25.     int totalSum = 0;
  26.     cout << "Enter number of product: ";
  27.     cin >> numberOfProduct;
  28.  
  29.     cout << '\n';
  30.  
  31.     for (int i = 0; i < numberOfProduct; i++) {
  32.         cout << "Enter data of " << i + 1 << " product: ";
  33.         Product product;
  34.         cin >> product;
  35.         totalSum += getSum(product);
  36.     }
  37.  
  38.     cout << "\nTotal sum: " << totalSum;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement