Create a program that allows stores data about an entity in


Pass Task 4.1: Using Records and Enumerations

Overview

Effectively organising your data makes programs much easier to develop. By using records and enumerations you can start to model the entities associated with your programs.

Purpose: Learn to use records and enumerations to start managing the data in your programs.

Task: Create a program that allows stores data about an entity in a record in your program, and then echo this back to the terminal.

Instructions

Implement one of the following five programs. In this program you will need to declare a record and an enumeration, as well as create functions and procedures to work with these new types you have created.

The following steps will help you implement your chosen program.

1. Start by creating a new program file in Sublime Text.

2. Implement the basic outline of the program with a Main procedure.

3. Use the Terminal User Input unit so that you have access to ReadString and ReadInte- ger.

4. Declare the enumeration using the list of options provided.

5. Declare the record. It will have a number of fields, each of which is like a variable within the record.

6. Create the function to read in a value of the enumeration from the user. The easiest option is to show the user a list of options, and then read in an integer. You can then use a case statement (or type casting) to convert the integer into the appropriate value from the enu meration. This will need to be above Main, but below you type declarations.

7. Create the function to read in a value from the user. This will read in data from the user, and use this to populate the fields of the record.

8. To validate the fields of the record you will need to use a while loop. This should show an error message while the user has not entered a valid value, and continue to ask them to enter the data until it is valid.

9. Create the procedure to print a record value to the Terminal. This will accept a parameter, and print the values from its fields to the terminal in the format indicated. Remember to use an if statement to check which, if any, of the additional details you need to write.

10. Implement Main, which will need to declare a local variable of the record's type and use the functions and procedures you have created to read and print its value.

11. Your program should now be complete. Make sure you test it at the Terminal to make sure that it works as you expect.

The five different programs you can choose from are:

1. Cost Calculator: reads in and prints expense data.

2. Instrument Readings: reads in and prints values from sensors.

3. High Scores: reads in and prints values for a high score table.

4. Bounty Hunters Hit List: read in hits for your local bounty hunter.

5. Make your own...

Option 1: Cost Calculator

In this task you will start to create a program that will calculates the costs of aspects of a project. The program will allow the user enter details for an expense, and then print its details to the Terminal.

This program will use an Expense Data record to store and work with expense data. Each ex- pense has a name (a string), an expense id (an integer), a kind (an Expense Kind), and a cost (an integer). There are three kinds of Expense (Expense Kind): Fixed Expense, Flexible Expense, and Discretionary Expense.

The program must include the following:

- A Read Expense Kind function that asks the user to select an Expense Kind, validates the user's data entry, and then returns the entered Expense Kind.

- A Read Expense function that reads in an expense's details from the user and returns it to the calling code as an Expense Data value. It must ensure that cost is not a negative value (so it is positive or 0), asking the user to reenter the value while not valid.

- A Print Expense procedure that accepts an Expense Data parameter and prints the details of this expense to the terminal in the format ‘name (expense id), kind, $cost' followed by ‘re- quires justification' if the cost is larger than 5000, or ‘required authorisation!' if cost is larger than 10000.

- A Main that declares an ExpenseData value. It will then perform the following steps:
1. Print the message ‘- Enter Expense Data -'
2. Use Read Expense to read in an Expense from the user, and store it in Main's local vari- able.
3. Print the message ‘- You Entered -'
4. Call Print Expense to output the value entered by the user.

Option 2: Instrument Readings

In this task you will start to create a program that will read values from physical sensors (tem- perature, flex, light, etc) which could then be used to control other devices. At this stage, the program will allow the user enter sensor details at the Terminal, and will print the values back to the Terminal.

This program will use a Sensor Data record to store and work with sensor readings. Each Sensor Data value has notes (a string), an reading id (an integer), a kind (an Sensor Kind), and a value (a double). There are three kinds of Sensors (Sensor Kind): Temperature Sen- sor, Flex Sensor, and Light Sensor.

The program must include the following:
- A Read Sensor Kind function that asks the user to select a Sensor Kind, validates the user's data entry, and then returns the entered Sensor Kind.

- A Read Sensor Data function that reads in a sensor reading from the user and returns it to the calling code as a Sensor Data value. It must ensure there are notes provided (its Length is larger than 0), asking the user to reenter the value while not valid.

- A Print Reading procedure that accepts a Sensor Data parameter and prints the details of this reading to the terminal in the format ‘kind: value (reading id), notes' followed by ‘check sensor' if the value is 0, or ‘check reading' if value is larger than 100.

- A Main that declares a Sensor Data value. It will then perform the following steps:

1. Print the message ‘- Enter Reading -'

2. Use Read Sensor Data to read in the value from the user, and store it in Main's local vari- able.

3. Print the message ‘- You Entered -'

4. Call Print Reading to output the value entered by the user.

Option 3: High Scores Log

In this task you will start to create a program that will store game scores that could be used to keep track of score ranks. At this stage the program will allow the user to enter game details at the Terminal, and it will then print these values back to the Terminal.

This program will use a Game Score Data record to store and work with game scores. Each Game Score Data value has user name (a string), an game id (an integer), a difficulty (a Difficulty Kind), and a score (an integer). There are three kinds of Difficulty (Difficulty Kind): Normal Difficulty, Hard Difficulty, and Insane Difficulty.

The program must include the following:

- A Read Difficulty function that asks the user to select a Difficulty Kind, validates the user's data entry, and then returns the entered Difficulty Kind.
- A Read Game Score Data function that reads in the game score data from the user and re- turns it to the calling code as a Game Score Data value. It must ensure that the score is 0 or larger, asking the user to reenter the value while not valid.

- A Print Score Data procedure that accepts a Game Score Data parameter and prints the details of this score to the terminal in the format ‘user name: score (game id - difficulty)' fol- lowed by ‘Newb' if the value is less than 1000, or ‘Godlike' if value is larger than 100000.

- A Main that declares a Sensor Data value. It will then perform the following steps:
1. Print the message ‘- Enter Score Data -'
2. Use Read Game Score Data to read in the value from the user, and store it in Main's local variable.
3. Print the message ‘- You Entered -'
4. Call Print Score Data to output the value entered by the user.

Option 4: Bounty Hunter's Hit List

In this task you will start to create a program that will store hits for a Bounty Hunter. At this stage the program will allow the user to enter a Hit at the Terminal, and it will then print these details back to the Terminal.

This program will use a Target Data record to store and work with the hits. Each Target Data value has a name (a string), an hit id (an integer), a difficulty (a Difficulty Kind), and a value (an integer). There are three kinds of Difficulty (Difficulty Kind): Normal Difficulty, Hard Diffi- culty, and Insane Difficulty.

The program must include the following:

- A Read Difficulty function that asks the user to select a Difficulty Kind, validates the user's data entry, and then returns the entered Difficulty Kind.

- A Read Target Data function that reads in the hit data from the user and returns it to the call- ing code as a Target Data value. It must ensure that the value is 0 or larger, asking the user to reenter the value while not valid.

- A Print Target procedure that accepts a Target Data parameter and prints the details of this hit to the terminal in the format ‘difficulty: target (hit id) $value' followed by ‘low priority' if the value is less than 10000, or ‘high priority' if value is larger than 1000000.

- A Main that declares a Target Data variable. It will then perform the following steps:

1. Print the message ‘- Enter Hit Data -'

2. Use Read Target Data to read in the value from the user, and store it in Main's local vari- able.

3. Print the message ‘- You Entered -'

4. Call Print Target to output the value entered by the user.

Option 5: Make your own...

Use the above four declarations guide you to create your own program. It must have the same features:
- An enumeration with at least 3 options.
- A record with at least 4 fields, one being of the enumeration's value and the others using dif- ferent types (a mix of types: string, integer, and double).
- A read function to read in the enumeration and record.
- The read function must validate at least one of the fields.
- A print procedure to output a record's data to the terminal.
- The print procedure must have at least two messages based on values from within the record's fields.
- Main will create a variable of the record's type.
- The read function is called to provide the value you assign to the variable.
- The print procedure is called to output the value from the variable.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Create a program that allows stores data about an entity in
Reference No:- TGS01401927

Expected delivery within 24 Hours