用visual_studio制作的简单的计算器。
C课程设计-仿照Windows设计计算器

《可视化编程技术课程设计》报告题目仿照Windows系统计算器设计计算器1.引言计算器的产生和发展是建立在电子计算机基础之上的,现代社会很需要一个健全、高效率的计算器。
为了提高自己的实践能力和将来开发一个更实用更全能更智能的计算器,以设计与实现计算器为课题。
此次设计的计算器应用软件从visual studio 2012编程环境中开发,是一个简单的窗体应用程序,实现简单的计算器功能。
以微软自带的计算器为模板,设计了简单易懂的计算器。
这款计算器不仅实现了简单的四则运算的功能,还可以进行复杂数学运算,和进制转换(十进制转二进制、八进制、十六进制)。
具有简洁的外观,即时准确的获得所需要要计算的结果,充分降低了数字计算器的难度和所需要的时间,对人们生活和学习具有有很大的帮助。
2. 系统设计(1)功能设计本计算器由四大模块,分别为:1.标准计算器(即为主窗口)2.科学型计算器3.程序员计算器(进制转换)4.开发者介绍(2)界面设计主窗口界面(from1)科学型计算器界面(from2)程序员界面(from3)开发者介绍(from4)1.文本框的设置:textBox1.Text = "0";窗口启动前:Form1.x = 0;//point:1 ;nopoint: 0Form1.a = 0;//1:+ 2:- 3:* 4:/Form1.b = 0;//判D断?是否执行过运算执行过运算Form1.shu1 = 0;Form1.shu2 = 0;Form1.result = 0;2.按键的设置:数字键及小数点:public static void number(object sender, TextBox textBox1){Button btn = (Button)sender;if ( == "one"){if (x == 1)//判断有小数点Ì{textBox1.Text = textBox1.Text + '1';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 1";elsetextBox1.Text = (textBox1.Text + '1').ToString(); }if ( == "two"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '2';return;}if (b != 0){textBox1.Text = "0";b = 0;}textBox1.Text = " 2";elsetextBox1.Text = (textBox1.Text + '2').ToString(); }if ( == "three"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '3';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 3";elsetextBox1.Text = (textBox1.Text + '3').ToString(); }if ( == "four"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '4';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 4";elsetextBox1.Text = (textBox1.Text + '4').ToString(); }if ( == "five"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '5';return;if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 5";elsetextBox1.Text = (textBox1.Text + '5').ToString(); }if ( == "six"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '6';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 6";elsetextBox1.Text = (textBox1.Text + '6').ToString(); }if ( == "seven"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '7';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 7";elsetextBox1.Text = (textBox1.Text + '7').ToString(); }{if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '8';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 8";elsetextBox1.Text = (textBox1.Text + '8').ToString(); }if ( == "nine"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '9';return;}if (b != 0){textBox1.Text = "0";b = 0;}if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 9";elsetextBox1.Text = (textBox1.Text + '9').ToString(); }if ( == "zero"){if (x == 1)//判断有无小数点{textBox1.Text = textBox1.Text + '0';return;}if (b != 0)//两个数的界限判断?{textBox1.Text = "0";b = 0;if (double.Parse(textBox1.Text) == 0)textBox1.Text = " 0";elsetextBox1.Text = (textBox1.Text + '0').ToString();}}public void one_Click(object sender, EventArgs e){number(sender, textBox1);}public void Form1_Load(object sender, EventArgs e){textBox1.Text = "0";}public static void point(object sender, TextBox textBox1){if (double.Parse(textBox1.Text) == 0)x = 1;textBox1.Text = (textBox1.Text + '.').ToString();}public void xiaoshudian_Click(object sender, EventArgs e){point(sender, textBox1);}运算符号1(加减乘除、退格。
y用C#制作计算器(实训的题目)

一、实验题目:用visual studio .NET制作一个简单的计算器二、实验要求:该计算器能实现一般的加、减、乘、除的操作,能进行开方操作,有清除功能(另加求平方功能)。
三、代码实现:Form1.designer的代码:namespace计算器制作2005{partial class Form1{///<summary>///必需的设计器变量。
///</summary>private ponentModel.IContainer components = null;///<summary>///清理所有正在使用的资源。
///</summary>///<param name="disposing">如果应释放托管资源,为true;否则为false</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码?///<summary>///设计器支持所需的方法 - 不要///使用代码编辑-器修改此方法的内容。
///</summary>private void InitializeComponent(){this.show = new System.Windows.Forms.TextBox();this.groupBox1 = new System.Windows.Forms.GroupBox();this.dengyu = new System.Windows.Forms.Button();this.chu = new System.Windows.Forms.Button();this.point = new System.Windows.Forms.Button();this.plusMinus = new System.Windows.Forms.Button();this.num0 = new System.Windows.Forms.Button();this.sqr = new System.Windows.Forms.Button();this.cheng = new System.Windows.Forms.Button();this.num9 = new System.Windows.Forms.Button();this.num8 = new System.Windows.Forms.Button();this.num7 = new System.Windows.Forms.Button();this.pingfang = new System.Windows.Forms.Button();this.minus = new System.Windows.Forms.Button();this.num6 = new System.Windows.Forms.Button();this.num5 = new System.Windows.Forms.Button();this.num4 = new System.Windows.Forms.Button();this.clear = new System.Windows.Forms.Button();this.plus = new System.Windows.Forms.Button();this.num3 = new System.Windows.Forms.Button();this.num2 = new System.Windows.Forms.Button();this.num1 = new System.Windows.Forms.Button();this.menuStrip1 = new System.Windows.Forms.MenuStrip();this.editToolStripMenuItem = newSystem.Windows.Forms.ToolStripMenuItem();this.lookToolStripMenuItem = newSystem.Windows.Forms.ToolStripMenuItem();this.helpToolStripMenuItem = newSystem.Windows.Forms.ToolStripMenuItem();this.groupBox1.SuspendLayout();this.menuStrip1.SuspendLayout();this.SuspendLayout();//// show//this.show.Location = new System.Drawing.Point(19, 38); = "show";this.show.Size = new System.Drawing.Size(244, 21);this.show.TabIndex = 0;this.show.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;this.show.TextChanged += newSystem.EventHandler(this.show_TextChanged);//// groupBox1//this.groupBox1.Controls.Add(this.dengyu);this.groupBox1.Controls.Add(this.chu);this.groupBox1.Controls.Add(this.point);this.groupBox1.Controls.Add(this.plusMinus);this.groupBox1.Controls.Add(this.num0);this.groupBox1.Controls.Add(this.sqr);this.groupBox1.Controls.Add(this.cheng);this.groupBox1.Controls.Add(this.num9);this.groupBox1.Controls.Add(this.num8);this.groupBox1.Controls.Add(this.num7);this.groupBox1.Controls.Add(this.pingfang);this.groupBox1.Controls.Add(this.minus);this.groupBox1.Controls.Add(this.num6);this.groupBox1.Controls.Add(this.num5);this.groupBox1.Controls.Add(this.num4);this.groupBox1.Controls.Add(this.clear);this.groupBox1.Controls.Add(this.plus);this.groupBox1.Controls.Add(this.num3);this.groupBox1.Controls.Add(this.num2);this.groupBox1.Controls.Add(this.num1);this.groupBox1.Location = new System.Drawing.Point(19, 78); = "groupBox1";this.groupBox1.Size = new System.Drawing.Size(244, 167);this.groupBox1.TabIndex = 1;this.groupBox1.TabStop = false;//// dengyu//this.dengyu.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.dengyu.ForeColor = System.Drawing.Color.Red;this.dengyu.Location = new System.Drawing.Point(188, 119); = "dengyu";this.dengyu.Size = new System.Drawing.Size(41, 28);this.dengyu.TabIndex = 23;this.dengyu.Text = "=";eVisualStyleBackColor = true;this.dengyu.Click += new System.EventHandler(this.dengyu_Click);//// chu//this.chu.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.chu.ForeColor = System.Drawing.Color.Red;this.chu.Location = new System.Drawing.Point(143, 119); = "chu";this.chu.Size = new System.Drawing.Size(41, 28);this.chu.TabIndex = 22;this.chu.Text = "/";eVisualStyleBackColor = true;this.chu.Click += new System.EventHandler(this.chu_Click);//// point//this.point.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.point.ForeColor = System.Drawing.Color.Blue;this.point.Location = new System.Drawing.Point(99, 119); = "point";this.point.Size = new System.Drawing.Size(41, 28);this.point.TabIndex = 21;this.point.Text = ".";eVisualStyleBackColor = true;this.point.Click += new System.EventHandler(this.point_Click);//// plusMinus//this.plusMinus.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.plusMinus.ForeColor = System.Drawing.Color.Red;this.plusMinus.Location = new System.Drawing.Point(55, 119); = "plusMinus";this.plusMinus.Size = new System.Drawing.Size(41, 28);this.plusMinus.TabIndex = 20;this.plusMinus.Text = "±¨¤";eVisualStyleBackColor = true;this.plusMinus.Click += new System.EventHandler(this.plusMinus_Click);//// num0//this.num0.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.num0.ForeColor = System.Drawing.Color.Blue;this.num0.Location = new System.Drawing.Point(11, 119); = "num0";this.num0.Size = new System.Drawing.Size(41, 28);this.num0.TabIndex = 19;this.num0.Text = "0";eVisualStyleBackColor = true;this.num0.Click += new System.EventHandler(this.num0_Click);//// sqr//this.sqr.Font = new System.Drawing.Font("宋体”, 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.sqr.ForeColor = System.Drawing.Color.Red;this.sqr.Location = new System.Drawing.Point(188, 87); = "sqr";this.sqr.Size = new System.Drawing.Size(41, 28);this.sqr.TabIndex = 18;this.sqr.Text = "sqrt";eVisualStyleBackColor = true;this.sqr.Click += new System.EventHandler(this.sqr_Click);//// cheng//this.cheng.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.cheng.ForeColor = System.Drawing.Color.Red;this.cheng.Location = new System.Drawing.Point(143, 87); = "cheng";this.cheng.Size = new System.Drawing.Size(41, 28);this.cheng.TabIndex = 17;this.cheng.Text = "*";eVisualStyleBackColor = true;this.cheng.Click += new System.EventHandler(this.cheng_Click);//// num9//this.num9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num9.ForeColor = System.Drawing.Color.Blue;this.num9.Location = new System.Drawing.Point(99, 87); = "num9";this.num9.Size = new System.Drawing.Size(41, 28);this.num9.TabIndex = 16;this.num9.Text = "9";eVisualStyleBackColor = true;this.num9.Click += new System.EventHandler(this.num9_Click);//// num8//this.num8.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.num8.ForeColor = System.Drawing.Color.Blue;this.num8.Location = new System.Drawing.Point(55, 87); = "num8";this.num8.Size = new System.Drawing.Size(41, 28);this.num8.TabIndex = 15;this.num8.Text = "8";eVisualStyleBackColor = true;this.num8.Click += new System.EventHandler(this.num8_Click);//// num7//this.num7.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.num7.ForeColor = System.Drawing.Color.Blue;this.num7.Location = new System.Drawing.Point(11, 87); = "num7";this.num7.Size = new System.Drawing.Size(41, 28);this.num7.TabIndex = 14;this.num7.Text = "7";eVisualStyleBackColor = true;this.num7.Click += new System.EventHandler(this.num7_Click);//// pingfang//this.pingfang.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.pingfang.ForeColor = System.Drawing.Color.Red;this.pingfang.Location = new System.Drawing.Point(188, 55); = "pingfang";this.pingfang.Size = new System.Drawing.Size(41, 28);this.pingfang.TabIndex = 13;this.pingfang.Text = "X²";eVisualStyleBackColor = true;this.pingfang.Click += new System.EventHandler(this.pingfang_Click);//// minus//this.minus.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.minus.ForeColor = System.Drawing.Color.Red;this.minus.Location = new System.Drawing.Point(143, 55); = "minus";this.minus.Size = new System.Drawing.Size(41, 28);this.minus.TabIndex = 12;this.minus.Text = "-";eVisualStyleBackColor = true;this.minus.Click += new System.EventHandler(this.minus_Click);//// num6//this.num6.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num6.ForeColor = System.Drawing.Color.Blue;this.num6.Location = new System.Drawing.Point(99, 55); = "num6";this.num6.Size = new System.Drawing.Size(41, 28);this.num6.TabIndex = 11;this.num6.Text = "6";eVisualStyleBackColor = true;this.num6.Click += new System.EventHandler(this.num6_Click);//// num5//this.num5.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num5.ForeColor = System.Drawing.Color.Blue;this.num5.Location = new System.Drawing.Point(55, 55); = "num5";this.num5.Size = new System.Drawing.Size(41, 28);this.num5.TabIndex = 10;this.num5.Text = "5";eVisualStyleBackColor = true;this.num5.Click += new System.EventHandler(this.num5_Click);//// num4//this.num4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,((byte)(134)));this.num4.ForeColor = System.Drawing.Color.Blue;this.num4.Location = new System.Drawing.Point(11, 55); = "num4";this.num4.Size = new System.Drawing.Size(41, 28);this.num4.TabIndex = 9;this.num4.Text = "4";eVisualStyleBackColor = true;this.num4.Click += new System.EventHandler(this.num4_Click);//// clear//this.clear.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.clear.ForeColor = System.Drawing.Color.Red;this.clear.Location = new System.Drawing.Point(188, 23); = "clear";this.clear.Size = new System.Drawing.Size(41, 28);this.clear.TabIndex = 8;this.clear.Text = "C";eVisualStyleBackColor = true;this.clear.Click += new System.EventHandler(this.clear_Click);//// plus//this.plus.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.plus.ForeColor = System.Drawing.Color.Red;this.plus.Location = new System.Drawing.Point(143, 23); = "plus";this.plus.Size = new System.Drawing.Size(41, 28);this.plus.TabIndex = 3;this.plus.Text = "+";eVisualStyleBackColor = true;this.plus.Click += new System.EventHandler(this.plus_Click);//// num3//this.num3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num3.ForeColor = System.Drawing.Color.Blue;this.num3.Location = new System.Drawing.Point(99, 23); = "num3";this.num3.Size = new System.Drawing.Size(41, 28);this.num3.TabIndex = 2;this.num3.Text = "3";eVisualStyleBackColor = true;this.num3.Click += new System.EventHandler(this.num3_Click);//// num2//this.num2.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num2.ForeColor = System.Drawing.Color.Blue;this.num2.Location = new System.Drawing.Point(55, 23); = "num2";this.num2.Size = new System.Drawing.Size(41, 28);this.num2.TabIndex = 1;this.num2.Text = "2";eVisualStyleBackColor = true;this.num2.Click += new System.EventHandler(this.num2_Click);//// num1//this.num1.Font = new System.Drawing.Font("宋体", 12F,System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.num1.ForeColor = System.Drawing.Color.Blue;this.num1.Location = new System.Drawing.Point(11, 23); = "num1";this.num1.Size = new System.Drawing.Size(41, 28);this.num1.TabIndex = 0;this.num1.Text = "1";eVisualStyleBackColor = true;this.num1.Click += new System.EventHandler(this.button1_Click);//// menuStrip1//this.menuStrip1.Items.AddRange(newSystem.Windows.Forms.ToolStripItem[] {this.editToolStripMenuItem,this.lookToolStripMenuItem,this.helpToolStripMenuItem});this.menuStrip1.Location = new System.Drawing.Point(0, 0); = "menuStrip1";this.menuStrip1.Size = new System.Drawing.Size(292, 24);this.menuStrip1.TabIndex = 2;this.menuStrip1.Text = "menuStrip1";//// editToolStripMenuItem// = "editToolStripMenuItem";this.editToolStripMenuItem.Size = new System.Drawing.Size(57, 20);this.editToolStripMenuItem.Text = "编辑(&E)";//// lookToolStripMenuItem// = "lookToolStripMenuItem";this.lookToolStripMenuItem.Size = new System.Drawing.Size(57, 20);this.lookToolStripMenuItem.Text = "查看(&F)";//// helpToolStripMenuItem// = "helpToolStripMenuItem";this.helpToolStripMenuItem.Size = new System.Drawing.Size(58, 20);this.helpToolStripMenuItem.Text = "帮助(&H)";//// Form1//this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(292, 273);this.Controls.Add(this.groupBox1);this.Controls.Add(this.show);this.Controls.Add(this.menuStrip1);this.MainMenuStrip = this.menuStrip1; = "Form1";this.Text = "软件09302刘志芳";this.groupBox1.ResumeLayout(false);this.menuStrip1.ResumeLayout(false);this.menuStrip1.PerformLayout();this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.TextBox show;private System.Windows.Forms.GroupBox groupBox1;private System.Windows.Forms.Button plus;private System.Windows.Forms.Button num3;private System.Windows.Forms.Button num2;private System.Windows.Forms.Button num1;private System.Windows.Forms.Button clear;private System.Windows.Forms.Button dengyu;private System.Windows.Forms.Button chu;private System.Windows.Forms.Button point;private System.Windows.Forms.Button plusMinus;private System.Windows.Forms.Button num0;private System.Windows.Forms.Button sqr;private System.Windows.Forms.Button cheng;private System.Windows.Forms.Button num9;private System.Windows.Forms.Button num8;private System.Windows.Forms.Button num7;private System.Windows.Forms.Button pingfang;private System.Windows.Forms.Button minus;private System.Windows.Forms.Button num6;private System.Windows.Forms.Button num5;private System.Windows.Forms.Button num4;private System.Windows.Forms.MenuStrip menuStrip1;private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem lookToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; }}Form1.cs的代码:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 计算器制作2005{public partial class Form1 : Form{double a = 0; //放第一个操作数double b=0; //放第二个操作数double sum=0; //最终结果int sign; //操作符public Form1(){InitializeComponent();}/*主要代码实现,对于点击按钮1、2、3 …… 0以及各种运算符的操作( +、-、*、/、* sqrt、X²),还有结果的得出,另外还有针对错误操作的一些处理,例如:当进行除* 法运算时,输入的除数为0,此时系统会有消息框弹出,提示:除数不能为0。
visualstudio设计计算器包括立方

visualstudio设计计算器包括立方
设计一个带有立方功能的计算器是一个有趣且具有挑战性的任务。
使用Visual Studio,我们可以轻松地创建一个用户友好且功能强大的计算器应用程序。
首先,我们需要创建一个Windows窗体应用程序项目。
在MainForm 窗体上,我们可以布置各种控件,如按钮、标签和文本框,以实现计算器的功能。
为了实现基本的计算功能,我们可以为每个按钮添加Click事件处理程序。
例如,当用户按下数字按钮时,相应的数字将显示在文本框中。
当用户按下操作符按钮(如加减乘除)时,我们将记录当前的操作符,并清空文本框以便用户输入下一个数字。
然后,我们需要实现立方功能。
为此,我们可以添加一个按钮,标记为'立方',并为其添加Click事件处理程序。
在此处理程序中,我们将从文本框中获取当前的数字,并将其立方值计算出来。
最后,将结果显示在文本框中。
计算器的另一个重要功能是清除按钮,用户可以使用它来清空当前的计算。
我们可以添加一个'清除'按钮,并为其添加Click事件处理程序,以清空文本框中的内容。
此外,我们可以为计算器添加其他功能,如开方、取反、百分数计算等。
这些功能的实现与立方功能类似,只需添加相应的按钮和处理程序即可。
通过Visual Studio的设计和开发工具,我们可以轻松地创建一个直观且功能强大的计算器应用程序。
使用窗体控件和事件处理程序,我们可以实现各种计算功能,包括立方。
这将使用户能够进行复杂的计算,并以直观的方式获得结果。
c语言制作简单的计算器

c语言制作简单的计算器在计算机编程领域中,C语言是一种广泛使用的编程语言之一。
它具有简单易学的特点,并且能够进行复杂的计算和逻辑处理。
今天,我们就来学习一下如何使用C语言来制作一个简单的计算器。
首先,我们需要明确我们计算器的功能和界面设计。
本次制作的计算器将具有基本的四则运算功能,即加法、减法、乘法和除法。
我们将在控制台中实现计算器的操作,并通过简单的用户界面进行交互。
接下来,我们需要创建一个C语言程序的框架。
首先,我们需要包含头文件,以便在程序中使用各种函数和变量。
我们可以使用"#include" 来引入头文件,例如:```c#include <stdio.h>```然后,我们需要定义主函数 `main()`。
在这个函数中,我们将编写计算器的逻辑代码。
让我们开始编写函数吧!首先,我们需要声明一些变量来存储用户输入的数字和运算符。
我们可以使用 `int` 来定义整数变量,并用 `char` 定义字符变量。
例如:```cint num1, num2, result;char operator;```接下来,我们需要提示用户输入要进行的运算,并读取用户输入的数字和运算符。
我们可以使用 `printf` 和 `scanf` 函数来完成这个任务,例如:```cprintf("请输入第一个数字: ");scanf("%d", &num1);printf("请输入运算符(+, -, *, /): ");scanf(" %c", &operator);printf("请输入第二个数字: ");scanf("%d", &num2);```注意,我们在读取运算符之前添加了空格,这是为了消除输入缓冲区中可能残留的换行符等字符。
接下来,我们需要编写代码来进行实际的计算操作。
vb6.0开发实例 -回复

vb6.0开发实例-回复VB6.0开发实例-一个简单的计算器在VB6.0中,我们可以轻松地创建一个简单的计算器。
计算器是我们日常生活中常见的工具,让我们一步一步地在VB6.0中创建一个简单的计算器,来帮助我们理解和掌握VB编程的基础知识和技巧。
首先,我们需要创建一个新项目。
在VB6.0中,选择“新建”->“标准EXE”创建一个新的窗体应用程序。
接下来,我们需要在窗体上添加一些控件,如文本框、按钮等,以实现计算器的功能。
在VB6.0中,我们可以通过拖动控件到窗体上的方式来添加控件。
第一个控件是一个文本框,用于显示输入的数字和计算结果。
在工具箱中选择文本框控件,然后点击窗体上的位置来添加它。
第二个控件是数字按钮,用于输入数字。
在工具箱中选择按钮控件,然后点击窗体上的位置来添加一个按钮。
我们可以复制该按钮来创建其他数字按钮。
第三个控件是运算符按钮,用于进行加、减、乘、除等计算操作。
同样地,在工具箱中选择按钮控件,然后点击窗体上的位置来添加一个按钮,复制该按钮来创建其他运算符按钮。
接下来,我们需要为这些按钮添加事件处理程序,以实现相应的功能。
在VB6.0中,我们可以通过双击按钮来自动创建一个点击事件的处理程序。
在点击事件中,我们可以使用VB6.0提供的内置函数和运算符来编写计算逻辑。
例如,我们可以使用“+”运算符来进行两个数字的相加,并将结果显示在文本框中。
除了基本的运算功能外,我们还可以为计算器添加其他功能,如清除输入、退格、求平方根等。
这些功能可以使用VB6.0提供的其他内置函数和方法来实现。
最后,我们需要进行界面的美化和调整,以满足用户的需求和审美。
在VB6.0中,我们可以通过更改控件的属性、添加背景和图标等方式来实现界面的美化。
完成所有的功能和界面调整后,我们可以运行程序来测试计算器的功能。
在VB6.0中,我们可以点击“运行”按钮来启动程序,并进行测试和使用。
通过以上的步骤,我们就成功地在VB6.0中创建了一个简单的计算器。
Visual_Basi程序设计圆面积计算器 2

第 1步:常用控件介绍
1.标 签 (Label)
2.文本框(TextBox)
3.命令按钮 (CommandButton)
二、 常用控件
1 . 标 签 (Label) 作用:输出文本,显示提示信息。
名 称
项目用到的标签属性
2.控件属性设置
以Label1的设置方 法为例
第3步:程序设计
1.变量的声明:
Dim 变量名 As 变量数据类型
例: Dim Banjing As Single 声明单精度Banjing变量用来存放圆的半径
2. 单击“计算”按钮时程序设 计 Private Sub Command1_Click() Dim BanJing As Single Dim MianJi As Single BanJing = Val(Text1.Text) If Text1.Text = "" Then MsgBox "请输入圆的半径!", 48, "警告" Text1.SetFocus Exit Sub End If MianJi = 3.1415926 * BanJing * BanJing Text2.Text = MianJi End Sub
说 明
Caption 控件名称 Label1、 Label2
设置标题显示的文本 属性 Caption 值 半径、面积
2. 文本框(TextBox)
作用:用作接收输入的参数及变量的初值。
项目用到的文本框属性ห้องสมุดไป่ตู้
名 称
Text 控件名称 Text1、Text2
说 明
vb.net程序设计案例

以下是一个简单的 程序设计案例,用于实现一个计算器应用程序:打开 Visual Studio,创建一个新的 Windows Forms 应用程序项目。
在 Form1 上添加以下控件:两个 Label 控件,分别命名为 lblNum1 和 lblNum2,用于显示输入的两个数字。
两个 TextBox 控件,分别命名为 txtNum1 和 txtNum2,用于输入两个数字。
四个 Button 控件,分别命名为 btnAdd、btnSubtract、btnMultiply 和 btnDivide,用于执行加、减、乘、除运算。
一个 Label 控件,命名为 lblResult,用于显示运算结果。
为 btnAdd、btnSubtract、btnMultiply 和 btnDivide 按钮分别添加 Click 事件处理程序。
在每个 Click 事件处理程序中,获取 txtNum1 和 txtNum2 中输入的两个数字,并执行相应的运算操作。
将结果显示在 lblResult 中。
以下是一个示例代码:vbPublic Class Form1Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Dim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 + num2lblResult.Caption = result.ToString()End SubPrivate Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 - num2lblResult.Caption = result.ToString()End SubPrivate Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 * num2lblResult.Caption = result.ToString()End SubPrivate Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)If num2 <> 0 ThenDim result As Double = num1 / num2lblResult.Caption = result.ToString()ElseMessageBox.Show("除数不能为0")End IfEnd SubEnd Class这个简单的计算器应用程序可以让用户输入两个数字,并选择执行加、减、乘、除运算操作。
VB写简易计算器附图

用V B6.0编写简易计算器效果图:废话不多说,直接上步骤一、创建控件组1、创建控件组的方法??首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。
这时,第一个按钮的Index属性值默认为“0”,第二个的Index属性值自动设为“1”,并且大小与第一个按钮相同,只需修改其 Caption 属性为数字“1”并将其拖至合适位置即可。
此后继续使用“粘贴”的方法建立其他控件组中其余按钮,共20个按钮,每建立一个,就将它拖到合适处,并修改相应的Caption属性值。
二、编写代码Dim s1 As Single, s2 As Single, ysf As String'定义两个单精度数变量用与存放参与运算的数,一个字符型存放运算符Private Sub Command1_Click(Index As Integer)Text1.Text = Text1.Text & Command1(Index).Caption'将command1的单击事件与文本框显示的内容连接End SubPrivate Sub Command2_Click()Text1.Text = Text1.Text + "."If (InStr(Text1.Text, ".") = 1) Then'第一位不能为小数Text1.Text = ""End IfIf InStr(Text1.Text, ".") < Len(Text1.Text) Then '防止出现两个小数点Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End IfEnd SubPrivate Sub Command3_Click()s2 = Val(Text1.Text) '开始加减乘除运算Select Case ysfCase "+"Text1.Text = s1 + s2Case "-"Text1.Text = s1 - s2Case "*"Text1.Text = s1 * s2Case "/"If s2 = 0 ThenMsgBox "分母不能为零!"Text1.Text = ""ElseText1.Text = s1 / s2End IfEnd SelectText1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text) '这个很关键,如果没有这个的话,得出小于1的小数前面没有0End SubPrivate Sub Command4_Click()If Text1.Text = "" Then '文本为空就结束Exit SubEnd IfText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) '文本退一格End SubPrivate Sub Command5_Click()Text1.Text = "" '清除当前框内文本End SubPrivate Sub Command6_Click(Index As Integer)s1 = Val(Text1.Text) '将s1隐藏起来ysf = Command6(Index).CaptionText1.Text = ""End SubPrivate Sub Command7_Click()If Left(Text1.Text, 1) <> "-" Then '判断作为负数Text1.Text = "-" & Text1.TextElseText1.Text = Right(Text1.Text, Len(Text1.Text) - 1)End IfEnd SubPrivate Sub Command8_Click()Text1.Text = Text1.Text * Text1.Text '平方End Sub各位朋友,可以将红色代码复制到相应位置,不清楚的可以全选复制,但是一定要按照我的步骤和给的名称来哦!还可以再添加按钮Private Sub Command9_Click() '这是退出代码EndEnd Sub三、测试,成功的话给个好评哦!谢谢各位下载与支持!这个可以编写作为作业哦!。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
首先利用visual studio里面的button和textbox模块建立上图模块。
然后就是编写程序:
该程序最重要的是要理解清楚计算器的运算逻辑。
public partial class Form1 : Form
{
string a, b, q, ac;
int c = 0, d = 0, n = 0, p = 0, m = 0;
double temp1 = -1;
int pos = 0;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public void addNum(int num)
{
textBox1.Text = textBox1.Text +
num.ToString();
if (c > 0) // 管¨¹理¤¨ª加¨®减?乘?除y运?算?
{
textBox1.Text = "";
a = num.ToString();
b = b + a;
textBox1.Text = b;
}
}
private void button1_Click(object sender, EventArgs e)
{
addNum(7); //向¨°显?示º?屏¨¢加¨®字Á? n++;
}
private void button2_Click(object sender, EventArgs e)
{
addNum(8);
}
private void button3_Click(object sender, EventArgs e)
{
addNum(9);
}
EventArgs e)
{
addNum(4);
}
private void button6_Click(object sender, EventArgs e)
{
addNum(5);
}
private void button7_Click(object sender, EventArgs e)
{
addNum(6);
}
EventArgs e)
{
addNum(1);
}
private void button10_Click(object sender, EventArgs e)
{
addNum(2);
}
private void button11_Click(object sender, EventArgs e)
{
addNum(3);
}
private void button14_Click(object sender, EventArgs e)
{
addNum(0);
}
private void button15_Click(object sender, EventArgs e)
{
if (p==0)
textBox1.Text = textBox1.Text + ".";//加¨®上¦?小?数ºy点Ì?
p++;
m++;
if (c > 0) // 管¨¹理¤¨ª加¨®减?乘?除y运?算?
{
b = b + ".";
}
}
private void button4_Click(object sender, EventArgs e)
{
pos = 1;
temp1 = Convert .ToDouble (textBox1.Text); textBox1.Text =temp1+"+";
d++;
c++;
p = 0;
}
private void button8_Click(object sender, EventArgs e)
{
pos = 2;
temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + "-";
c++; p = 0;
}
private void button12_Click(object sender, EventArgs e)
{
pos = 3;
temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + "*";
c++; p = 0;
}
private void button16_Click(object sender, EventArgs e)
{
pos = 4;
temp1 = Convert.ToDouble(textBox1.Text); textBox1.Text = temp1 + "/";
c++; p = 0;
}
private void button13_Click(object sender, EventArgs e)
{
double temp2 = Convert.ToDouble(b);
switch (pos)
{
case 1:
textBox1.Text = (temp1 + temp2).ToString();
break;
case 2:
textBox1.Text = (temp1 - temp2).ToString();
break;
case 3:
textBox1.Text = (temp1 * temp2).ToString();
break;
case 4:
textBox1.Text = (temp1 / temp2).ToString();
break;
}
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = "";//清?空?显?示º?器¡Â temp1 = 0;
pos = 0;
b = "";
a = "";
n = 0;
c = 0;
p = 0;
}
}
}。