C程序设计总实习报告.doc

上传人:b****1 文档编号:133770 上传时间:2022-10-04 格式:DOC 页数:62 大小:880.96KB
下载 相关 举报
C程序设计总实习报告.doc_第1页
第1页 / 共62页
C程序设计总实习报告.doc_第2页
第2页 / 共62页
C程序设计总实习报告.doc_第3页
第3页 / 共62页
C程序设计总实习报告.doc_第4页
第4页 / 共62页
C程序设计总实习报告.doc_第5页
第5页 / 共62页
点击查看更多>>
下载资源
资源描述

C程序设计总实习报告.doc

《C程序设计总实习报告.doc》由会员分享,可在线阅读,更多相关《C程序设计总实习报告.doc(62页珍藏版)》请在冰豆网上搜索。

C程序设计总实习报告.doc

实验报告

河南财经政法大学

计算机与信息工程学院

实验报告

2013年--------2014年第一学期

专业:

______管理信息系统_______

课程名称:

____C#高级程序设计_____

班级:

_________________

姓名:

__________学号:

_________

指导教师:

_________________

实验一:

派生类

实验目的:

1.了解继承和多态的基本概念。

2.掌握派生类、虚方法的使用方法。

3.掌握抽象类的定义方法。

实验内容:

一、

1.运行课本例8.1,仔细理解派生类、基类对象的引用及其转换方法。

2.参照课本例8.3,创建基类Person和派生类Teacher。

基类Person包含实例字段name和age;虚函数GetInfo()显示个人信息(显示name和age的值)。

派生类Teacher除了包含基类的name和age字段,还包括自己的TeacherID字段,并使用关键字override来重写方法GetInfo()显示教师信息(显示name、age和TeacherID的值)。

运行效果如图所示。

3.创建抽象类基类Shape和派生类Rectangle、Circle、Square。

利用多态性实现Area(计算面积)和Show(显示图形名称和面积)抽象方法。

具体要求如下:

l抽象类Shape中有字段name(名称)及两个抽象方法Show(显示名称及面积)、Area(面积)。

l派生类Rectangle(矩形)中有字段weigh(宽度)、height(高度)及两个覆盖方法Show(显示名称及面积)、Area(计算矩形的面积)。

l派生类Circle(圆)中有字段radius(半径)及两个覆盖方法Show(显示名称及面积)、Area(计算圆的面积)。

l派生类Square(正方形)中有字段weigh(边长)及两个覆盖方法Show(显示名称及面积)、Area(计算正方形的面积)。

运行效果如图所示。

实验数据记录及分析(或程序及运行结果)

1

namespaceConsoleApplication1

{

classProgram

{

publicclassParent

{publicParent(){}

publicvoidMethodA()

{

Console.WriteLine("调用MethodA()");

}

}

publicclassChild:

Parent

{publicChild(){}

publicvoidMethodB()

{Console.WriteLine("调用MethodB()");

}

}

classTest

{

staticvoidMain()

{ParentoParent=newParent();

oParent.MethodA();

ChildoChild=newChild();

oChild.MethodB();

oChild.MethodA();

ParentoParent1=(Parent)oChild;

oParent.MethodA();

Console.ReadLine();

ChildoChild1=(Child)oParent1;

oChild1.MethodB();

oChild1.MethodA();

Console.ReadKey();

}

}

}}

2

namespaceConsoleApplication2

{

classProgram

{

publicclassPerson

{

publicstringname;

publicuintage;

publicPerson(stringname,uintage)

{

this.name=name;

this.age=age;

}

publicvirtualvoidGetInfo()

{

Console.WriteLine("Name:

{0}",name);

Console.WriteLine("Age:

{0}",age);

}

publicclassTeacher:

Person

{

publicstringteacherID;

publicTeacher(stringname,uintage,stringid)

:

base(name,age)

{

this.teacherID=id;

;

}

publicoverridevoidGetInfo()

{

base.GetInfo();

Console.WriteLine("TeacherID:

{0}",teacherID);

}

}

publicclassTestPersonTeacher

{

staticvoidMain(string[]args)

{

Teacherobjteacher=newTeacher("Mr.Yu",40,"1990108001");

objteacher.GetInfo();

Console.ReadKey();

}

}

}

}

}

3

publicabstractclassShape

{

publicstringname;

publicShape(stringname)

{

this.name=name;

}

publicabstractdoubleArea();

publicabstractvoidShow();

}

publicclassRectangle:

Shape

{

publicintweight,height;

publicRectangle(intweight1,intheight1,stringname):

base(name)

{

weight=weight1;

height=height1;

}

publicoverridevoidShow()

{

Console.WriteLine("Rectangle:

{0},Area:

{1}",name,weight*height);

}

publicoverridedoubleArea()

{

returnweight*height;

}

}

publicclassCircle:

Shape

{

publicintradius;

publicCircle(intr,stringid)

:

base(id)

{

radius=r;

}

publicoverridevoidShow()

{

Console.WriteLine("Rectangle:

{0},Area:

{1}",name,radius*radius*System.Math.PI);

}

publicoverridedoubleArea()

{

returnradius*radius*System.Math.PI;

}

}

publicclassSquare:

Shape

{

publicintweight;

publicSquare(intweight1,stringid)

:

base(id)

{

weight=weight1;

}

publicoverridevoidShow()

{

Console.WriteLine("Rectangle:

{0},Area:

{1}",name,weight*weight);

}

publicoverridedoubleArea()

{

returnweight*weight;

}

}

classTest

{

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 党团建设

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1