C++模拟Windows系统(第5集)

Hello,我是老六工作室,今天我们优化一下代码。(以后每五集就会优化一次)

原代码:

#define n1 532

#define D 250

#include<iostream>

#include<windows.h>

using namespace std;

void sound()

{

Beep(n1,D);

}

int setting()

{

cout<<"设置 Setting"<<endl;

cout<<"1:停止运行Windows C++"<<endl;

cout<<"2:参数"<<endl;

cout<<"3:关闭设置"<<endl;

int a;

cin>>a;

switch (a)

{

case 1:

{

cout<<"停止Windows C++运行中...";

_sleep(1000);

return 0;

}

case 2:cout<<"【老六工作室】制作"<<endl;

}

return 0;

}

void user_handbook()

{

cout<<"O键打开,W键关闭,C键复制,V键粘贴。"<<endl;

_sleep(2000);

}

int main()

{

system("title Windows C++");

cout<<"Opening";

cout<<".";

_sleep(100);

cout<<".";

_sleep(100);

cout<<".";

_sleep(100);

string username;

cout<<endl;

cout<<"欢迎使用~"<<endl;

cout<<"[初始化1/2]请输入用户名:";

cin>>username;

string password;

cout<<"[初始化2/2]请输入密码:";

cin>>password;

int len=password.length();

while(len<6){

cout<<"请重新输入(6位以上):";

cin>>password;

len=password.length();

}

//system("start https://baidu.com"); 浏览器

return 0;

}

优化1-使用手册

更改:

①输出“使用手册”字样

②按任意键继续:用getch()实现,同时增加conio.h头文件

void user_handbook()

{

cout<<"使用手册:O键打开,W键关闭,C键复制,V键粘贴。"<<endl;

_sleep(2000);

cout<<"请按任意键继续...";

getch();

cout<<endl;

}

优化2-开机效果

更改:

①开机动画:新建函数openshow

②初始化前清屏

void openshow()

{

for(float i=0;i<=100;i+=0.3)

{

if(i<=25)

cout<<"系统设置中("<<i<<"%)..."<<endl;

else if(i<=50)

cout<<"数据加载中("<<i<<"%)..."<<endl;

else if(i<=75)

cout<<"文件解压中("<<i<<"%)..."<<endl;

else cout<<"设备调试中("<<i<<"%)..."<<endl;

_sleep(50);

system("cls");

}

}

优化3-初始化

更改:

①将初始化放入函数

②初始化后清屏

void initialize()

{

cout<<endl;

cout<<"欢迎使用~"<<endl;

cout<<"[初始化1/2]请输入用户名:";

cin>>username;

cout<<"[初始化2/2]请输入密码:";

cin>>password;

int len=password.length();

while(len<6){

cout<<"请重新输入(6位以上):";

cin>>password;

len=password.length();

}

system("cls");

}

现在的代码如下:

#define n1 532
#define D 250
#include<iostream>
#include<windows.h>
#include<conio.h>
using namespace std;
string username;
string password;
void openshow()
{
    for(float i=0;i<=100;i+=0.3)
    {
        if(i<=25)
        cout<<"系统设置中("<<i<<"%)..."<<endl;
        else if(i<=50)
        cout<<"数据加载中("<<i<<"%)..."<<endl;
        else if(i<=75)
        cout<<"文件解压中("<<i<<"%)..."<<endl;
        else cout<<"设备调试中("<<i<<"%)..."<<endl;
        _sleep(50);
        system("cls");
    }
}
void sound()
{
    Beep(n1,D);
}
int setting()
{
    cout<<"设置 Setting"<<endl;
    cout<<"1:停止运行Windows C++"<<endl;
    cout<<"2:参数"<<endl;
    cout<<"3:关闭设置"<<endl;
    int a;
    cin>>a;
    switch (a)
    {
        case 1:
            {
                cout<<"停止Windows C++运行中...";
                _sleep(1000);
                return 0;
            }
        case 2:cout<<"【老六工作室】制作"<<endl;
    }
    return 0;
}
void initialize()
{
    cout<<endl;
        cout<<"欢迎使用~"<<endl;
        cout<<"[初始化1/2]请输入用户名:";
        cin>>username;
        cout<<"[初始化2/2]请输入密码:";
        cin>>password;
        int len=password.length();
        while(len<6){
        cout<<"请重新输入(6位以上):";
        cin>>password;
        len=password.length();
        }
        system("cls");
}
void user_handbook()
{
    cout<<"使用说明:O键打开,W键关闭,C键复制,V键粘贴。"<<endl;
    _sleep(2000);
    cout<<"请按任意键继续...";
    getch();
    cout<<endl;
}
int main()
{
    system("title Windows C++");
    openshow();
    initialize();
    user_handbook();
    //system("start https://baidu.com");   浏览器
    return 0;
}

今天的C++ Windows就结束了,我们下期再见!

(阅读量满100加速更新哦)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值