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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started