i\'m working on an answer right now, did this in another class already. will pos
ID: 3543438 • Letter: I
Question
i'm working on an answer right now, did this in another class already. will post soon, please rate!!!
Implement the printMemory(int*,size_t) and printMemory(long long*,size_t) functions in the given source code.
/*
* Will print two arrays to the screen, one int and one long long.
* Rather than print the values, this program will only print
* the position of each value along with its location in memory
* (in hex AND integer format).
*/
#include <iostream>
#include <cstdlib>
using namespace std;
/* Will print each sequential int value's position in the array
* and its memory location to the screen (in hex and in integer format).
*
* e.g int array[] = {1,2,3};
* printMemory(array,3);
* // 'Position: 0 Address (hex): 0x14fe420 Address (int): 1284059040'
* // 'Position: 1 Address (hex): . . . '
*
* @require length > 0
* @ensure valid memory locations are iterated over and accessed
*/
void printMemory(int *array, size_t length);
/* Will print each sequential long long value's position in the array
* and its memory location to the screen (in hex and in integer format).
*
* e.g long array[] = {1,2,3};
* printMemory(array,3);
* // 'Position: 0 Address (hex): 0x14fe420 Address (int): 1284059040'
* // 'Position: 1 Address (hex): . . . '
*
* @require length > 0
* @ensure valid memory locations are iterated over and accessed
*/
void printMemory(long long *array, size_t length);
int main() {
int int_array[] = {4605,4669,4669,2805,5378,6138,9726,7226,3875,7536,8563,
2911,6223,7054,1483,9555,9316,1184,8308,5474,7188,8544,5850,8564,8498,
4462,7638,4358,3827,6243,8038,3686,9553,8916,3023,8494,9045,2323,5789,4885,
4662,9886,5500,3435,5554,8134,8438,1746,1723,4196,7933,7748,5013,3138,
7843,3669,1820,4634,7818,2390,9588,2120,2926,1461,3307,8164,8591,4323,9273,
6279,9807,6391,3755,6720,8272,3823,5089,5439,3483,8107,8096,9769,7299,
9622,3786,9631,9565,1839,2121,9319,4083,9156,1817,5584,6580,7905,1529,6328,
6862,4823,6178,8519,8700,8525,8463,6060,3908,6880,9509,4440,2413,6190,
6184,4823,2007,6132,9726,3460,5701,1177,6791,2646,5596,1384,2996,1586,2366,
9921,3251,2643,1736,2567,2745,3668,2281,8720,7080,2185,5572,4580,2819,
9314,3939,8759,7117,6211,5497,5378,7734,5577,7504,7245,3790,3878,3175,2950,
3885,6177,8281,3529,8161,4719,2149,4663,2197,9099,8904,7479,2303,2524,
5475,1570,3946,9619,3115,5309,5462,4032,3242,1078,7072,5410,2847,5739,9388,
1053,8756,6577,7582,2281,5420,6581,5326,4477,8181,1947,3025,7565,6596,
8413,8213,7757,3326,5845,3416,4488,4538,2362,2634,8316,9089,8678,5059,9779,
5659,3411,2842,4216,2071,4723,6243,3462,2607,9702,8751,5988,5966,9109,
7497,3330,4880,9284,1225,7849,7842,4161,6228,5015,5828,2701,3192,6752,4888,
3411,3882,7390,5878,1299,9257,1499,6143,4181,3756,2316,7353,1861,9821,
8903,5194,3067,9880,5150,6346,8624,9977,2619,1266,9306,6351,6767,6352,3743};
long long long_array[] = {61672732,69007275,95884733,50426966,84118418,
54873807,15499066,74193718,68507201,30010681,86854025,67900967,76834357,
92891936,36003851,98096153,72615010,91899737,63317604,78886665,29765558,
91622341,74712032,24943652,82359667,44714104,19689735,74973726,34141462,
33077584,40994588,84726699,36216776,58947784,10249102,74134636,42901171,
57036574,97335177,42594057,28687929,21418501,80305361,57978275,61166444,
87276122,78130970,75849089,27955524,52959897,13878410,39032219,46108043,
83448824,41450322,13941096,72509920,76379155,82732804,59377840,60234306,
86006626,73240563,45000294,66918459,91481735,70557669,47846963,66334472,
97451982,74653710,65163430,17072181,60051015,85508582,85382035,35988881,
58594650,66085259,66855830,29302616,97812352,68992566,74831555,20834395,
48160742,26483154,35497191,96109940,29070580,88784502,95105543,49732812,
44897171,24387759,55826113,86585203,41740782,33217754,55450074,65802611,
10920998,18422176,33649408,27327932,15717014,69222433,58750884,95892216,
89313764,11066532,86167273,84164733,13698099,27666800,19399390,26722640,
36219165,46880601,70295392,52240326,49889002,26221832,56909839,65387155,
90113159,52448986,64634694,25723344,37744265,26197776,85367543,17517702,
64818735,27604028,99512602,78802589,53833747,20294465,30118063,25660602,
87702122,42511687,96443214,29895908,31637162,16380626,55614255,71033816,
99241639,72267613,55948758,43503538,75748552,42890005,43004794,84303649,
41506054,80304070,72025678,19007159,95700984,93871428,54756772,76580588,
43085045,21325498,10467746,16162251,38558838,73177657,70362848,98193456,
55435164,96704698,25116011,43895354,77614972,19721108,83667015,17977724,
29705170,44221780,65219074,16079861,19547099,35828641,40687828,63224502,
28391971,13108256,52997051,90822340,89932585,45745403,44956864,72511067,
85024127,44345571,76567057,65512326,72700682,24929162,44398784,10840196,
58390309,74950525,93426951,49837244,49035885,95814501,18783585,34726639,
12236478,12339137,94400508,87857465,96937502,36623991,32768858,90593378,
25124777,31573775,24443871,97243797,28663950,49677571,37698056,92219983,
63064859,57927422,86507932,64503681,54010029,59535796,70599015,46670856,
64389373,82445880,68999705,22293658,25149356,70690321,73296427,39779516,
27619591,79743659,43656537,59011489,53114882,11714189,96973913,83926349,
98208897,92515741,50082502,28085446,89723600,12762306,46371561,80284618,
29704234,30230941,55815695,15101209,66163210,17831354,98385099,52412061,
38218037,26026040,15007939,82444379,80325480,28672120,78261325,19725737,
87952974,70347780,90003737,63938060,72470472,38671616,89144966,37540784,
84856033,47829138,53910466,29285902,56802011,97342128,57006773};
// print out the integer array's memory locations
cout << "Integer Array: " << endl;
printMemory(int_array, (sizeof(int_array)/sizeof(*int_array)));
cout << endl;
// now print the long long array's memory locations
cout << "Long Long Array: " << endl;
printMemory(long_array, (sizeof(long_array)/sizeof(*long_array)));
cout << endl;
// we're done so exit
exit(EXIT_SUCCESS);
}
Explanation / Answer
Here's the answer. Please rate! :)
/*
* Will print two arrays to the screen, one int and one long long.
* Rather than print the values, this program will only print
* the position of each value along with its location in memory
* (in hex AND integer format).
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.