14.2.2

来源:互联网 发布:段子精选分享软件 编辑:程序博客网 时间:2024/05/18 01:55

14.9

std::istream& operator>>(std::istream &is, Sales_data &item){    double price = 0.0;    is >> item.bookNo >> item.units_sold >> price;    if (is)        item.revenue = price * item.units_sold;    else        item = Sales_data();    return is;}

14.10

(a) 0-201-99999-9 10 24.95 //正确的输入(b) 10 24.95 0-210-99999-9 //错误的输入,会被重置成一个默认的Sales_date

14.11
没有输入检查。如果输入错误 ,将得到错误的数据

14.12

std::istream& operator>>(std::istream &in, Book &book){    in >> book.no_ >> book.name_ >> book.author_ >> book.pubdate_;    if (in)        ;    else        book = Book();    return in;}
0 0
原创粉丝点击