CIW Course Revision Site


Tutor Marked Assignment PL TMA-11A

In a Nutshell - CIW Course Section 2 Part B

PL TMA-11A - CD Access Code: not required

Part A.

If you find yourself at a complete loss with this assignment then click HERE.

Q1. Create a Perl program to acquire customer information for an optician's practice. Save the program in a file titled optician.pl.

When the program is run, the user should be prompted to enter a four digit customer reference number. The user should then be prompted to enter new customer details. These prompts should be given in the following sequence:

  • Title
  • Surname
  • Forename
  • Sex
  • Date of Birth
  • Vision measurement

All inputs should be verified. Any input which fails the verification should result in a suitable error message being displayed, along with another prompt for the same item to be entered again. The verification should be as follows:

  • Customer Reference - 4 digits only
  • Title - between 1 and 4 alphabetic characters. The allowable list of titles is Dr, Lady, Lord, Miss, Mr, Mrs, Ms, Sir.
  • Surname = between 1 and 20 alphabetic characters
  • Forename - between 1 and 20 alphabetic characters
  • Sex - 1 character, either M or F (upper or lower case acceptable)
  • Date of Birth = in the format DD/MM/YYYY
  • Vision measurement - 1 or 2 digits (i.e. between 1 and 99)

The date of birth input does not need to be checked for date validity, e.g. 99/99/9999 should be accepted. However, you should check that the digits and forward slash characters are in the DD/MM/YYYY form, e.g. 3/10/2004 should be rejected whereas 03/10/2004 is acceptable.

 

Q2. Amend optician.pl so that entries of customer records are stored in a file called CustData.txt. Save this revised program in a file titled optician2.pl.

The individual customer fields should be written separated by a comma, and each complete customer record terminated by a newline character: For example:

1234,Dr,Huxtable,Cliff,M,24/12/1976,60
5678,Miss,Smith,Mary,F,15/03/1874,35
9012,Mr,Smith,Joseph,M,02/02/1972,40

When the program is run, it should test for the existence of the CustData.txt file and create it if it doesn't already exist. When the user enters a customer reference, the file should be checked to ascertain whether the customer reference is already in use. If it is, the customer details for that reference number should be displayed. If not, the details for a new customer should be input and written to the file.

Print and submit a copy of CustData.txt showing five example customers using data of your choice.

Q3. The optician will like to get some statistics regarding customer's vision measurements. Create a separate program, called measurements.pl.

This program should display a breakdown of vision measurements. A count of the number of customers within vision ranges should be made and the results displayed in a table:

Range 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-99
Count 0 3 2 2 1 1 1 0 0 0
Percent 0 30 20 20 20 10 10 0 0 0

 

In the above example, there are three customers with vision measurements within the 11-20 range, two within 21-30, two within 31-40, etc. Overall, in this example there are 10 customers. The percentages should be calculated from the number within the range divided by the total number of customers, e.g. for the 21-30 range there are 2 customers so the percentage is (2/10)*100.

Q4. Amend the measurements.pl program so that it initially displays a prompt to allow the user to specify whether the output is displayed to the screen or to a file (for example, by entering an 'S' or an 'F').

If to file, the user should also be prompted to enter a suitable filename. This filename should be checked to ensure it complies with the following rules:

  • No greater than 8 characters in length
  • No file extension allowed
  • At least 3 characters
  • Must start with a letter, although digits are permitted for characters other than the first

Once a valid filename is given, it should have the ".txt" extension added. This complete filename should then be checked to ensure that a file of that name does not already exist. If it does the user should be prompted as to whether the file should be overwritten or not by way of 'Y' or 'N' character input. If not, a new name should be prompted for and input.

Part B.

Q1. A motor vehicle is a people and goods carrier that is powered by an engine. It has wheels and it can have doors.

A private vehicle is a motor vehicle that is owned by an individual.

A family car is a private vehicle designed to carry 5 passengers and 50lbs of goods. It has 4 wheels.

A sports car is a private vehicle designed to carry 1 or 2 passengers and 0lbs of goods. It has 4 wheels

A public vehicle is a motor vehicle that is used by more than one person on a pay-per-use basis.

A bus is a public vehicle designed to carry 50 passengers and 200lbs of goods. It has 10 wheels

A train is a public vehicle designed to carry 200 passengers and 800lbs of goods. It has 100 wheels.

 

Define an inheritance structure where each type of vehicle is in a separate module. Each module will give a simple print statement.

E.g.

The motor vehicle class will print three statements.
"I have an engine"
"I have wheels"
"I have doors"

Create a class for each type of vehicle. You should have 7 classes in total. Wheels, doors, goods and passengers are all defined with variable of the integer type.

In your main package you will print the details of each type of vehicle.

E.g
Family Car
"I have an engine"
"I have wheels"
"I have doors"
"I am private"
"I carry 5 passengers"
"I carry 50lbs"

Save this program as motorVehicle.pl. Submit a soft copy of this program. Print and submit screen shots of the output.

Q2. Write a program which reads from a text file and counts the number of punctuation characters used within it.

The name of the file should be prompted from the keyboard when the program is run. For example, if you provide the name of the file containing the following text:

The object-oriented (OO) features of Perl can make your scripts easier to reuse. You can use either OO or structured programming to write your Perl scripts. However, whenever your scripts are long and complex, you will find that the features and techniques in OO Perl make your scripts easier to maintain and reuse.

Unlike OO programs, structured programs focus their attention on the flow of information. Data is generally generated outside the script and flows through a set of data-handling subroutines to produce some output.

Data, in the form of objects, are the fundamental component of any OO model. The data and the subroutines, or methods, that act on data are combined into a single entity, called an object.

The output from the program should be:

2 hyphens
1 open bracket
1 close bracket
7 full stops
7 commas

Hint: you will need to have some way of tying the punctuation character to its equivalent English name. Think ASCII and hash. Only those punctuation characters within a standard ASCII character set need to be checked for.

Produce screenshots of the output from your program, along with the source file used. At least one Perl script should be tested as an input for your program.

Q3. Write a program to ask a user 7 questions. It reads the answers and shows the number of answers that were right.

The format of the questions is: Please enter n things in which n is a number between 1 and 10 and things is one of three symbols $, £, &.

E.g.

Please enter $ three times: $$$
    Correct!
Please enter $ six times: *****
    Wrong.
...

You got 5 correct answers.

Q4. Write a program that reads from a text file, then prints the number of lines, words and characters in the input, followed by the text as a string without white space (tabs, spaces, or return characters) or punctuation and all lowercase.

E.g.

Hey, diddle, diddle,
The cat and the fiddle,
The cow jumped over the moon.
The little dog laughed
To see such sport,
And the dish ran away with the spoon.

Output:
lines: 6
words: 30
characters: 154

String:
heydiddlediddlethecatandthefiddlethecowjumpedoverthemoonthelittledogla
ughedtoseesuchsportandthedishranawaywiththespoon

Print and submit the results in a text file called StringText.txt


If you are really stuck with this assignment, then I will gladly send you a copy of my solution. I will need to make a modest administrative charge for this, and I would strongly advise that you edit it extensively before submission. In particular, I would recommend you use your own data. My solution is not perfect, but it did score 100% and should give you some ideas.

The charge for this will be £2.75 (UK Pounds) and payment is only possible via PayPal.

The files will be compressed with WinZip and may be downloaded via the PayLoadz service that you will be directed to after payment is complete.

Sign up to PayLoadz

to sell your file downloads.

Design by Stephen

Certified Internet Webmaster

Page last Edited: 25 Nov 2011