#include<iostream>
#include<string>
using namespace std;
struct Sale_data
{
string bookNo;
string bookName;
unsigned units_sold = 0;
double revenue = 0.0;
double price = 0.0;
};
int main()
{
Sale_data book;
double price;
cin >> book.bookNo >> book.units_sold >> book.price;
book.revenue = book.units_sold*book.price;
cout << book.bookNo << " " << book.units_sold << " " << book.revenue << endl;
return 0;
}
#include<iostream>
#include<string>
using namespace std;
struct Sale_data
{
string bookNo;
string bookName;
unsigned units_sold = 0;
double revenue = 0.0;
double price = 0.0;
};
int main()
{
Sale_data book1, book2;
double price1, price2;
cin >> book1.bookNo >> book1.units_sold >> price1;
cin >> book2.bookNo >> book2.units_sold >> price2;
book1.revenue = book1.units_sold*price1;
book2.revenue = book2.units_sold*price2;
if (book1.bookNo == book2.bookNo)
{
unsigned totalcnt = book1.units_sold + book2.units_sold;
double totalrevenue = book1.revenue + book2.revenue;
cout << book1.bookNo << " " << totalcnt << " " << totalrevenue << endl;
if (totalcnt != 0)
cout << totalrevenue / totalcnt << endl;
else
cout << "no sales" << endl;
return 0;
}
else
{
cerr << "data must refer to same isbn" << endl;
return -1;
}
}
#include<iostream>
#include<string>
using namespace std;
struct Sale_data
{
string bookNo;
string bookName;
unsigned units_sold = 0;
double revenue = 0.0;
double price = 0.0;
};
int main()
{
Sale_data total;
double totalprice;
if (cin >> total.bookNo >> total.units_sold >> totalprice)
{
total.revenue = total.units_sold*totalprice;
Sale_data trans;
double transprice;
while (cin >> trans.bookNo >> trans.units_sold >> transprice)
{
trans.revenue = trans.units_sold*transprice;
if (total.bookNo == trans.bookNo)
{
total.units_sold += trans.units_sold;
total.revenue += trans.revenue;
}
else
{
cout << total.bookNo << " " << total.units_sold << " " << total.revenue << " ";
if (total.units_sold != 0)
cout << total.revenue / total.units_sold << endl;
else
cout << "no sales" << endl;
total.bookNo = trans.bookNo;
total.units_sold = trans.units_sold;
total.revenue = trans.revenue;
}
}
cout << total.bookNo << " " << total.units_sold << " " << total.revenue << " ";
if (total.units_sold != 0)
cout << total.revenue / total.units_sold << endl;
else
cout << "no sales" << endl;
return 0;
}
else
{
cerr << "no data!" << endl;
return -1;
}
}