-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path2.41_1.23.cpp
46 lines (46 loc) · 1.11 KB
/
2.41_1.23.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<string>
struct Sales_data
{
std::string ISBN;
double totalPrice;
int amount;
};
int main()
{
Sales_data book1, book2;
double price;
int num = 0;
if(!(std::cin >> book1.ISBN >> book1.amount >> price))
return -1;
book1.totalPrice = price * book1.amount;
num++;
while (std::cin >> book2.ISBN >> book2.amount >> price)
{
book2.totalPrice = price * book2.amount;
if(book1.ISBN == book2.ISBN)
{
book1.amount += book2.amount;
book1.totalPrice += book2.totalPrice;
num++;
}
else
{
std::cout << book1.ISBN << ' ' << book1.amount << ' ' << book1.totalPrice;
if(book1.amount > 0)
std::cout << ' ' << book1.totalPrice / book1.amount << std::endl;
else
std::cout << ' ' << "No Sales!" << std::endl;
std::cout << "num = " << num << std::endl;
num = 1;
book1 = book2;
}
}
std::cout << book1.ISBN << ' ' << book1.amount << ' ' << book1.totalPrice;
if(book1.amount > 0)
std::cout << ' ' << book1.totalPrice / book1.amount << std::endl;
else
std::cout << ' ' << "No Sales!" << std::endl;
std::cout << "num = " << num << std::endl;
return 0;
}