// main.cpp
// array pointer(s)
/* Write a program with the following functions:
Reverse Array
Write a function that accepts an int array and the array’s size as arguments.
The function should create a copy of the array, except that the element values should be reversed in the copy.
The function should return a pointer to the new array.
Array Expander
Write a function that accepts an int array and the array’s size as arguments. The
function should create a new array that is twice the size of the argument array. The
function should copy the contents of the argument array to the new array, and initialize the unused elements of the
second array with 0. The function should return a pointer to the new array.
*/
// Created by Lord Vader on 3/28/15.
// Copyright (c) 2015 Lord Vader. All rights reserved.
//
#include <iostream>
using namespace std;
void arrayReverse(int[], int); // Function Prototype
int *arryExpand(int *, int);
int main()
{
// Declare the size of the array and initialize it.
const int SIZE = 7;
int numbers [SIZE] = {2, 6, 9, 16, 23, 30, 39};
arrayReverse(numbers, SIZE);
arryExpand(numbers, SIZE);
return 0;
}
void arrayReverse(int values[], int size)
{
int *nums = values;
cout << "The elements of the original array are: \n";
cout << *nums << " ";
while (nums < &values[size - 1])
{
nums++;
cout << *nums << " ";
}
cout << "\n\nThe elements of the reversed array are: \n";
cout << *nums << " ";
while (nums > values)
{
nums--;
cout << *nums << " ";
}
}
int arryExpand(int arry, int size)
{
int *expand = new int[size * 2];
for (int i=0; i < size; i++)
{
expand[i] = arry[i];
}
for (int i = size; i < size * 2; i++)
{
expand[i] = 0;
}
return *expand;
}
Ly8gIG1haW4uY3BwCi8vICBhcnJheSBwb2ludGVyKHMpCi8qICBXcml0ZSBhIHByb2dyYW0gd2l0aCB0aGUgZm9sbG93aW5nIGZ1bmN0aW9uczoKCiAgICBSZXZlcnNlIEFycmF5CiAgICBXcml0ZSBhIGZ1bmN0aW9uIHRoYXQgYWNjZXB0cyBhbiBpbnQgYXJyYXkgYW5kIHRoZSBhcnJheeKAmXMgc2l6ZSBhcyBhcmd1bWVudHMuIAogICAgVGhlIGZ1bmN0aW9uIHNob3VsZCBjcmVhdGUgYSBjb3B5IG9mIHRoZSBhcnJheSwgZXhjZXB0IHRoYXQgdGhlIGVsZW1lbnQgdmFsdWVzIHNob3VsZCBiZSByZ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IG51bWJlcnMgW1NJWkVdID0gezIsIDYsIDksIDE2LCAyMywgMzAsIDM5fTsKICAgIAoKICAgIGFycmF5UmV2ZXJzZShudW1iZXJzLCBTSVpFKTsKICAgIGFycnlFeHBhbmQobnVtYmVycywgU0laRSk7CiAgICAKICAgIHJldHVybiAwOwp9Cgp2b2lkIGFycmF5UmV2ZXJzZShpbnQgdmFsdWVzW10sIGludCBzaXplKQp7CiAgICBpbnQgKm51bXMgPSB2YWx1ZXM7CgogICAgY291dCA8PCAiVGhlIGVsZW1lbnRzIG9mIHRoZSBvcmlnaW5hbCBhcnJheSBhcmU6IFxuIjsKICAgIAogICAgY291dCA8PCAqbnVtcyA8PCAiICI7CiAgICAKICAgIHdoaWxlIChudW1zIDwgJnZhbHVlc1tzaXplIC0gMV0pCiAgICB7CiAgICAgICAgbnVtcysrOwogICAgICAgIGNvdXQgPDwgKm51bXMgPDwgIiAiOwogICAgfQogICAgCiAgICBjb3V0IDw8ICJcblxuVGhlIGVsZW1lbnRzIG9mIHRoZSByZXZlcnNlZCBhcnJheSBhcmU6IFxuIjsKICAgIGNvdXQgPDwgKm51bXMgPDwgIiAiOwogICAgCiAgICB3aGlsZSAobnVtcyA+IHZhbHVlcykKICAgIHsKICAgICAgICBudW1zLS07CiAgICAgICAgY291dCA8PCAqbnVtcyA8PCAiICI7CiAgICB9Cn0KCmludCBhcnJ5RXhwYW5kKGludCBhcnJ5LCBpbnQgc2l6ZSkKewogICAgaW50ICpleHBhbmQgPSBuZXcgaW50W3NpemUgKiAyXTsKICAgIAogICAgZm9yIChpbnQgaT0wOyBpIDwgc2l6ZTsgaSsrKQogICAgewogICAgICAgIGV4cGFuZFtpXSA9IGFycnlbaV07CiAgICB9CiAgICAKICAgIGZvciAoaW50IGkgPSBzaXplOyBpIDwgc2l6ZSAqIDI7IGkrKykKICAgIHsKICAgICAgICBleHBhbmRbaV0gPSAwOwogICAgfQogICAgCiAgICByZXR1cm4gKmV4cGFuZDsKfQ==
Main.java:22: error: illegal character: '#'
#include <iostream>
^
Main.java:22: error: class, interface, or enum expected
#include <iostream>
^
Main.java:26: error: class, interface, or enum expected
void arrayReverse(int[], int); // Function Prototype
^
Main.java:27: error: class, interface, or enum expected
int *arryExpand(int *, int);
^
Main.java:29: error: class, interface, or enum expected
int main()
^
Main.java:33: error: class, interface, or enum expected
int numbers [SIZE] = {2, 6, 9, 16, 23, 30, 39};
^
Main.java:36: error: class, interface, or enum expected
arrayReverse(numbers, SIZE);
^
Main.java:37: error: class, interface, or enum expected
arryExpand(numbers, SIZE);
^
Main.java:39: error: class, interface, or enum expected
return 0;
^
Main.java:40: error: class, interface, or enum expected
}
^
Main.java:46: error: class, interface, or enum expected
cout << "The elements of the original array are: \n";
^
Main.java:48: error: class, interface, or enum expected
cout << *nums << " ";
^
Main.java:50: error: class, interface, or enum expected
while (nums < &values[size - 1])
^
Main.java:53: error: class, interface, or enum expected
cout << *nums << " ";
^
Main.java:54: error: class, interface, or enum expected
}
^
Main.java:57: error: class, interface, or enum expected
cout << *nums << " ";
^
Main.java:59: error: class, interface, or enum expected
while (nums > values)
^
Main.java:62: error: class, interface, or enum expected
cout << *nums << " ";
^
Main.java:63: error: class, interface, or enum expected
}
^
Main.java:70: error: class, interface, or enum expected
for (int i=0; i < size; i++)
^
Main.java:70: error: class, interface, or enum expected
for (int i=0; i < size; i++)
^
Main.java:70: error: class, interface, or enum expected
for (int i=0; i < size; i++)
^
Main.java:73: error: class, interface, or enum expected
}
^
Main.java:75: error: class, interface, or enum expected
for (int i = size; i < size * 2; i++)
^
Main.java:75: error: class, interface, or enum expected
for (int i = size; i < size * 2; i++)
^
Main.java:78: error: class, interface, or enum expected
}
^
Main.java:81: error: class, interface, or enum expected
}
^
27 errors