Question: A file named input.txt contains valid C++ code which declares a user-defined type (i.e., a struct). The size of its members determines the size of

A file named input.txt contains valid C++ code which declares a user-defined type (i.e., a struct). The size of its members determines the size of a struct in bytes. For this question, the types of a user-defined type's members are limited to int, float, double, char, and arrays of int, float, double, and char. The size of int, float, double, and char are 4, 4, 8, and 1 byte(s), respectively.

For example, consider the contents of the file input.txt as shown below:

input.txt

structComplexType{

char locs [4] = "hi!!";

int x = 1;

float y ;

double z [2] = {892.0,234};

};

The size of the ComplexType above is calculated as 4(the size of a char) + 1(the size of int) + 1(the size of float) + 2(the size of double) = 41 + 14 + 14 + 28 = 28 bytes.

how to write a program which reads the struct definition from input.txt character by character and outputs its size in bytes as a single integer to the console. The file input.txt only contains the C++ code required to define the struct. This code does not contain any syntax errors, comments, include statements or functions. In this question, you are not allowed to use any of the functions built into the C-string library. The output is shown below is generated from the input.txt in the example above.

output: 28

Only use from these libraries: #include

#include

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!