【C#】上机实验七
、开发一个窗体应用程序,窗体上能接收华氏温度或者摄氏温度,点击相应按钮可以相互转换。
要求转换后的华氏温度或者摄氏温度保留小数点后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#】上机实验七的更多相关文章
- oracle上机实验内容
这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...
- lingo运筹学上机实验指导
<运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...
- 算法课上机实验(一个简单的GUI排序算法比较程序)
(在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...
- 【C++ 流类库与输入输出 】实验七
1. 基础练习 (1)教材习题 11-7 (2)教材习题 11-3 (3)教材习题 11-4 2. 应用练习 (1)已知有班级名单文件 list.txt(见实验 7 附件包).编写一个应用程序实现随机 ...
- Java第一次上机实验源代码
小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验七:PS/2模块① — 键盘
实验七:PS/2模块① — 键盘 实验七依然也是熟烂的PS/2键盘.相较<建模篇>的PS/2键盘实验,实验七实除了实现基本的驱动以外,我们还要深入解PS/2时序,还有PS/2键盘的行为.不 ...
- 软件测试技术lab2——Selenium上机实验
Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...
- 合肥工业大学数据结构上机实验代码与实验报告(全)github地址
我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...
- 《数据挖掘导论》实验课——实验七、数据挖掘之K-means聚类算法
实验七.数据挖掘之K-means聚类算法 一.实验目的 1. 理解K-means聚类算法的基本原理 2. 学会用python实现K-means算法 二.实验工具 1. Anaconda 2. skle ...
随机推荐
- 通过redash query results 数据源实现跨数据库的查询
redash 提供了一个简单的 query results 可以帮助我们进行跨数据源的查询处理 底层数据的存储是基于sqlite的,期望后期有调整(毕竟处理能力有限),同时 query results ...
- 机器学习---逻辑回归(一)(Machine Learning Logistic Regression I)
逻辑回归(Logistic Regression)是一种经典的线性分类算法.逻辑回归虽然叫回归,但是其模型是用来分类的. 让我们先从最简单的二分类问题开始.给定特征向量x=([x1,x2,...,xn ...
- I Count Two Three(打表+排序+二分查找)
I Count Two Three 二分查找用lower_bound 这道题用cin,cout会超时... AC代码: /* */ # include <iostream> # inclu ...
- D3.js的v5版本入门教程(第十三章)—— 饼状图
D3.js的v5版本入门教程(第十三章) 这一章我们来绘制一个简单的饼状图,我们只绘制构成饼状图基本的元素——扇形.文字,从这一章开始,内容可能有点难理解,因为每一章都会引入比较多的难理解知识点,在这 ...
- 【Java 8】巧用Optional之优雅规避NPE问题
避之不及的 NullPointerException NPE : NullPointerException 空指针异常是最常见的Java异常之一,抛出NPE错误不是用户操作的错误,而是开发人员的错误, ...
- rust 函数的使用
fn main() { println!("Hello, world!"); another_function(2,3); let y ={ let x =3; //表达式的结尾没 ...
- 刷题记录:[FBCTF2019]Products Manager
目录 刷题记录:[FBCTF2019]Products Manager 一.知识点 1.基于约束的SQL注入攻击 刷题记录:[FBCTF2019]Products Manager 题目复现链接:htt ...
- spring4.x企业应用开发读书笔记1
第一章 概述 1 spring 以 ioc 和 aop 为内核,提供了展现层 springMVC.持久层SpringJDBC及业务层事务管理等一站式企业级应用技术. 2spring的特性 方便解耦,简 ...
- Charles 激活入口以及账号密码
激活入口 // Charles Proxy License // 适用于Charles任意版本的注册码,谁还会想要使用破解版呢. // Charles 4.2目前是最新版,可用. Registered ...
- docker登录报错Error response from daemon: Get https://192.168.30.10/v1/users/: dial tcp 192.168.30.10:443: connect: connection refused
背景描述: 登录docker报错: [root@localhost sysconfig]# docker login 192.168.30.10 Username (newcs06): newcs06 ...