Question: Createa text file named reflect.txt Record your answer in the reflect.txt file for each of the following :1.Structures data types can demand a lot of
Createa text file named reflect.txt
Record your answer in the reflect.txt file for each of the following
:1.Structures data types can demand a lot of memory (for example the "ReportData" structure). Without digging into advanced memory management (for example padding), how many bytes of memory would the"ReportData" structure require? How could we improve the passing of this information to functions? Use the function "displayReportData" from this workshop in your explanation.
2.The CatFoodInfo structure and the ReportData structure contain common members. How could the "ReportData" structure be improved? Show the new and improved "ReportData"structure with your changes, then show how you would modify your code in the function "displayReportData". Specifically, show how you would need to modify the printf statement that displays the data.
i want the answer for this 2 questions please.
i will attached you the output for this program and the main code for this program, so you will be able to answer the 2 questions above.
#include
#include "w6p2.h"
#define TEST_NEG -1 #define TEST_ZERO 0 #define TEST_INT 24 #define TEST_DBL 82.5 #define TEST_LBSKG 2.20462 #define TEST_LBSG 2494 #define TEST_LBS 5.5
// --------------------------------------- // Function prototypes // --------------------------------------- int testIntFunction(void); int testDoubleFunction(void); int testConvertLbsKg(void); int testConvertLbsG(void); int testConvertLbs(void);
// --------------------------------------- // Main entry-point to the program // --------------------------------------- int main(void) { int preTestFailed = 0;
printf("============================ "); printf("Pre-testing Helper Functions "); printf("============================ ");
preTestFailed += testIntFunction(); preTestFailed += testDoubleFunction(); preTestFailed += testConvertLbsKg(); preTestFailed += testConvertLbsG(); preTestFailed += testConvertLbs();
if (preTestFailed) { printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "); printf(" Pretesting revealed ERRORS in the helper functions. "); printf(" Review where the tests failed and fix these errors "); printf(" before continuing. "); printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "); } else { printf("=========================== "); printf("Starting Main Program Logic "); printf("=========================== ");
// Entry-point to program logic start(); }
return 0; }
// --------------------------------------- // Function definitions // ---------------------------------------
int testIntFunction(void) { int intA = 0, intB = 0, fail = 0;
printf("------------------------ "); printf("Function: getIntPositive "); printf("------------------------ "); printf("For each of these tests, enter the following "); printf("three values (space delimited): %d %d %d ", TEST_NEG, TEST_ZERO, TEST_INT);
//----------------------------------- // Test-1: argument and return value printf("TEST-1: "); intB = getIntPositive(&intA); if (intA == intB && intA == TEST_INT) { printf("
//----------------------------------- // Test-2: return value only intA = intB = 0; printf("TEST-2: "); intA = getIntPositive(NULL); if (intA == TEST_INT) { printf("
//----------------------------------- // Test-3: argument only intA = intB = 0; printf("TEST-3: "); getIntPositive(&intA); if (intA == TEST_INT) { printf("
return fail; }
int testDoubleFunction(void) { double dblA = 0.0, dblB = 0.0; int fail = 0;
printf("--------------------------- "); printf("Function: getDoublePositive "); printf("--------------------------- "); printf("For each of these tests, enter the following "); printf("three values (space delimited): %d %d %.1lf ", TEST_NEG, TEST_ZERO, TEST_DBL);
//----------------------------------- // Test-1: argument and return value printf("TEST-1: "); dblB = getDoublePositive(&dblA); if (dblA == dblB && dblA == TEST_DBL) { printf("
//----------------------------------- // Test-2: return value only dblA = dblB = 0.0; printf("TEST-2: "); dblA = getDoublePositive(NULL); if (dblA == TEST_DBL) { printf("
//----------------------------------- // Test-3: argument only dblA = dblB = 0.0; printf("TEST-3: "); getDoublePositive(&dblA); if (dblA == TEST_DBL) { printf("
return fail; }
int testConvertLbsKg(void) { double dblA, dblB, lbs= TEST_LBS; int fail = 0;
printf("--------------------------- "); printf("Function: convertLbsKg "); printf("--------------------------- ");
//



Dear just answer the first 2 question from the reflection, you can answer it by text message you don't need to write any code. Thanks
double weightKgs; int weightGms; double totalServing; double costPerserving; double costPerCal; Struct CatFoodInfo catFood; }; struct CatFoodInfo { int productsku; double price; int calPerserving; double weightLbs; };
And we can show printf like this:
printf ("% 07d% 10.2lf% 10.1lf% 10.4lf% 9d% 8d% 8.1lf% 7.2lf% 7.5lf", data.catFood.productSku, data.catFood.price, data.catFood.weightLbs, data.weightKgs, data.weightGms, data.catFood. calPerServing, data. totalServings, data.costPerServing, data.costPerCal);
The improved code makes it easier to read by programmers and can fix any errors again.
Pre-testing Helper Functions Function: getInt Positive For each of these tests, enter the following three values (space delimited): 10 24 TEST-1: -10 24 ERROR: Enter a positive value: ERROR: Enter a positive value:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
