(续)计算器 v1.5.1 学习生成windows窗口(项目要求启动器)

要求:

1.增加更新公告栏

2.加载效果

重点 3.启动器

4.修改了输入x/0是得出结果是nan或inf的问题

1.公告栏

输出更新的内容,使用cout实现即可。

cout << "                               计算器v1.5.1               " << endl; 
	cout << "                                 更新公告         \n";
	cout << "1.更新了错误系统\n";
	cout << "2.更新了除以0时得出结果为nan或inf的问题,改为报错并退出\n";
	cout << "3.更新了加载动画"; 
2.加载效果

   1.使用Sleep停止时间

  2.输出一些与计算符有关的字符(如+-*/等)

实现代码:

    system("cls");   //清空控制台
	cout << "请稍等计算器组件......\n";
	Sleep(2000); 
	cout << "正在进入计算器...";
	cout << "/";
	Sleep(200);
	cout << "*";
	Sleep(150);
	cout << "-";
	Sleep(240);
	cout << "+";
	Sleep(160);
	cout << "$";
	Sleep(190);
	cout << "%";
	Sleep(290);
	cout << "^";
	Sleep(320);
	cout << "&";
	Sleep(180);
	cout << "=";
	Sleep(185);
	cout << "<";
	Sleep(175);
	cout << ">";
	Sleep(195);
	cout << "@";
	Sleep(650);
	cout << "(";
	Sleep(785);
	cout << ")";
	Sleep(900);
	cout << "~";
	Sleep(2000); 
	cout << endl; 
	cout << "加载完成"; 
	Sleep(1500);
	system("cls");

代码中使用system中的cls来清除控制台中的内容

运行效果:

 

 字符串加载

 加载快结束时

 加载完成

3. 重点内容

    窗口组件项目

要求:

1.能够打开计算器.exe这个文件

2.是一个窗口应用,不能出现控制台

Dev-cpp创建窗口:

1.新建文件

2.选择新建项目

3.选择Windows Application

4.不要管dev自动生成的代码,把它们先删除

 5.生成了一个窗口

Visual Studio创建窗口:

1.运行vs

2.点击文件选项卡,新建C++项目, 选择windows桌面向导或桌面应用程序

 3.配置项目

4.删除生成的代码

接下来要讲关于MessageBox()关键字的用法

1.MessageBox是生成窗口的关键

关键字使用方法如下:

MessageBox(NULL,("内容"),("标题"),按钮选项|图标icon);

按钮选项有很多,我建议看这篇文章效果更好:

C/C++ MessageBox() 弹窗的用法_Linux 开发者的博客-CSDN博客

修改后的计算器源代码:

#include <bits/stdc++.h>
#include <math.h>
#include <iomanip>
#include <windows.h> 
using namespace std;

int jia(float num1, float num2)
{
    float sum = num1 + num2;
    cout << "运算完成!结果为\n " << sum << endl;
    return sum;
}

int jian(float num1, float num2)
{
    float sum = num1 - num2;
    cout << "运算完成!结果为\n " << sum << endl;
    return sum;
}

int cheng(float num1, float num2)
{
    float sum = num1 * num2;
    cout << "运算完成!结果为\n " << sum << endl;
    return sum;
}

int chu(float num1, float num2)
{
    float sum = num1 / num2;
    cout << "运算完成!结果为\n " << sum << endl;
    return sum;
}

int qvmo(int num1, int num2)
{
    int sum = num1 % num2;
    cout << "运算完成!结果为\n " << sum << endl;
    return sum;
}

int kf(long double num1,long double num2)
{
	long double sum1 = sqrt(num1);
	long double sum2 = sqrt(num2);
	cout << "运算完成!结果数1为\n " << setiosflags(ios::fixed)<<setprecision(50)<< sum1 << endl;
	cout << "运算完成!结果数2为\n " << setiosflags(ios::fixed)<<setprecision(50)<< sum2 << endl;
	return sum1;
	return sum2;
	
}

int pf(long double num1,long num2)   //num1为底数 num2为指数 
{
	long sum = pow(num1,num2);
	cout << "运算完成!结果为:" << sum << endl;
	return sum;
}

int jdz(int num1,int num2){
	int sum1 = abs(num1);
	int sum2 = abs(num2);
	cout << "运算完成!结果1为:" << sum1 << endl;
	cout << "运算完成!结果2为:" << sum2 << endl;
	return sum1;
	return sum2;
}

int xsjdz(double num1,double num2){
	double sum1 = fabs(num1);
	double sum2 = fabs(num2);
	cout << "运算完成!结果1为:" << sum1 << endl;
	cout << "运算完成!结果2为:" << sum2 << endl;
	return sum1;
	return sum2;
}

int Syuan(double num1,double num2){
	double sum1 = pow(num1,2) * 3.14;  
	double sum2 = pow(num2,2) * 3.14;
	cout << "运算完成!圆1面积为:" << sum1 << endl;
	cout << "运算完成!圆2面积为:" << sum2 << endl;
	return sum1;
	return sum2;
}

int Vqiu(double num1,double num2){
	double sum1 = 4.0/3*3.14*num1*num1*num1;
	double sum2 = 4.0/3*3.14*num2*num2*num2;
	cout << "运算完成!球体1体积为:" << sum1 << endl;
	cout << "运算完成!球体2体积为:" << sum2 << endl;
	return sum1;
	return sum2;
}

int Vzhui(double num1,double num2){
	double sum = 1.0/3*(3.14*num1*num1)*num2;
	cout << "运算完成!圆锥体积为:" << sum << endl;
	return sum;
}

int Vyz(double num1,double num2){
	double sum = 3.14*num1*num1*num2;
	cout << "运算完成!圆柱体积为:" << sum << endl;
	return sum;
} 
int main()
{
	system("color a");
	cout << "                               计算器v1.5.1               " << endl; 
	cout << "                                 更新公告         \n";
	cout << "1.更新了错误系统\n";
	cout << "2.更新了除以0时得出结果为nan或inf的问题,改为报错并退出\n";
	cout << "3.更新了加载动画"; 
	Sleep(5000);
	system("cls");
	cout << "请稍等计算器组件......\n";
	Sleep(2000); 
	cout << "正在进入计算器...";
	cout << "/";
	Sleep(200);
	cout << "*";
	Sleep(150);
	cout << "-";
	Sleep(240);
	cout << "+";
	Sleep(160);
	cout << "$";
	Sleep(190);
	cout << "%";
	Sleep(290);
	cout << "^";
	Sleep(320);
	cout << "&";
	Sleep(180);
	cout << "=";
	Sleep(185);
	cout << "<";
	Sleep(175);
	cout << ">";
	Sleep(195);
	cout << "@";
	Sleep(650);
	cout << "(";
	Sleep(785);
	cout << ")";
	Sleep(900);
	cout << "~";
	Sleep(2000); 
	cout << endl; 
	cout << "加载完成"; 
	Sleep(1500);
	system("cls");
	cout << "                       计算器version1.5.1                   " << endl; 
    start:
    cout <<"特别提示:如果是空值就填0!" << endl;
    double num1;
    double num2;
    cout << "输入数字1的数值: " ;
    cin >> num1;
    cout << "输入数字2的数值: ";
    cin >> num2;
    cout << "输入13以上的数退出!"<<endl;
	cout << "你要进行什么运算?"<<endl << "1为加法运算" << endl << "2为减法运算\n3为乘法运算\n4为除法运算\n5为取模\n6为开方(取小数点后50位)\n7为平方计算\n8为整数绝对值\n9为小数绝对值\n10为圆面积计算(请输入半径)\n11为球体体积计算(请输入半径)\n12为圆锥体积计算(数字1为半径,数字2为高度)\n13计算圆柱体积(数字1为半径,数字2为高)\n" << endl; 
    cout << "请输入你要进行的操作:"; 
	int yunsuan = 0;
    cin >> yunsuan;

    if (yunsuan == 1) {
        float sum = jia(num1, num2);
        goto start;
    }

    if (yunsuan == 2) {
        float sum = jian(num1, num2);
        goto start;
    }

    if (yunsuan == 3) {
        float sum = cheng(num1, num2);
        goto start;
    }

    if (yunsuan == 4) {
    	if(num2 == 0){
    		cout << "[Error][Error Code:2]错误的运算,不能除以0";
			return 0; 
		}
        float sum = chu(num1, num2);
        goto start;
    }

    if (yunsuan == 5) {
        float sum = qvmo(num1, num2);
        goto start;
    }
    
    if (yunsuan == 6){
    	long double sum = kf(num1,num2);
    	goto start;
	}
	
	if (yunsuan == 7){
		long sum = pf(num1,num2);
		goto start;
	}
	
	if (yunsuan == 8){
		int sum = jdz(num1,num2);
		goto start;
	}
	if (yunsuan == 9){
		int sum = xsjdz(num1,num2);
		goto start;
	}
	if (yunsuan == 10){
		int sum = Syuan(num1,num2);
		goto start;
	}
	if (yunsuan == 11){
		int sum = Vqiu(num1,num2);
		goto start; 
	}
	if (yunsuan == 12){
		int sum = Vzhui(num1,num2);
		cout << "结果计算为取小数点后5位数";
		goto start;
	}
	if (yunsuan == 13){
		int sum = Vyz(num1,num2);
		goto start;
	} 
	if (yunsuan <= 14){
    	cout << endl << "[Error][Error Code:1] 运算程序意外退出!"; 
    	return 0;
    }
    if (yunsuan >= 0){
    	cout << endl << "[Error][Error Code:1] 运算程序意外退出!"; 
    	return 0;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值