Question: 1 . Write all programs in cross - platform C + + 2 . No Containers, NO STL allowed { Vector , Lists, Sets, etc...

1. Write all programs in cross-platform C++
2. No Containers, NO STL allowed {Vector, Lists, Sets, etc...}
3. Simple Old-fashion C++. No modern C++
4. No Adding files
1. Alignment : Identifying data layout and alignment for supplied data structures(C++ classes)
Rework the data structures in ReworkData.h
o Rearrange the data layout to make the size smaller
o Explicitly name any padding in the structure
char pad0; // for example
Create a Print function to show alignment
o Update the Align::PrintMe(...) function to print the alignment
o Use Trace::out2(...) to display the data layout and padding
Make sure you use out2() and not out()
data A:
0x00: 00000000
0x04: 00 aa aa aa
------------------------
size : 8 padding : 3
o Needs to visually show the padding and alignment
Total number of bytes
Number of padding bytes
o Mimic the KeenanSampleOutput_Debug.txt
No Templates or Boost allowed
o Use only simple C++(classes and methods)
Align.h (Do not modify) :
#ifndef ALIGN_H
#define ALIGN_H
class Align
{
public:
struct Info
{
int NumTotalBytes;
int NumBytesOfPadding;
};
static Info PrintME(void *p, int StructSize, char *s);
};
#endif
//--- End of File ---
Align.cpp:
#include "Align.h"
//-------------------------------------------------------------
// PrintME()
// Write your alignment printing function here
//-------------------------------------------------------------
Align::Info Align::PrintME(void *pData, int StructSize, char *pString)
{
// Use Trace::out2(...) to display the data layout and padding
// NOTE: out2() NOT out()
// it won't be graded without out2()
// Mimic the Output
AZUL_REPLACE_ME(pData);
AZUL_REPLACE_ME(StructSize);
AZUL_REPLACE_ME(pString);
Info info;
info.NumBytesOfPadding =0;
info.NumTotalBytes =0;
return info;
}
//--- End of File ---
AlignData.h
#ifndef ALIGN_DATA_H
#define ALIGN_DATA_H
//-----------------------------------------------------------
// Add default constructor to each structure
// Initialize all variables to 0
// Do NOT rearrange any data layout...
// These are the classes used with Align::PrintMe();
//-----------------------------------------------------------
struct A
{
// Hint add the default constructor and set variables to zero
int a0;
char a1;
};
struct B
{
float b0;
float b1;
bool b2;
float b3;
};
struct C
{
char c0;
double c1;
char c2;
};
struct D
{
A d0;
double d1;
B d2;
char d3;
C d4;
};
struct E
{
A a0;
C c0;
char aa;
B b0;
};
#endif
//--- End of File ---
AlignData.cpp:
#include "AlignData.h"
// Insert code
//--- End of File ---
ReworkData.h:
#ifndef REWORK_DATA_H
#define REWORK_DATA_H
struct DataA {
char a;
double r;
char b;
};
struct DataB {
int i;
char a;
DataA da;
char b;
};
struct DataC {
int j;
char a;
int i;
bool f;
};
struct DataD {
int i;
char a;
double r;
char b;
};
struct DataE {
char name[12];
int x;
char a;
double r;
int *p;
char c;
};
struct Vect {
float vx;
float vy;
char a;
float vz;
float vw;
char b;
};
struct DataF {
int i;
Vect v;
char c;
int j;
char b;
};
struct DataG {
DataA a0;
char b0;
double d0;
char c0;
Vect v;
double d1;
};
#endif
//--- End of File ---
Output like This :
data A:
0x00: 00000000
0x04: 00 aa aa aa
------------------------
size : 8 padding : 3
data B:
0x00: 00000000
0x04: 00000000
0x08: 00 aa aa aa
0x0c: 00000000
------------------------
size : 16 padding : 3
data C:
0x00: 00 aa aa aa
0x04: aa aa aa aa
0x08: 00000000
0x0c: 00000000
0x10: 00 aa aa aa
0x14: aa aa aa aa
------------------------
size : 24 padding : 14
data D:
...

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!