write a c++ program that stores the following numbers in the array named
miles:15,22,16,18,27,23, and 20. have your program copy the data stored in miles to another program named dist, and then display the values in the dist array. your program should use pointer rotation when copying and displaying array elements.

i write this program. hope any1 could help me out.

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    const int MILES = 7;
    int *dist;
    int i, nums[MILES] = {15,22,16,18,27,23,20};
    cout << "Miles" << "\t" << "Distance" << endl;
    for (i=0;i< MILES; i++)
    {
    dist = nums;
    cout << nums[i] << '\t' << *(dist+i);
    cout << endl;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}

my teacher said that i will add functions to it. and im really confused about it and to the pointer rotation that will i add. please help me out guys. i really need this to pass my subject :) hope u can help me.

You need to start by initializing your "dist" array properly. Currently, it is not an array, and it is not initialized. It is a pointer to a single int. If you try to use it as an array, you will cause a segmentation fault at run time.

To accomplish this, you will need to write at least 1 function, a copy function. For practice, I would also recommend a display function.

Since this needs to be done with pointer notation, both functions will need at least 1 pointer parameter and a "size" parameter. The copy function would need an additional pointer parameter to accept a second array.

Here is the prototype I used for the copy function. See if you can figure out how to write the definition and how to call it properly.

void copy(const int * const src, int size, int * const dest);

where will i put that? story for the stupid question sir. cause im really having a hard time in programming. :( can u edit my work and place it there? thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.