Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,070 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,603 people online right now. Registration is fast and FREE... Join Now!




Array and Functions

 
Reply to this topicStart new topic

Array and Functions, initializing array's and making them work

Entropicvamp
13 Apr, 2008 - 05:03 PM
Post #1

New D.I.C Head
*

Joined: 31 Mar, 2008
Posts: 14


My Contributions
This is what I have so far, could someone please let me know if I am doing this right. Also this is what else I have to figure out-
The class should include the following methods:

Sum – I am pretty sure I have this part done right.
CountNmbrsBigger – provide a count of the number of data elements in the array that are larger than a given integer.
Average – provides an average of the data in an array.
High – I am pretty sure I have this part done right.
Low –I am pretty sure I have this part done right.
Find(number) – Returns the first index of the location of the number in the array.

CODE
int main() {

  int arrayOfInts1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int arrayOfInts2[10];
  int arrayOfInts3[] = {1,2,3,4,5,
                        6,7,8,9,10}; /* an unsized array */
  int arrayOfInts4[10];
  int i;

  arrayOfInts2[0] = 1;
  arrayOfInts2[1] = 2;
  arrayOfInts2[2] = 3;
  arrayOfInts2[3] = 4;
  arrayOfInts2[4] = 5;
  arrayOfInts2[5] = 6;
  arrayOfInts2[6] = 7;
  arrayOfInts2[7] = 8;
  arrayOfInts2[8] = 9;
  arrayOfInts2[9] = 10;

  for(i=0; i<10; i++) {
    arrayOfInts4[i] = i + 1;
  }

  return 0;
}
class ArrayClass {
      private:

      public:
              int *theArray;
              int theArraySize;

             ArrayClass(int [], int);
             int sum(void);
             int countNmbrsBigger(int);
             int average(void);
             int high(void);
             int low(void);
             int find(int);
};

ArrayClass::ArrayClass(int anArray[], int ArraySize){
      //constructor
      theArray = anArray;
      theArraySize = ArraySize;
}  

int ArrayClass::sum(void){
      //sum of all the data in the array
      int sum = 0;

      for (int i = 0; i < theArraySize; i++){
         sum += theArray[i];
            }
      return sum;
}
int ArrayClass::high(void){
      //find the highest value in the array
      int highValue = theArray[0];
      for (int i = 0; i > theArraySize; i++){
            if (theArray[i] > highValue){
                  highValue = theArray[i];
            }
      }
      return highValue;
}
int ArrayClass::low(void){
      //find the lowest value in the array
      int lowValue = theArray[0];
      for (int i = 0; i < theArraySize; i++){
            if (theArray[i] < lowValue){
                  lowValue = theArray[i];
            }
      }
      return lowValue;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:07PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month