zoukankan      html  css  js  c++  java
  • c++第四天

    // 练习 1.20
    #include<iostream>
    #include "Sales_item.h"
    
    int main()
    {
        Sales_item item_temp;
        
        while(std::cin >> item_temp)
            std::cout << item_temp << std::endl;
        return 0;
    }
    // 练习 1.21
    #include<iostream>
    #include "Sales_item.h"
    
    int main()
    {
        Sales_item item1, item2;
        
        std::cin >> item1 >> item2;
        std::cout << item1 + item2 << std::endl;
        return 0;
    }
    // 练习 1.22
    #include<iostream>
    #include "Sales_item.h"
    
    int main()
    {    
        // currItem是我们正在统计的销售记录; 我们将读入的记录存入item
        Sales_item currItem, item;
        // 读取第一条记录, 并确保有记录可以处理
        if(std::cin >> currItem){
            Sales_item sum_item = currItem;        // 保存已经统计的销售记录
            
            while(std::cin >> item)                // 读取剩余记录
                if(item.isbn == currItem.isbn)    // 如果书的isbn相同
                    sum_item += item;            // 将销售记录统计到sum_item
            std::cout << sum_item << std::endl;    // 打印销售记录
        }
        return 0;
    }
    // 练习 1.23 
    // 练习 1.24
    #include<iostream>
    #include "Sales_item.h"
    
    int main()
    {
        Sales_item currItem, item;
        
        if(std::cin >> currItem){
            int cnt = 1;
            while(std::cin >> item)
                if(item.isbn == currItem.isbn)
                    ++cnt;
                else{
                    std::cout << currItem.isbn << " " << cnt << std::endl;
                    currItem = item;
                    cnt = 1;
                }
            std::cout << currItem.isbn << " " << cnt << std::endl;
        }
        return 0;
    }
    
    // 测试数据:
    // 0-201-78345-X 4 25.0
    // 0-201-78345-X 1 25.0
    // 0-201-78345-X 2 25.0
    // 0-201-78345-X 9 25.0
    // 0-207-78345-X 9 31.0
    // 0-207-78345-X 3 31.0
    // 0-202-78345-X 3 20.0
    // 0-202-78345-X 3 20.0
    // 运行结果:
    // 0-201-78345-X 4
    // 0-207-78345-X 2
    // 0-202-78345-X 2
    // 练习 1.25
    #include<iostream>
    #include "Sales_item.h"
    
    int main()
    {
        Sales_item total;
        
        if(std::cin >> total){
            Sales_item trans;
            
            while(std::cin >> trans){
                if(total.isbn == trans.isbn)
                    total += trans;
                else{
                    std::cout << total << std::endl;
                    total = trans;
                }
            }
            std::cout << total << std::endl;
        }else{
            std::cerr << "No data?!" << std::endl;
            return -1;
        }
        return 0;
    }
  • 相关阅读:
    解决:信息中插入avi格式的视频时,提示“unsupported video format”
    java字节数组和16进制之间的转换
    16进制转换字节数组工具类
    如何在ubuntu 12.04 中安装经典的 GNOME桌面
    Ubuntu安装软件提示”需要安装不能信任的软件包”解决办法
    Ubuntu系统下运行Eclipse出现找不到jre的问题的解决方法
    ubuntu添加共享出错
    从scrapy使用经历说开来
    有趣的问题--12 coins problem
    一个奇怪的MySQL错误返回
  • 原文地址:https://www.cnblogs.com/xkxf/p/6268679.html
Copyright © 2011-2022 走看看