Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91780489

Have any Question?


Related Questions in Programming Language

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As