Min program for array

Hello, If someone could explain to me what is going on with this code, I would appreciate it. Yes it is an assignment for class, and the parameters are to add a function "min" to the class "unorderedArrayListType" with a defintion and write a test program for min. I have tried this for awhile and need to not look at it for awhile, but any insight would be appreciated.

Here is the code:
#include <iostream>
#include "unorderedArrayListType.h"
using namespace std;
class unorderedArrayListType
{

virtual void min(int);//creating function min in class
void print();

};
int unorderedArrayListType ::min(int first, int last) //min function with definition
{
int minIndex;
minIndex = first;
for (int loc = first+1; loc <= last; loc++)
if (list[loc] < list[minIndex])
minIndex = loc;
return minIndex;
}

int main()
{
unorderedArrayListType<int> intList(25);

int number;

cout << "Enter 8 integers: ";

for (int count = 0; count < 8; count++)
{
cin >> number;
intList.insertEnd(number);
}

cout << endl;
cout << "intList: ";
intList.print();
cout << endl;

cout << "The smallest number in intList: "
<< intList.min() << endl;
system("pause");
return 0;
}
//Driver program to test min function
void main()
{
//create list first
unorderedArrayListType <int> intList(25);
int number;
cout << intList.listSize();

// insert 5 elements
cout << "Enter 5 numbers:";
for (int count = 0; count < 8; count++)
{
cin >> number;
intList.insertEnd(number);
}
cout << endl;

//display list
cout << "intList:";
intList.print();

// display min element
cout << "minimum element:" << intList.min(8) << endl;

// pause system to view results
system("pause");


}
Last edited on
So... I assume you were given (or made yourself) the class unorderedArrayListType.h, right?
And you #include it at the top, because you want to use it, of course. Nothing to worry about there.
But still, you're probably getting some errors! ;)

You have this .cpp file, which has the main function.
You probably also have unorderedArrayListType.h and unorderedArrayListType.cpp.
Most often the .h file has the definition of the class, and the .cpp file the definitions of its functions. Class definition looks like this:
1
2
3
class MyClass
{
};

And what's important is that a class (and anything else, too) can be defined only once... This is often done in the .h file...


Another important thing to remember is that your program starts in the main() function. This is a special function.
And just like how it is with classes, functions also can de defined only once in the same class. You can have multiple functions with the same name, but they must have different parameter lists, so that they are really all different.
Anyway, since main() is special, it has to be defined in a specific way. And naturally, it may only be defined once...

There is some more that needs fixing, but this is a start for now. Do things step by step. Fix problems one by one.
Topic archived. No new replies allowed.