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;
    }
  • 相关阅读:
    docker 的官方PHP镜像 如何修改 php.ini 配置
    数据结构和算法
    接口的幂等性
    linux ftp服务器设置,只允许用户访问指定的文件夹,禁止访问其他文件夹
    rabitmq + php
    微信上传客服消息图片
    golang Printf 函数有超过 10 个转义字符
    golang bufio.NewScarme
    springboot(一)
    springboot加入第三方jar,使用mvn打包
  • 原文地址:https://www.cnblogs.com/xkxf/p/6268679.html
Copyright © 2011-2022 走看看