Hello guys,
I was wondering if you could help me out with a class function definition I need to make. Maybe its just getting late but I can't come up with the right definition for the function that returns the location in an integer array of maximum size 20 or 0 if there is no such value. Here's my code.
Code:#ifndef LIST_H #define LIST_H #include <iostream.h> const int SIZE = 20; class List{ public: List(); void Show(); bool Insert(int value); bool Insert(int value, int pos); bool Delete(int pos); int Size(); int Sum(); float Average(); int Odds(); int HowMany(char value); int Between(int low,int high); int WhereIs(int value); void Clear(); ~List(); private: int list_array[SIZE];// the container -- an array of 20 integers int element;// a pointer that keeps track of the position in array }; #endifThanks in advance!Code:int List::WhereIs(int value) // returns the position of the first occurence of a given value(or returns 0, if not found) { int num; int pos_counter = 0; int i = 0; while (num != value){ num = list_array[i]; pos_counter++; i++; } return pos_counter; }



LinkBack URL
About LinkBacks


