• 第一章


    #include <iostream>
    int main()
    {
    std::cout << "Hello, World" << std::endl;
    return 0;
    }

    1.9while实现50-100和

    #include <iostream>
    using namespace std;
    int main()
    {
            int sum = 0;
            int i = 50;
            while(i <= 100)
            {
                    sum += sum + i;
            }
            cout << sum;
    }

    1.10实现10-0整数

    #include <iostream>
    using namespace std;
    int main()
    {
    int i = 10;
    while(i >= 0)
    {
    cout << i << endl;
    i--;
    }
    return 0;
    }

    1.13 for循环

    #include <iostream>
    using namespace std;
    int main()
    {
            int sum = 0;
            for(int i = 50; i < 101; i++)
            {
                    sum += i;
                    cout << i  << "  " << sum << endl;
            }
            return 0;
    }
    #include <iostream>
    using namespace std;
    int main()
    {
            int v1 = 0, v2 = 0;
            cout << "enter two numbers" << endl;
            cin >> v1 >> v2;
            int sum = 0;
            for(int i = v1; i <= v2; i++)
            {
                    sum += i;
                    cout << i  << "  " << sum << endl;
            }
            return 0;
    }

    1.16 cin一组数据

    #include <iostream>
    using namespace std;
    int main()
    {
            int value = 0;
            int sum = 0;
            cout << "enter one group data: " << endl;
            while (cin >> value)
            {
                    sum = sum + value;
            }
    
            cout << sum << endl;
    
            return 0;
    }

    1.20

    #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编写程序,读取多个具有相同 ISBN 的销售记录,输出所有记录的和

    #include <iostream>
    #include "Sales_item.h"
    using namespace std;
    int main()
    {
            Sales_item item, sum_item;
            cout << "enter some groups of data which ISBN is same." << endl;
            while(cin >> item)
            {
                    sum_item += item;
            }
            std::cout << "The data sum is " <<  sum_item << std::endl;
            return 0;
    }

    1.24输入表示多个 ISBN 的多条销售记录来测试上一个程序,每个 ISBN 的记录应该聚在一起。

    #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;
    }
  • 相关阅读:
    word设置的密码忘了怎么办?
    Navicat Report Viewer 设置 HTTP 的方法
    如何处理Navicat Report Viewer 报表
    excel密码忘记了怎么办
    Beyond Compare文本比较搜索功能详解
    Popular Cows POJ
    Problem B. Harvest of Apples HDU
    网络流模型整理
    The Shortest Statement CodeForces
    Vasya and Multisets CodeForces
  • 原文地址:https://www.cnblogs.com/11ys/p/14593016.html
Copyright © 2020-2023  润新知