、开发一个窗体应用程序,窗体上能接收华氏温度或者摄氏温度,点击相应按钮可以相互转换。
要求转换后的华氏温度或者摄氏温度保留小数点后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. Python 02 编写代码

    原文:https://www.cnblogs.com/jimmy-share/p/9784219.html 方式: 交互式编程:打开python.exe文件后,直接输入代码即可.文件的位置(我本地): ...

  2. centos7 安装postgresql11

    1 进入postresql官网下载页面,提示了centos相关下载安装等信息. https://www.postgresql.org/download/linux/redhat/   image.pn ...

  3. es6学习2:变量的解构赋值

    一:数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构 let [foo, [[bar], baz]] = [1, [[2], 3]]; foo bar ba ...

  4. SSL 安全协议 以及 如何认证

    目录 ssl安全协议 以及 认证 什么是协议 http劫持 ssl是什么 ssl 证书 概念 3种类型ssl 证书 ssl认证:阿里云免费认证 配置 Nginx的ssl认证 nginx的ssl证书(一 ...

  5. 第09组 Alpha冲刺(2/4)

    队名:软工9组 组长博客:https://www.cnblogs.com/cmlei/ 作业博客:http://edu.cnblogs.com/campus/fzu/SoftwareEngineeri ...

  6. mybatis Example Criteria like 模糊查询

    用Mybatis代码生成工具会产生很多个XXXExample类,这些类的作用是什么? 查阅了很多资料,在这里总结归纳一下 简介XXXExample类用于构造复杂的筛选条件 它包含一个名为Criteri ...

  7. Linux零拷贝技术 直接 io

    Linux零拷贝技术 .https://kknews.cc/code/2yeazxe.html   https://zhuanlan.zhihu.com/p/76640160 https://clou ...

  8. android: 结合BottomNavigationView、ViewPager和Fragment 实现左右滑动的效果

    主界面:MainActivity package com.yongdaimi.android.androidapitest; import android.os.Bundle; import andr ...

  9. jeff dean的主页

    https://ai.google/research/people/jeff/ 上面有他的很多论文和ppt 很不错 我于1999年中期加入Google,目前是研究小组的Google高级研究员,负责Go ...

  10. python 上下文管理器contextlib.ContextManager

    1 模块简介 在数年前,Python 2.5 加入了一个非常特殊的关键字,就是with.with语句允许开发者创建上下文管理器.什么是上下文管理器?上下文管理器就是允许你可以自动地开始和结束一些事情. ...