0% found this document useful (0 votes)
140 views1 page

Lab1 FPT C# OOP

The document describes two exercises for creating class hierarchies. The first exercise involves creating an abstract Shape class and derived classes for specific shapes like Line, Circle, and Rectangle. The second exercise involves creating an abstract Animal class and derived classes for specific animals like Dog, Cat, and Duck with their own attributes and methods. Both exercises conclude with testing the classes by creating objects and invoking their methods.

Uploaded by

Phu Dao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views1 page

Lab1 FPT C# OOP

The document describes two exercises for creating class hierarchies. The first exercise involves creating an abstract Shape class and derived classes for specific shapes like Line, Circle, and Rectangle. The second exercise involves creating an abstract Animal class and derived classes for specific animals like Dog, Cat, and Duck with their own attributes and methods. Both exercises conclude with testing the classes by creating objects and invoking their methods.

Uploaded by

Phu Dao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercise 1:

 Define an abstract base class Shape that includes protected data

members for the (x, y) position of a shape, a public method to move


a shape, and a public abstract method Show () to output information
of a shape.
 Derive subclasses for lines, circles, and rectangles. You can represent

a line as two points, a circle as a center and a radius, and a rectangle


as three points.
 Also, define the class PolyLine with Shape as its base class.

 Implement the ToString() method for each class.

 Test the classes by creating objects of the derived classes, and then

invoking methods for each.

Exercise 2:

 Define an abstract class Animal which has the following members:


- Type is used to identify the type of animal (mammal, bird), and its
value is set by the constructor.
- A method returns sound made by animal.
- A method returns information of animal.
 Define classes, which derive from Animal, for Dog, Cat and Duck.
These classes have Name attribute. Besides, each class has more
some other members such as:
- Dog class has Breed attribute. This attribute can be one of values
such as Spaniel, Chihuahua, and Collie.
- Cat has Climb method which indicates that cat is climbing some
thing (tree, wall, roof, etc).
 Duck has Swim method which indicates that duck is swimming some
thing (pond, pool, etc).
- Test the classes by creating objects of the derived classes, and
then invoking methods for each.

You might also like