Console.WriteLine(\正方体的面积为:{0}\ Console.ReadLine(); } }
10. 创建一个名称为Circle的类:
该类中定义私有的成员字段radius,并设置其相应的公有属性; 完成该类的无参有参构造方法;
该类包含方法Circumference(周长)和面积(Area); 定义子类圆柱体Cylinder类: 字段包括高;并定义相应属性; 完成该类的无参有参构造方法;
实现该类的面积(Area)和体积(Volumn)方法。
在main中创建圆类对象,计算并显示其周长和面积;创建圆柱体对象,计算并显示其面积和体积。 class Circle {
private double radius;
public double Radius {
get { return radius; } set { radius = value; } }
public Circle() { }
public Circle(double radius) {
this.radius = Radius; }
public double Circumference() {
return Math.PI * radius*2; }
public virtual double Area() {
return Math.PI *radius*radius; } }
class Cylinder:Circle {
private double height; public double Height {
get { return height; } set { height = value; }
}
public Cylinder() { }
public Cylinder(double height) {
this.height = height; }
public override double Area() {
return 2 * Math.PI * Radius * Radius + Math.PI *Radius* 2; }
public double Volumn() {
return height * Math.PI * Radius * Radius; } }
class Program {
static void Main(string[] args) {
Circle c = new Circle(); c.Radius = 3;
Console.WriteLine(\圆的面积为:{0} 周长为:{1}\c.Area(), c.Circumference());
Cylinder cy = new Cylinder(); cy.Radius = 2; cy.Height = 2;
Console.WriteLine(\圆柱的面积为:{0} 体积为:{1}\cy.Area(), cy.Volumn());
Console.ReadLine(); } }
建表: 打开SQL2005软件,选择数据库,右击新建数据库Test,打开找到表,右击新建表,输入字段名,类型宽度,是否为空,若设置主键,右击字段名设为主键;保存,改表名.选择数据库右击,任务选项卡里选择分离.然后去c:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/DATA下的Test.ldf, Test.mdf两个文件考下来交上 四、windows程序设计题
1. 在数据库Test中,包括教师信息表Teachers,其表结构如表所示
表 Teacher(教师信息表) 字段名 类型 宽是否空 备注 度 TID varchar 10 非空 主键,教工号 Name varchar 10 非空 姓名 Sex varchar 2 非空 性别 Birthday Datetime 8 出生日期 Position varchar 18 非空 职位如教授、副教授等 Email varchar 50 电子邮件 请完成数据库的建立,并利用NET环境创建Window程序TeacherManage,在该系统中实现对教师信息的添加和查询,具体要求如下:
1)在主窗体添加菜单栏,并设置菜单项:添加、查询、退出。并单击添加菜单栏,进入添加窗体,单击查询菜单栏进入查询窗体,单击退出菜单退出系统。 2)添加窗体,实现添加教师信息功能,在该窗体,设置相应的控件,录入教师信息,单击“添加”按钮实现将录入信息添加到数据库的表中;
3)查询窗体要求根据教工号进行查询,将查询到的详细信息显示到对应的控件中;
4)窗体要求设计整洁,控件使用合理,各功能的实现尽量全面、完整。 若题目要求添加添加、查询的这样写
深色的大框为工具栏里数据中的DataGridView class DBHelper {
public static string message;
public static SqlConnection getConn() {
SqlConnection conn = new SqlConnection(\ return conn; }
public static int None(string sql) {
int flag = 0;
SqlCommand cmd = null;
SqlConnection conn = getConn(); try {
conn.Open();
cmd = new SqlCommand(sql, conn); flag = cmd.ExecuteNonQuery(); }
catch (Exception e) {
message = e.ToString(); flag = 0; }
finally {
if (conn != null) { conn.Close(); } }
return flag; } }
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) {
Tian tian = new Tian(); tian.Show(); }
private void 查询ToolStripMenuItem_Click(object sender, EventArgs e) {
Cha cha = new Cha(); cha.Show(); }
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) {
this.Close(); } }
添加: public partial class Tian : Form {
public Tian() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
string name = textBox1.Text; string phone = textBox2.Text; string mphone = textBox3.Text; string address = textBox4.Text; string qq = textBox5.Text; string email = textBox6.Text;
string sql = string.Format(\AddressLists
values('{0}','{1}','{2}','{3}','{4}','{5}')\ if (DBHelper.None(sql) > 0) { MessageBox.Show(\成功\
else { MessageBox.Show(\失败\ } }
查询:
public partial class Cha : Form {
public Cha() {
into
百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库C#程序设计期末题库带答案(8)在线全文阅读。
相关推荐: