实验二 面向对象的编程基础.doc
文本预览下载声明
实验二 面向对象的编程基础
(课时)一、实验目的
二、实验要求
程序结构清晰、语句完整,包含有头文件和main函数;
格式正确,语句采用缩进格式;
设计子函数实现题目要求的功能;
编译、连接通过,熟练使用命令键;
运行结果正确,输入输出有提示,格式美观。
三、实验设备、材料和工具
奔腾2计算机或以上机型
四、实验内容和步骤
实验内容:
步骤:
步骤:
五、实验报告要求
实验前需填写好实验的名称和实验目的;
根据实验内容初步设计好程序并从理论上排除错误;
针对程序的健壮性准备好测试数据;
结果分析中如实填写运行后的结果,并记录调试过程中产生的重要问题和解决方法。
六、根据实验过程填写class Book{
private readonly string isbn; //书号
private string title; //标题
private string author; //作者
private string press; //出版社
private int price; //价格
public Book(string isbn):this(isbn,未知,未知,未知,0){
}
public Book(string isbn,string title,string author,string press,int price){
this.isbn=isbn;
this.title=title;
this.author=author;
this.press=press;
this.price=price;
}
public string ISBN{
get{
return isbn;
}
}
public string Title{
get{
return title;
}
set{
title=value;
}
}
public string Author{
get{
return author;
}
set{
author=value;
}
}
public string Press{
get{
return press;
}
set{
press=value;
}
}
public int Price{
get{
return price;
}
set{
price=value;
}
}
public void Show(){
Console.WriteLine(书号: {0},isbn);
Console.WriteLine(标题: {0},title);
Console.WriteLine(作者: {0},author);
Console.WriteLine(出版社:{0},press);
Console.WriteLine(价格: {0},price);
}
}
class Test5_1{
static void Main(){
Book book1=new Book(978-7-111-23423-4);
book1.Show();
Console.WriteLine();
book1.Title=C#程序设计(C#2.0版);
book1.Author=刘慧宁;
book1.Press=机械工业出版社;
book1.Price=32;
book1.Show();
Console.WriteLine();
book1=new Book(978-7-302-15800-4,Java程序设计,温秀梅,清华大学出版社,29);
book1.Show();
}
}
结果:
调试过程中产生的重要问题和解决方法enum CColor{
BLACK,BLUE,BROWN,CYAN,GRAY,GREEN,ORANGE,PINK,RED,WHITE,YELLOW
}
//定义一个几何图形接口
interface Shape{
CColor Color{
get;
set;
}
//绘制的方法
void Draw();
//擦拭的方法
void Erase();
//移动的方法
void Move();
}
//定义一个点的结构来实现Shape几何图形的接口
struct Point:Shape{
private CColor color;
private int x,y;
public CColor Color{
get{
return color
显示全部