fork download
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. using std::cout;
  6. using std::endl;
  7.  
  8.  
  9. const int size = 100;
  10.  
  11. void phillip(int[], int & );
  12. /* Preconditions: Array of base type in declared and int varuable declared
  13.   postconditions: the array is filled with values supllied by the user at
  14.   the keybord. the user is assked how many values they want - this value is
  15.   given to the second argument.
  16. */
  17.  
  18. int remdubs(int[], int& noel);
  19. /* Preconditions: An array of basetype int that has noel values.
  20.   postconditions: The number of unique elemts in the array is returned. The function removes all dubplicates inside the array.
  21. */
  22.  
  23. void report(int s[], int d);
  24.  
  25.  
  26. int main(int argc, char* argv[])
  27. {
  28. int ruby[size];
  29. int numele = 0, numuniq = 0;
  30.  
  31. phillip(ruby, numele);
  32.  
  33. numuniq = remdubs(ruby, numele);
  34.  
  35. report(ruby, numuniq);
  36.  
  37. return 0;
  38. }
  39.  
  40. void phillip(int myRuby[], int& s)
  41. {
  42. cout << "\nHow many values you want? ";
  43. cin >> s;
  44.  
  45. cout << "\nPlease input " << s << " integers, hitting return after each one \n";
  46. for (int i = 0; i < s; i++)
  47. {
  48. int num;
  49. cin >> num;
  50. }
  51. }
  52.  
  53. int remdubs(int sapphire[], int& noel)
  54. {
  55. for (int i = 0; i < noel; i++)
  56. {
  57. for (int j = i + 1; j < noel; j++)
  58. {
  59. if (sapphire[i] == sapphire[j])
  60. {
  61. for (int k = j; k < noel; k++)
  62. sapphire[k] = sapphire[k + 1];
  63.  
  64. noel--;
  65.  
  66. j--;
  67. }
  68. }
  69. }
  70. return noel;
  71. }
  72.  
  73. void report(int s[], int d)
  74. {
  75. for (int i = 0; i < d; i++)
  76. {
  77. std::cout << "s[" << i << "]=" << s[i] << std::endl;
  78. }
  79. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
How many values you want? 
Please input 0 integers, hitting return after each one