fork download
  1. // main.cpp
  2. // array pointer(s)
  3. /* Write a program with the following functions:
  4.  
  5.   Reverse Array
  6.   Write a function that accepts an int array and the array’s size as arguments.
  7.   The function should create a copy of the array, except that the element values should be reversed in the copy.
  8.   The function should return a pointer to the new array.
  9.  
  10.   Array Expander
  11.   Write a function that accepts an int array and the array’s size as arguments. The
  12.   function should create a new array that is twice the size of the argument array. The
  13.   function should copy the contents of the argument array to the new array, and initialize the unused elements of the
  14.   second array with 0. The function should return a pointer to the new array.
  15.  
  16.  */
  17. // Created by Lord Vader on 3/28/15.
  18. // Copyright (c) 2015 Lord Vader. All rights reserved.
  19. //
  20.  
  21.  
  22. #include <iostream>
  23.  
  24. using namespace std;
  25.  
  26. void arrayReverse(int[], int); // Function Prototype
  27. int *arryExpand(int *, int);
  28.  
  29. int main()
  30. {
  31. // Declare the size of the array and initialize it.
  32. const int SIZE = 7;
  33. int numbers [SIZE] = {2, 6, 9, 16, 23, 30, 39};
  34.  
  35.  
  36. arrayReverse(numbers, SIZE);
  37. arryExpand(numbers, SIZE);
  38.  
  39. return 0;
  40. }
  41.  
  42. void arrayReverse(int values[], int size)
  43. {
  44. int *nums = values;
  45.  
  46. cout << "The elements of the original array are: \n";
  47.  
  48. cout << *nums << " ";
  49.  
  50. while (nums < &values[size - 1])
  51. {
  52. nums++;
  53. cout << *nums << " ";
  54. }
  55.  
  56. cout << "\n\nThe elements of the reversed array are: \n";
  57. cout << *nums << " ";
  58.  
  59. while (nums > values)
  60. {
  61. nums--;
  62. cout << *nums << " ";
  63. }
  64. }
  65.  
  66. int arryExpand(int arry, int size)
  67. {
  68. int *expand = new int[size * 2];
  69.  
  70. for (int i=0; i < size; i++)
  71. {
  72. expand[i] = arry[i];
  73. }
  74.  
  75. for (int i = size; i < size * 2; i++)
  76. {
  77. expand[i] = 0;
  78. }
  79.  
  80. return *expand;
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty