吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1721|回复: 10
收起左侧

[学习记录] [学习笔记]C++17学习第10天

[复制链接]
mdl2999_52pj 发表于 2021-5-25 10:36
# include <iostream>
# include <iomanip>
# include <cctype>
// c++ 17

using namespace std;

int main()
{
    size_t table{};
    const size_t table_min {2};
    const size_t table_max {12};

    char reply {};

    do{
        cout << "What size table would you like (" << table_min << " to " << table_max << ")? ";
        cin >> table;
        cout << endl;
        if (table < table_min || table > table_max)
        {
            cout << "Invalid table size entered. Program terminated." << endl;
            return 1;
        }
        //// 表头
        cout << setw(6) <<" |";
        for(size_t i{1}; i<=table;++i)
        {
            cout << " " << setw(3) << i << " |";
        }
        cout << endl;
        //// 表头横线   
        for(size_t i{}; i<= table; ++i)
        {
            cout << "------" ;
        }
        cout << endl;

        ///// 横列
        for (size_t row{1}; row <= table; ++ row)
        {
            //每列开头
            cout << " " << setw(3) << row << " |";
            //
            for(size_t col{1}; col <= table; ++col)
            {
                cout << " " << setw(3) << row * col << " |";
            }
            // 列尾
            cout << endl;
        }

        cout << "\nDo you want another table (y or n)? ";
        cin >> reply;
    }while(tolower(reply) == 'y');
}


001.png

免费评分

参与人数 5吾爱币 +4 热心值 +5 收起 理由
52pj_wyh + 1 用心讨论,共获提升!
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
tlf + 1 热心回复!
小龙人XX + 1 用心讨论,共获提升!
461735945 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| mdl2999_52pj 发表于 2021-5-25 10:51
# include <iostream>
# include <cctype>
# include <iomanip>
# include <limits>
// c++17
using namespace std;

int main()
{
    cout << setw(11) <<  "Character " << setw(13) <<  "Hexadecimal "  << setw(9) << "Decimal " << endl;
    cout << uppercase;
    unsigned char ch{};
    do{
        if (!isprint(ch))   continue;
        cout << setw(6) << ch 
            << hex << setw(12) << static_cast<int>(ch)
            << dec << setw(10) << static_cast<int>(ch)
            << endl;

    }while(ch++ < numeric_limits<unsigned char>::max());
}


002.png
 楼主| mdl2999_52pj 发表于 2021-5-25 11:15
# include <iostream>
# include <iomanip>
# include <limits>
// c++17
using namespace std;

int main()
{
    constexpr size_t size{1000};
    double val[size] {};
    size_t count {};

    for(;;)
    {
        double input{};
        cout << "Enter a non-zero value, or 0 to end: ";
        cin >> input;

        if (input < numeric_limits<double>::epsilon() && input > -numeric_limits<double>::epsilon())
            // 输入 认为是0 退出
            break;

        val[count++] = input;

        if (count == size)
        {
            cout << "Sorry, I can only store " << size << " values.\n";
            break;
        }

    }
    if (!count)
    {
        cout << "No data.";
        return 0;
    }
    cout << "Starting sort." << endl;
    while(1)
    {
        bool swapped {0};
        for (size_t i{}; i < count-1; ++i)
        {
            if (val[i] >val[i+1])
            {
                swap(val[i], val[i+1]);
                swapped = true;
            }
        }
        if (!swapped)
            break;
    }

    cout << "Your data in ascending sequence:\n" 
        << fixed << setprecision(2);
    for(size_t i{}; i< count ; ++i)
    {
        cout << setw(8) << val[i];
        if (i% 10 == 9)  cout << endl;
    }
    cout << endl;
}


003.png
dxlxh20150521 发表于 2021-5-25 11:17
tan567421 发表于 2021-5-25 11:22
让我们一起学习。
头像被屏蔽
tlf 发表于 2021-5-25 13:30
提示: 作者被禁止或删除 内容自动屏蔽
hinome 发表于 2021-5-25 14:27
一起学习进步。
eleket 发表于 2021-5-25 15:05
支持楼主,一起学习!
柑桔 发表于 2021-5-25 15:37
冲冲冲,楼主分享实用,互勉
lili95 发表于 2021-5-25 15:46
谢谢分享, 一起学习 !
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-20 11:57

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表