C++ pointer program using a struct and array of arbitary size??
ID: 3659816 • Letter: C
Question
I am stuck on this programing challenge with pointers in c++:Write a function named ArraySize() that takes 2 ptrs to the Date() structure which point, to the first and last elements of an array of Date structs. The function should return the number of bytes that the whole array(arbitrary size) uses using address arithmetic and sizeof() function applied to a Date struct.
The size should not be determined any other way. Write a driver to create an array of 7 Date structures. The dirver should then call ArraySize() function with the appropriate arguments and print out the returned result.
Here is the:
struct Date
{ int day,
month,
year;
};
Any help would be gratefully appreciated. I am stuck on this programing challenge with pointers in c++:
Write a function named ArraySize() that takes 2 ptrs to the Date() structure which point, to the first and last elements of an array of Date structs. The function should return the number of bytes that the whole array(arbitrary size) uses using address arithmetic and sizeof() function applied to a Date struct.
The size should not be determined any other way. Write a driver to create an array of 7 Date structures. The dirver should then call ArraySize() function with the appropriate arguments and print out the returned result.
Here is the:
struct Date
{ int day,
month,
year;
};
Any help would be gratefully appreciated.
Explanation / Answer
#include #include struct money { char name[80]; float balance; }; int bank(int, struct money *); int main(void) { struct money *p; int x = 1; bank(x,p); printf("%s %f ",p[x].name,p[x].balance); return 0; } int bank(int mode, struct money p) { static struct money abank[3]; //bank0 strcpy(abank[0].name,"Arthur's Bank"); abank[0].balance = 43.57; //bank1 strcpy(abank[1].name,"Pete's Savings & Loan"); abank[1].balance = 1123.80; //bank2 strcpy(abank[2].name,"T.G. Chelt's Trust"); abank[2].balance = 340.23; p = &abank[mode]; return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.