ooad3-自制OOA&D实验报告系列

时间:2024.3.31

OOAD: Experimental lecture 6

Advanced GUI

Name :Li Hongfu

Student no:  201219010145

Date: December 10 2014

Table of Contents

Objectives:------------------------------------------------------------3

Methods:--------------------------------------------------------------3

Results:----------------------------------------------------------------3

Exercise 1:----------------------------------------------------------------------3

Exercise 2:----------------------------------------------------------------------3

Exercise 3:----------------------------------------------------------------------4

Exercise 4:----------------------------------------------------------------------4

Code--------------------------------------------------------------------4

Exercise 1:----------------------------------------------------------------------4

Exercise 2:----------------------------------------------------------------------5

Exercise 3:----------------------------------------------------------------------5

Exercise 4:----------------------------------------------------------------------6

Picture------------------------------------------------------------------6

picture 1:------------------------------------------------------------------------6

picture 2:------------------------------------------------------------------------7

picture 3:------------------------------------------------------------------------7

picture 4:------------------------------------------------------------------------7

Conclusions:---------------------------------------------------------8

A.Objectives:

1.    Learning the abstract function.

2.    Getting familiar with the super-class and subclass.

3.    Learn about the usage of abstract.

4.    Getting learned about the override.

B.   Methods:

There is the following part that is needed to understand exercise:

1.    Abstract class

2.    Virtual function

3.    Override function

4.    Create new object

C.Result

Exercise 1

Firstly, I created a abstract animal as the super class, it’s basically a abstract class. And after that, I created two methods Eatfood and speak in the animal class. To inherit the abstract animal, I created two subclass named cow and chicken.

Public class cow:animal 

The colon represents inevitability.

Public void virtual Eatfood()

Void means no value will be returned.

Exercise 2

Created the main function, and then crated the new objects. And when you want to invoke the method, just write like this way:myanimal.Eatfood();

New objects:

Animal myanimal=new Cow();

Cow mycow=new Cow();

The result is in the appendix.

Exercise 3

In this exercise, you can see that an abstract class can’t be instantiated directly; to use it we need to inherit from it. We can just see the result in appendix.

Exercise4:

In this exercise, I add some methods for chicken and animal.

Public void override Eatfood()

{ Console.Writeline(‘Chicken eats stone”);

Console.Writeline(‘Chicken speak Hello”);}

The whole code:

Exercise 1:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyFirstABstract

{

    public abstract class Animal

    {

        public virtual void EatFood()

        {

            Console.WriteLine("Animal eat");

        }

        public virtual void Speak()

        {

            Console.WriteLine("Animal speak");

        }

    }

    public class Cow : Animal

    {

        public override void EatFood()

        {

            Console.WriteLine("Cow eats");

        }

    }

    public class Chinken : Animal

    { }

}

Exercise 2 :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyFirstABstract

{

   public abstract class Animal

    {

        public virtual void EatFood()

        {

            Console.WriteLine("Animal eat");

        }

       public virtual void Speak()

       {

           Console.WriteLine("Animal speak");

       }

    }

    public class Cow:Animal

    {

        public override void  EatFood()

        {

            Console.WriteLine("Cow eats");

        } 

    }

    public class Chinken: Animal

    { }

    class Program

    {

        static void Main(string[] args)

        {

            Animal myAnimal = new Cow();

            Cow myCow = new Cow();

            myAnimal.EatFood();

            myCow.EatFood();

            myCow.Speak();

            Console.ReadKey();

        }

    }

}

Exercise 3:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyFirstABstract

{

   public abstract class Animal

    {

        public virtual void EatFood()

        {

            Console.WriteLine("Animal eat");

        }

       public virtual void Speak()

       {

           Console.WriteLine("Animal speak");

       }

    }

    public class Cow:Animal

    {

        public override void  EatFood()

        {

            Console.WriteLine("Cow eats");

        } 

    }

    public class Chinken: Animal

    { }

    class Program

    {

        static void Main(string[] args)

        {

            Animal myAnimal = new Animal();

            Cow myCow = new Cow();

            myAnimal.EatFood();

            myCow.EatFood();

            myCow.Speak();

            Console.ReadKey();

        }

    }

}

Exercise 4

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyFirstABstract

{

   public abstract class Animal

    {

        public virtual void EatFood()

        {

           Console.WriteLine("Animal speak");

           Console.WriteLine("\n");

        }

       public virtual void Speak()

       {

           Console.WriteLine("Animal speak");

           Console.WriteLine("\n");

       }

    }

    public class Cow:Animal

    {

        public override void  EatFood()

        {

            string Food1;

            Console.WriteLine("Please input Cow eat :");

            Food1 = Console.ReadLine();

            Console.WriteLine("Cowsd eat :\t" + Food1);

            Console.WriteLine("\n");

        } 

    }

    public class Chinken: Animal

    {

        public void Eat()

        {

            string Food2;

            Console.WriteLine("Please input Animal eat :");

            Food2 = Console.ReadLine();

            Console.WriteLine("Animal eat :\t" + Food2);

            Console.WriteLine("\n");

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Animal myAnimal = new Cow();

            Cow myCow = new Cow();

            Chinken myChinken = new Chinken();

            myAnimal.EatFood();

            myCow.EatFood();

            myCow.Speak();

            myChinken.Eat();

            Console.ReadKey();

        }

    }

}

Picture 1

Picture 2

Picture 3

Picture 4

D.Conclude

1.    An abstract class can’t be instantiated directly; to use it we need to inherit from it.

2.    Abstract classes can have abstract members, which have no implementation in the base class, so an implementation must be supplied in the derived class.

3.    Child classes can override members that are defined as virtual in a parent class.

4.    Child classes cannot access private members in its parent, but it is possible to define protected members that are available only within a class or classes that derive from that class.

更多相关推荐:
3d实验报告

实验报告实验报告院系信息科学与技术学院课程名称三维动画设计日期实验报告九江学院实验报告实验报告实验报告实验报告实验报告实验报告院系信息科学与技术学院课程名称三维动画设计日期九江学院3D王燕信A1131实验报告

3D实验报告

景德镇陶瓷学院设计艺术学院实验报告课程名称计算机辅助设计三维设计姓名戈瑞琪教师董翠专业班级08陶设4班成绩日期实验项目名称1基础工具2建模3材质4灯光摄影机5渲染实验学时1基础工具8学时2建模32学时3材质16...

3d实习报告

前言所谓三维设计就是利用电脑进行设计与创作以产生真实的立体场景与动画虽然在这个学期对3DSMAX的接触才知道3DSMAX是一个广泛应用于游戏开发后期制造影视特效及专业视觉设计领域的一款功能强大的三维设计软件它是...

unity 3d实验报告

江南大学Unity3D实验报告实验题目班级姓名学号日期一目的与要求1理解使用Unity3D制作游戏的基本过程和方法2理解Unity3D软件的操作界面3掌握地形的创建和简单编辑方法4掌握游戏场景中光源的添加和设置...

3D打印实验报告

姓名:学号:指导教师:20xx年x月x日一、技术介绍3D打印是一种通过材料逐层添加制造三维物体的变革性、数字化增材制造技术,它将信息、材料、生物、控制等技术融合渗透,将对未来制造业生产模式与人类生活方式产生…

3D MAX过程训练实验报告

3D MAX过程训练实验报告,内容附图。

3d实验报告建筑材质 灯光

本科学生综合性实验报告项目组长郭恺学号0094326成员郭恺专业09环艺2班实验项目名称建筑材质灯光设计指导教师及职称陈茜讲师开课学期20xx至20xx学年二学期上课时间20xx年3月30日学生实验报告一实验综...

实验报告 -3D打印机

人机交互技术实验报告实验名称3D打印机原理及构造班级数媒1301组长学号姓名刘家旺组员学号姓名沈苏明成绩实验四3D打印机原理及构造一实验目的了解学院使用的3D打印机的工作原理二实验要求了解学院使用的3D打印机的...

3D打印实验课实验报告及说明

关于先进制造技术课程3D打印实验的通知一实验须知1实验时间安排第12周周一11月23日下午200330全体同学统一进行3D打印实验原理和操作方法及注意事项的讲解理论讲解地点为上课地点讲解后分2批进行实验具体分批...

3D建模实验报告

摄影测量学实验报告实验序号实验二实验项目名称建筑三维建模

3D 实验报告

实验一1打开素材中的三维场景文件在3dsMax中选择全部模型然后单击工具栏中的工具按钮在打开的面板中单击更多按钮调出VRPforMax插件面板2在打开的插件面板中在目标选项组中勾选全部单选按钮并勾选类型选项组中...

3D建模贴图实验报告

摄影测量学实验报告实验序号实验三实验项目名称建筑三维建模贴图

3d实验报告(35篇)