Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i want the C code for this program 1. Carefully review the Part-1 Output Example (next section) to see how this program is expected

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Please i want the C code for this program

1. Carefully review the "Part-1 Output Example" (next section) to see how this program is expected to work 2. DO NOT MODIFY the "main1.c" file. This launches some pre-testing routines for two functions you need to develop getintPositive and getDoublePositive (described later) Following the pre-testing, it will call a function "start" that is the entry point to the logic of your program 3. The code you write will be placed in two additional files: "wop1.h" (header file) and "wop1.c" (source file) File w6p1.h (header file) 4. This file will contain applicable macro's (#define), structures, and function prototypes 5. Create a macro that represents the maximum number of products to analyze (used in sizing the array later-on) - define this to be 3 6. Create a macro that represents the number of grams (64) In a suggested serving 7. Create a structure "CatFoodinfo" with the following related members that can hold: a whole number for storing a product sku number (unique identifier) a double floating-point number for the product price a whole number for storing calories per suggested serving . a double floating point number for the product weight in pounds (lbs) 8. You will need to create seven (7) functions. In this file, you need to code the prototypes. Here are the names (case sensitive) of those functions including a short description to help you create the necessary return types and parameter information for each 1. getintPositive Returns an integer number Receives an address that points to a whole number data type (provide a meaningful parameter name) Note: This function returns the user-entered positive integer value in two ways: o Return value Via the pointer argument 2. getDoublePositive Returns a double floating-point number Receives an address that points to a double floating point data type (provide a meaningful parameter name) Note: This function returns the user-entered positive double floating point value in two ways: o Return value o Via the pointer argument 3. opening Message Does not return a value Receives an argument that is an unmodifiable integer value representing the number of products the user will need to enter for analyzing (provide a meaningful parameter name) 4. getCatFoodInfo Returns a "CatFoodinfo" type Receives an unmodifiable integer number representing the sequence number of the product to be entered by the user (provide a meaningful parameter name) 5. displayCatFood Header (this function is provided for you) Does not return a value nor receives any arguments 6. displayCatFoodData Does not return a value Receives multiple unmodifiable arguments representing each member of the "CatFoodinfo type (not the structure itself) Match the data types according to the member types in the "CatFoodinfo" type Note: integer types are passed by value, but double floating point types are passed by address 7. start Does not return a value nor receive any arguments This function acts as the main entry point to the logic of the application (similar to what you are used to coding in "main" only this function does not return a value) File w6p1.c (source file) 9. In this file, you will code the function definitions (the implementation of each function) 10. Include the necessary system and user-defined libraries you need for the application (system libraries use angle brackets (>), while user-defined use double quotes (*) 11. Code each function definition implementation based on the prototypes declared in the header file. Below describes each function in a little more detail: 1. getintPositive This function should accept user input for an integer value If the value entered is a negative or zero value, an error message should be displayed (see example output for the message to display) Logic should be designed to continue prompting until a positive value is entered This function must return the entered value in two ways: One by assigning the entered value to the pointer argument (only if it is NOT NULL) Two: by "return"ing the value. This provides flexibility to the "caller" of the function where the value can be captured in two possible ways for both). Refer to the main.c file to see how this function is "pre-tested" 2. RetDoublePositive This is the same as the above described getint Positive function, only this is for a double floating-point type 3. opening Message See the example output "Cat Food Cost Analysis..." Be sure to produce the number values by using the appropriate macro's defined earlier 4. getCatFoodInfo Display a message to indicate the sequence number (use argument variable) See the example output "Cat Food Product #..." Prompt the user to enter data for each member of a "CatFoodinfo" type Call appropriate helper functions to get validated user input whenever possible o Try calling the helper functions in different ways to get the return value o Suggestion-1. Try getting the function output value via the argument o Suggestion-2. Try getting the function output value via the returned value (hint send "NULL" as the argument) Return the CatFoodinfo value 5. displayCatFood Header (this function is provided for you) Use the following formatting to display the table header: printf("SKU $Price Bag-lbs Cal/Serv "); printf(". ---- "); 6. displayCatFoodData Use the following formatting do display a data row based on the arguments being received: printf("%07d %10.21f %10.11f %8d "... 7. start This is the entry-point to the logic portion of your application (called from main) Create an array variable of type "CatFoodInfo" and size it using the appropriate macro defined in the header file (be sure to initialize it to a safe empty state) You may need to declare other local variables as needed Call the necessary function that will display an opening message Nested inside an iteration construct that will iterate the necessary number of times, call the necessary function to get user input for each product and assign the function returned value to the appropriate element of the "CatFoodInfo" array variable (declared earlier). Hint: Send as an argument to the function, the iterator variable to represent the sequence number After obtaining all the product data from the user, call the necessary function that will display the table header Nested inside an iteration construct, iterate the necessary number of times for each product, call the necessary function that will display each "CatFoodinfo" record (send the necessary arguments - reminder, some are pass-by-value, and others are pass-by-address). Part-1 Output Example (Note: Use this data for submission) Pre-testing Helper Functions Function: getInt Positive For each of these tests, enter the following three values (space delimited): -1 0 24 TEST-1: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: TEST-2: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: TEST-3: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: Starting Main Program Logic Cat Food Cost Analysis Function opening Message Enter the details for 3 dry food bags of product data for analysis. NOTE: A 'serving' is 64g Cat Food Product #1 SKU ERROR: Enter a positive value: 12221 PRICE : $0 ERROR: Enter a positive value: 26.99 WEIGHT (LBS): 0 ERROR: Enter a positive value: 2.5 CALORIES/SERV.: 0 ERROR: Enter a positive value: 325 Function getCatFoodInfo Cat Food Product #2 SKU : 23332 PRICE : $41.99 WEIGHT (LBS) : 5.5 CALORIES/SERV.: 325 Cat Food Product #3 SKU : 34443 PRICE : $71.99 WEIGHT (LBS) 13.0 CALORIES/SERV.: 325 SKU $Price Bag-lbs Cal/Serv 0012221 0023332 0034443 26.99 41.99 71.99 2.5 5.5 13.0 325 325 325 Functions displayCatFood Header displayCatFoodData 1. Carefully review the "Part-1 Output Example" (next section) to see how this program is expected to work 2. DO NOT MODIFY the "main1.c" file. This launches some pre-testing routines for two functions you need to develop getintPositive and getDoublePositive (described later) Following the pre-testing, it will call a function "start" that is the entry point to the logic of your program 3. The code you write will be placed in two additional files: "wop1.h" (header file) and "wop1.c" (source file) File w6p1.h (header file) 4. This file will contain applicable macro's (#define), structures, and function prototypes 5. Create a macro that represents the maximum number of products to analyze (used in sizing the array later-on) - define this to be 3 6. Create a macro that represents the number of grams (64) In a suggested serving 7. Create a structure "CatFoodinfo" with the following related members that can hold: a whole number for storing a product sku number (unique identifier) a double floating-point number for the product price a whole number for storing calories per suggested serving . a double floating point number for the product weight in pounds (lbs) 8. You will need to create seven (7) functions. In this file, you need to code the prototypes. Here are the names (case sensitive) of those functions including a short description to help you create the necessary return types and parameter information for each 1. getintPositive Returns an integer number Receives an address that points to a whole number data type (provide a meaningful parameter name) Note: This function returns the user-entered positive integer value in two ways: o Return value Via the pointer argument 2. getDoublePositive Returns a double floating-point number Receives an address that points to a double floating point data type (provide a meaningful parameter name) Note: This function returns the user-entered positive double floating point value in two ways: o Return value o Via the pointer argument 3. opening Message Does not return a value Receives an argument that is an unmodifiable integer value representing the number of products the user will need to enter for analyzing (provide a meaningful parameter name) 4. getCatFoodInfo Returns a "CatFoodinfo" type Receives an unmodifiable integer number representing the sequence number of the product to be entered by the user (provide a meaningful parameter name) 5. displayCatFood Header (this function is provided for you) Does not return a value nor receives any arguments 6. displayCatFoodData Does not return a value Receives multiple unmodifiable arguments representing each member of the "CatFoodinfo type (not the structure itself) Match the data types according to the member types in the "CatFoodinfo" type Note: integer types are passed by value, but double floating point types are passed by address 7. start Does not return a value nor receive any arguments This function acts as the main entry point to the logic of the application (similar to what you are used to coding in "main" only this function does not return a value) File w6p1.c (source file) 9. In this file, you will code the function definitions (the implementation of each function) 10. Include the necessary system and user-defined libraries you need for the application (system libraries use angle brackets (>), while user-defined use double quotes (*) 11. Code each function definition implementation based on the prototypes declared in the header file. Below describes each function in a little more detail: 1. getintPositive This function should accept user input for an integer value If the value entered is a negative or zero value, an error message should be displayed (see example output for the message to display) Logic should be designed to continue prompting until a positive value is entered This function must return the entered value in two ways: One by assigning the entered value to the pointer argument (only if it is NOT NULL) Two: by "return"ing the value. This provides flexibility to the "caller" of the function where the value can be captured in two possible ways for both). Refer to the main.c file to see how this function is "pre-tested" 2. RetDoublePositive This is the same as the above described getint Positive function, only this is for a double floating-point type 3. opening Message See the example output "Cat Food Cost Analysis..." Be sure to produce the number values by using the appropriate macro's defined earlier 4. getCatFoodInfo Display a message to indicate the sequence number (use argument variable) See the example output "Cat Food Product #..." Prompt the user to enter data for each member of a "CatFoodinfo" type Call appropriate helper functions to get validated user input whenever possible o Try calling the helper functions in different ways to get the return value o Suggestion-1. Try getting the function output value via the argument o Suggestion-2. Try getting the function output value via the returned value (hint send "NULL" as the argument) Return the CatFoodinfo value 5. displayCatFood Header (this function is provided for you) Use the following formatting to display the table header: printf("SKU $Price Bag-lbs Cal/Serv "); printf(". ---- "); 6. displayCatFoodData Use the following formatting do display a data row based on the arguments being received: printf("%07d %10.21f %10.11f %8d "... 7. start This is the entry-point to the logic portion of your application (called from main) Create an array variable of type "CatFoodInfo" and size it using the appropriate macro defined in the header file (be sure to initialize it to a safe empty state) You may need to declare other local variables as needed Call the necessary function that will display an opening message Nested inside an iteration construct that will iterate the necessary number of times, call the necessary function to get user input for each product and assign the function returned value to the appropriate element of the "CatFoodInfo" array variable (declared earlier). Hint: Send as an argument to the function, the iterator variable to represent the sequence number After obtaining all the product data from the user, call the necessary function that will display the table header Nested inside an iteration construct, iterate the necessary number of times for each product, call the necessary function that will display each "CatFoodinfo" record (send the necessary arguments - reminder, some are pass-by-value, and others are pass-by-address). Part-1 Output Example (Note: Use this data for submission) Pre-testing Helper Functions Function: getInt Positive For each of these tests, enter the following three values (space delimited): -1 0 24 TEST-1: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: TEST-2: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: TEST-3: -1 @ 24 ERROR: Enter a positive value: ERROR: Enter a positive value: Starting Main Program Logic Cat Food Cost Analysis Function opening Message Enter the details for 3 dry food bags of product data for analysis. NOTE: A 'serving' is 64g Cat Food Product #1 SKU ERROR: Enter a positive value: 12221 PRICE : $0 ERROR: Enter a positive value: 26.99 WEIGHT (LBS): 0 ERROR: Enter a positive value: 2.5 CALORIES/SERV.: 0 ERROR: Enter a positive value: 325 Function getCatFoodInfo Cat Food Product #2 SKU : 23332 PRICE : $41.99 WEIGHT (LBS) : 5.5 CALORIES/SERV.: 325 Cat Food Product #3 SKU : 34443 PRICE : $71.99 WEIGHT (LBS) 13.0 CALORIES/SERV.: 325 SKU $Price Bag-lbs Cal/Serv 0012221 0023332 0034443 26.99 41.99 71.99 2.5 5.5 13.0 325 325 325 Functions displayCatFood Header displayCatFoodData

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the preferred personality?

Answered: 1 week ago

Question

What is the relationship between humans?

Answered: 1 week ago