Create a program that allows stores data

Assignment Help Programming Languages
Reference no: EM131056086

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.

Reference no: EM131056086

Questions Cloud

Carefully and clearly outline map of the region on a blank : On a blank outline map of the region, carefully and clearly label 20 of the physical features found within North America that you have selected based on reading Chapter 2 or from additional sources.
What you agree or disagree with and ah-ha moments : The best article reviews also tie the article to the materials we have learned in class. Focus equal attention on each of the two sections (summary and insights). Discuss the relevancy of your new material to the course material and conflict coachi..
How much heat was released per gram of fuel burned : The heat capacity of the calorimeter hardware is 150 J/?C. How much heat was released per gram of fuel burned? Please answer in J/g.
What is the pressure of the gas : A 0.032 mol sample of gas occupies a volume of 350ml at 300K. What is the pressure of the gas?
Create a program that allows stores data : Create a program that allows stores data about an entity in a record in your program, and then echo this back to the terminal - Effectively organising your data makes programs much easier to develop.
Identify two patient rights and two patient responsibilities : Identify two patient rights and two patient responsibilities. Then, choose one of each (patient rights and patient responsibilities) and explain their purpose and effects in detail, providing examples.
Describe management role within a work environment : Describe your current or past organization (or another selected organization) and how the organization's actions, policies, and practices compare to your two researched organizations.
Restore power to the freezer : After 24 hours, the local electrician was able to restore power to the freezer, allowing the freezer to return to a temperature of -5 °C and a pressure of 0.95 atm.
What is the total heat flow : Consider a chemical reaction that does 310 J of work and decreases the internal energy by 31 kJ. What is the total heat flow?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a method that returns the value of base exponent

Write a method IntegerPower(base, exponent) that returns the value of base exponent For example, IntegerPower(3, 4) = 3 * 3 * 3 * 3.

  Choose two different formats for audio and with each record

Choose two different formats for audio and with each record a short passage of speech and a short passage of music. Try to discern any difference in quality. What do you think?

  Modify the dynamic programming algorithm

How would you modify the dynamic programming algorithm for the coin collecting problem if some cells on the board are inaccessible for the robot?

  Program to calculate interest on account balance

10% of total amount owed, which ever is larger. Program comprises loop which lets user repeat this computations until user says she or he is done.

  Explain different kind of product sold

Use two-dimensional array to solve following problem. Company has four salespeople(1 to 4) who sell five different products (1 to 5). Once day, each salesperson passes slip for each different kind of product sold.

  Discuss what is meant by low-level programming

Discuss what is meant by "low-level" programming. What are the advantages of assembly language over higher-level languages for this type of programming?

  Validation case using regexp

The user must enter a valid IPV4 number in the range 0.0.0.0 to 255.255.255.255(decimal numbers). The number in each category must be between 0-255.

  Program for vehicle registration department

Consulting firm has narrowed the choice of programming language to Java and C#. Which language do you believe would be more suitable for this application and why?

  Is this an example of head or tail recursion

Referring to the code in Part 1, use the substitution model to illustrate what the result of calling (add1-iter '(1 2 3)) will be. Why is the list reversed ?

  Develop project to calculate checking account balance

Develop project to calculate your checking account balance. Form: Include radio buttons to indicate the type of transaction: deposit, check, or service charge.

  Create the behavioral vhdl model for thirty two-bit alu

Create the behavioral VHDL model for 32-bit ALU. The ALU has 4-bit "op" control singal. Relationship between the "op" and operations of ALU.

  Identify two major segments erp systems

And a brief summary describing how such a system would be installed/implemented

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd