Skip to main content

OOPS/Perl Examples + Excercises

Exercise:
Imagine the following situation. Software is to be written to handle information about the aircraft housed at a particular airport. There are various kinds of these aircraft and these fall into three categories: personal, elite and passenger. Personal and elite aircraft are privately owned and the airport keeps information about the owner’s name and contact details. Personal aircraft are never piloted by the airport’s pilots. Elite aircraft also have a V.I.P. associated with them. Elite aircraft are usually owned by companies but usually use the airport’s pilots. Passenger aircraft are owned by the
airport and have a regular route with predetermined destinations and only use the airport’s pilots.

All aircrafts have fuel quantities, hanger numbers, a maximum person carrying capacity as well as luggage and cargo, a maximum flying distance and several other values.

1. What classes can you identify in this description?
2. Draw these classes and their relations to each other. Can you identify any places where inheritance might be useful?
3. With each class list any methods and attributes you can think of that belong to that class.
4. Can we make use of inheritance polymorphism to reduce code duplication? Mark any methods you’ve included in child classes that can be inherited in total from an ancestor class.

PERL :

Exercises
1. Create a file called MyTest.pl Define at least two subroutines; pass and fail which print some
amusing output. Make sure that it uses strict.
2. Test that your code compiles by running perl -c MyTest.pl. (The -c tells Perl to check your
code).
3. Create a simple Perl script which requires MyTest.pl and calls the functions defined within.

---------------
OOPS Examples and Concepts :

1.A drinks machine has a number of attributes; the amount and type of coins with which to give change, inventories of the various drinks available, the cost of each drink, the current internal temperature, whether or not the refrigeration unit is operating, and so on. People don’t have direct access to those attributes, instead they’re restricted by the buttons and coin slots on the machine.
This interface is designed to ensure that only certain operations may be performed so that the machine maintains a consistent internal state. For example, the owners of the drinks machine only want to dispense a drink if an appropriate amount of money has been inserted.
The restrictions aren’t just in the interest of the machine’s owner, some of them are to help the customer as well. By maintaining a consistent state it’s possible to ensure that customers get both the drink they asked for as well as correct change. Some restrictions (like the machine being bolted to the floor) can stop potentially dangerous operations, like people trying to rock the machine. Otherrestrictions help ensure that the internal temperature setting can’t be changed and spoil the drinks for
others.
2.A common mistake in object oriented programming is to forget the distinction between objects and their classes. The class is the description of the object and the object in an instance of the class. For example the class of humans would describe us as having the attributes such as arms, hands, legs and heads; and methods such as talk, think, eat, and sit. However each of us would be an instance of that class, an object. If I can jump it’s because humans can jump, if I can laugh, it’s because humans can laugh. That is, the class defines the methods and attributes for each object belonging to that class.

3.
Parent and child classes are related by an "is a" relationship. A credit-card drinks machine is a drinks
machine, and a grandfather-clock is a clock. Inheritance extends not just to parents, but to
grandparents and great-grandparents and so on as well. So a credit card drinks machine is a drinks
machine is a vending machine is a machine. The further up the ancestry we go, the more generalised
things become.
We should note that there’s a difference between "is a" relationships and "has a" relationships. A car
has a steering wheel (which may be a class unto itself that inherits from a steering device class), but
it is not a steering wheel. A car has a headlight (or two) but the car is not a headlight. On the other
hand, the car may inherit from the vehicle class and hence we’d say the car is a vehicle. It’s usually
fairly straight forward to determine which is the correct relationship

Comments

Popular posts from this blog

How to Use Chisanbop (Korean Finger Math) for Basic Addition and Counting | eHow.com

How to Use Chisanbop (Korean Finger Math) for Basic Addition and Counting eHow.com Difficulty: Easy Instructions Step 1 In Chisanbop you'll be using your two hands and ten fingers to represent numbers from 0 to 99. Start out with your hands out in front of you with closed fists. This represents 0. Each finger (not thumb) on your right hand represents 1. To represent 3, just press down three right hand fingers. Your right thumb represents 5. To represent 7, press down your right thumb and 2 right hand fingers. Think of your right hand as the ones or units place (column). Step 2 Your left hand represents the tens place (column). Each finger on your left hand is worth 10. For example, to represent 30, press down three left hand fingers. To represent 38, do the same, but also use your right hand to represent 8 as described above. Your left thumb represents 50. To represent 86, press down your left thumb and three left hand fingers for the 80, and your right thumb and one righ

How to load the sample database into the MariaDB server.

1. Download  the Sample Database  (Source :  https://www.mariadbtutorial.com/getting-started/mariadb-sample-database/  ) 2. unzip the file to a directory e.g.,  c:\mariadb\nation.sql 2.   connect to the MariaDB server  with the  root  user account, type the password and press the   Enter  keyboard. sudo mysql -u root -p Enter password: ******** 3.  Load the database by using the source command: mysql>source c:\mariadb\nation.sql 4.  select the   nation   database and display tables of the database: mysql> use nation; Database changed mysql> show tables ;