2.41

#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;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值