Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- class Product {
- private:
- friend istream& operator >> (istream &stream, Product& product) {
- stream >> product.name >> product.price >> product.quantity;
- return stream;
- }
- friend int getSum(Product &product);
- string name;
- int price;
- int quantity;
- };
- int getSum(Product &product) {
- return product.price * product.quantity;
- }
- int main()
- {
- int numberOfProduct = 0;
- int totalSum = 0;
- cout << "Enter number of product: ";
- cin >> numberOfProduct;
- cout << '\n';
- for (int i = 0; i < numberOfProduct; i++) {
- cout << "Enter data of " << i + 1 << " product: ";
- Product product;
- cin >> product;
- totalSum += getSum(product);
- }
- cout << "\nTotal sum: " << totalSum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement