、开发一个窗体应用程序,窗体上能接收华氏温度或者摄氏温度,点击相应按钮可以相互转换。
要求转换后的华氏温度或者摄氏温度保留小数点后3位,程序中要有异常处理结构。

        

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Myform1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void label1_Click(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
try
{
textBox2.Text = htc(textBox1.Text).ToString("f3");
}
catch (Exception ex)
{
Text = ex.Message;
}
} private void button2_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = cth(textBox2.Text).ToString("f3");
}
catch (Exception ex)
{
Text = ex.Message;
}
} public double htc( double x ){
return (x - ) * / ;
} public double htc(string s)
{
double x = double.Parse(s);
return (x - ) * / ;
} public double cth(double x)
{
return (x * / ) + ;
}
public double cth(string s)
{
double x = double.Parse(s);
return (x * / ) + ;
} }
}

温度转换


、设计一个窗体应用程序,输入一个字符,判定此字符是数字、大写字母、小写字母,还是其它字符。
要求:
()类中定义公有方法(判断字符归属)
()在按钮单击事件中调用该方法及返回值完成判断。
()程序中要有异常处理结构。

      

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Myproject2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string s = textBox1.Text;
if (s.Length > )
{
Text = "请输入一个字符";
textBox1.Text = "";
textBox2.Text = "";
MessageBox.Show("请输入一个字符", "Warming", MessageBoxButtons.OK);
} if( s.Length == )
try
{
char ch = s[];
if ('a' <= ch && ch <= 'z') {
textBox2.Text = "小写字母";
}
else if ('A' <= ch && ch <= 'Z') {
textBox2.Text = "大写字母";
}
else if ('' <= ch && ch <= '')
{
textBox2.Text = "数字";
}
else {
textBox2.Text = "其他字符";
}
}
catch (Exception ex)
{
Text = ex.Message;
}
} private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
} }
}

判断字符


、开发一个窗体应用程序,可以根据圆的半径计算圆的面积。具体要求如下:
()设计一个方法求圆的面积。
()求圆面积的方法要定义成重载方法,既能接收整形参数,也能接收单精度类型参数。
()程序中要有异常处理结构。

    

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Myproject3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
double d = ;
int x = ;
bool Is_int = false;
bool Is_double = false; if (Is_int = int.TryParse(str, out x)){}
else if ( Is_double = double.TryParse(str, out d)){} if (Is_int || Is_double)
{
try
{
if (Is_int)
{
textBox2.Text = (Math.PI * x * x).ToString("f2");
}
else
{
textBox2.Text = (Math.PI * d * d).ToString("f2");
} }
catch (Exception ex)
{
Text = ex.Message;
}
}
else
{
MessageBox.Show("请输入数字", "Warning", MessageBoxButtons.OK);
textBox1.Text = textBox2.Text = ""; }
}
}
}

求圆的面积


、设计一个窗体应用程序,练习最基本的控件使用,实现单选按钮、复选按钮和命令按钮的相关功能。

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Myproject4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void groupBox1_Enter(object sender, EventArgs e)
{ }
private FontFamily fontFamily = new FontFamily("宋体");
private FontStyle Style = FontStyle.Regular;
private float Size = ;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
fontFamily = new FontFamily("黑体");
textBox1.Font = new Font(fontFamily, Size, Style);
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
fontFamily = new FontFamily("楷体");
textBox1.Font = new Font(fontFamily, Size, Style);
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Style ^= FontStyle.Bold;
textBox1.Font = new Font(fontFamily, Size, Style);
} private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
Style ^= FontStyle.Italic;
textBox1.Font = new Font(fontFamily, Size, Style);
} private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
Size = ;
textBox1.Font = new Font(fontFamily, Size, Style);
} private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
Size = ;
textBox1.Font = new Font(fontFamily, Size, Style);
} private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
textBox1.ForeColor = Color.Red;
} private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
textBox1.ForeColor = Color.Blue ;
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Copy();
} private void button2_Click(object sender, EventArgs e)
{
textBox1.Cut();
} private void button3_Click(object sender, EventArgs e)
{
textBox1.Paste();
} private void button4_Click(object sender, EventArgs e)
{
textBox1.Undo();
} }
}

记事本

【C#】上机实验七的更多相关文章

  1. oracle上机实验内容

    这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...

  2. lingo运筹学上机实验指导

    <运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...

  3. 算法课上机实验(一个简单的GUI排序算法比较程序)

    (在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...

  4. 【C++ 流类库与输入输出 】实验七

    1. 基础练习 (1)教材习题 11-7 (2)教材习题 11-3 (3)教材习题 11-4 2. 应用练习 (1)已知有班级名单文件 list.txt(见实验 7 附件包).编写一个应用程序实现随机 ...

  5. Java第一次上机实验源代码

    小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...

  6. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验七:PS/2模块① — 键盘

    实验七:PS/2模块① — 键盘 实验七依然也是熟烂的PS/2键盘.相较<建模篇>的PS/2键盘实验,实验七实除了实现基本的驱动以外,我们还要深入解PS/2时序,还有PS/2键盘的行为.不 ...

  7. 软件测试技术lab2——Selenium上机实验

    Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...

  8. 合肥工业大学数据结构上机实验代码与实验报告(全)github地址

    我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...

  9. 《数据挖掘导论》实验课——实验七、数据挖掘之K-means聚类算法

    实验七.数据挖掘之K-means聚类算法 一.实验目的 1. 理解K-means聚类算法的基本原理 2. 学会用python实现K-means算法 二.实验工具 1. Anaconda 2. skle ...

随机推荐

  1. PHP.INI生成环境配置文件

    extension_dir = /home/php/lib/php/extensions/no-debug-zts- zend_extension = opcache.so extension = p ...

  2. JavaScript高级程序编程(三)

    2017-06-24 更新 北京连续三天下雨啦 乘性操作符   1.ECMA中定义了三种操作符,乘法 除法 和求模 并与其他语言相应操作符相同,再计算之前如果不是数值,会先去调用number()方法转 ...

  3. JavaScript中字符串多行编辑

    常用写法: var str = 'w3c' +'标准' +'方式.' 升级版:var str = ['w3c','标准','方式.'].join('');终极版:var str = 'w3c\标准\方 ...

  4. Android程序员问答题

    前言 最近三个月内,不断地进行移动应用开发在线测试题,也积累了不一样的知识.这也将对android studio有很好的掌握,对将来面试也很有好处.那么我就分享给大家.分享是一种幸福,这是一种质的飞越 ...

  5. mysql 添加表字段

    mysql> alter table table1 add price ) not null; Query OK, rows affected (0.05 sec) Records: Dupli ...

  6. 梯形法求解常微分方程(c++)

    #include<iostream> #include<iomanip> using namespace std; int main() { double x,y,yn,h,t ...

  7. [Beta]第四次 Scrum Meeting

    [Beta]第四次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/5/12 22:00 30min 大运村公寓6F楼道 附Github仓库:WEDO 例会照片 工作情况 ...

  8. 008 @Import作用

    一: 1.说明 在应用中,有时没有把某个类注入到IOC容器中,但在运用的时候需要获取该类对应的bean,此时就需要用到@Import注解. 二:示例一 1.说明 基于007接着做的测试. 2.Bean ...

  9. [转]Vue CLI 3搭建vue+vuex 最全分析

    原文地址:https://my.oschina.net/wangnian/blog/2051369 一.介绍 Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统.有三个组件: CLI:@ ...

  10. java使用ssh连接Linux并执行命令

     方式1:通过设置账号密码和链接地址 maven pom.xml配置: <dependency>         <groupId>com.jcraft</groupId ...