Question

Guided Exploration 06: Passing Structures and Secure Numeric Input Validation

Purpose: To demonstrate understanding of structures and secure validation of numeric

input.

Effort: Collaborate (Academic Integrity)

Points:

20 (see rubric in canvas)

Deliverables: Upload this document with your answers. Do not upload a zip file or your code.

Part 1: Structures

Part 2: Secure Validation

Part 1: Structures

Open ch10structs.c from the repository to answer the following questions.

1. Explore passing structures by reference to get information by the user entering

from the keyboard. Update void passStructBy Reference(struct employee*

employeeTestPtr) to

a. Read information from the user using scanf to get the hourly salary. No need

to validate the value. You will explore this in part 2. Think about how you

pass the hourly Salary by reference to scanf.

b. Read information from the user using fgets to get the name. Think about

how you pass the character array to fgets by reference./nCode:

2. Explain a structure and using typedef to define it.

Explain

3. Explain how structures are passed by value. Include code examples in your explanation.

Explain

4. Explain how structures are passed by reference. Include code examples in your explanation.

Explain/nUse the following Requirements to write code using structures for the property information for the following

questions.

User Story2: Rental Property Owner Set Up

As a rental property owner I want to be able to enter the property rental information so it can be

listed for others to rent.

All properties will use the following values instead of having the property owner enter them.

Minimum nights is 1

Maximum nights is 14

Minimum rate is $1

Maximum rate is $1000

Example Rental Information entered by property owner

Interval 1 Nights: 3

Interval 2 Nights: 6

Rental Rate 400

Discount 50/n6. Think about what information about the property should be included in the structure. Define the

structure below.

Code:

7. Declare a structure in main called property 1

Code:

8. Create a function setUpProperty to initialize the property information by passing the structure from main

by reference.

Code:

a. Read the numeric values in using scanf. No need to do any validation as you will be creating a

function similar to scanf in part 2.

b. Use fgets to read in the string information./nPart 2: Secure Validation

Open chap08validateint.c from the repository.

Read the following, run the code in your debugger and answer the questions below to

help you explain parts of the code.

INT05-C. Do not use input functions to convert character data if they cannot handle all

possible inputs - For this class we will use fgets not scanf even if you are on a linux

computer.

ERR34-C. Detect errors when converting a string to a number Compliant solution use

strtol ( ) and strtod ( ) and not atoi or atol

1. Run the code and debug function void exploreValidateInt(const char* buff). Enter

a valid integer.

Look at the array of characters that is stored for the inputStr and step through the

exploreValidateInt function.

Take a screenshot of what is stored in the string array after an integer value is

entered. Paste screenshot below.

Explain the problem and provide a fix.

Copy and paste the code you used to fix it.

Question image 1Question image 2Question image 3Question image 4Question image 5