here is my code:
quick note, can't edit the function prototypes (this is for a lab, prototypes must be those ones))
Code:
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
void header(int lab,int question,string date);
void printArrayA( int * , int size, int high, int low);
void printArrayB( int *, int size);
void printArrayC( int *, int size);
void printArrayD( int &, int size);
void printArrayE( int * , int size);
char menu();
int main()
{
int max(0), min(0),n;
int* myArray=NULL;
header(6,1,"March 10");
char selection;
cout<<"Please enter the size of the Array: ";
cin>>n;
myArray=new int [n];
do
{
selection=menu();
switch(selection)
{
case 'a':
case 'A':
{
cout<<"Enter a minimum value for the array : ";cin>>min;
cout<<"Enter a maximum value for the array : ";cin>>max;
while (min>=max)
{
cout<<"Invalid number : ";cin>>max;
}
printArrayA(myArray,n,max,min);
break;
}
case 'b':
case 'B':
{
printArrayB(myArray,n);
break;
}
case 'c':
case 'C':
{
printArrayC(myArray,n);
break;
}
case 'd':
case 'D':
{
printArrayD(*myArray,n);
break;
}
case 'e':
case 'E':
{
printArrayE(myArray,n);
break;
}
default :
{
cout<<"Invalid Entry"<<endl;
break;
}
}
}
while(!(selection=='f'||selection=='F'));
}
void header(int x, int y, string z)
{
cout<<" ++ Dave Tripp ++\n";
cout<<" ++ Lab "<<x<<" ++\n";
cout<<" ++ Question "<<y<<" ++\n";
cout<<" ++ "<<z<<" ++"<<endl;
}
char menu()
{
cout<<" MENU \n";
cout<< "A. Populate the Array with Random Numbers. \n";
cout<< "B. Sort the Array from least to greatest. \n";
cout<< "C. Sort the Array from greatest to lest. \n";
cout<< "D. Reverse the Array. \n";
cout<< "E. Print the Array. \n";
cout<< "F. Exit. \n";
char letter; cin>>letter;
return letter;
}
void printArrayE( int inputarray[], int n)
{
for (int i = 0; i<n; i++)
{
cout<<inputarray[i]<<" ";
}
cout<<endl;
cout<<endl;
}
void printArrayA( int inputarray[], int n, int max,int min)
{
int i;
srand((unsigned int)time(NULL));
for(i = 0; i <n; i++)
{
inputarray[i]=min+rand()%(max-1);
}
cout<<endl;
cout<<endl;
}
void printArrayB( int inputarray[],int n)
{
int i,j;
int temporary;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(inputarray[i]<inputarray[j])
{
temporary=inputarray[i];
inputarray[i]=inputarray[j];
inputarray[j]=temporary;
}
}
}
}
void printArrayC( int inputarray[],int n)
{
int i,j;
int temporary;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(inputarray[i]>inputarray[j])
{
temporary=inputarray[i];
inputarray[i]=inputarray[j];
inputarray[j]=temporary;
}
}
}
}
void printArrayD( int *inputarray[],int n)
{
int* k;
*inputarray=k;
int i;
for (i = 0; i < n/2; i++)
{
swap ( k[i], k[n-1-i]);
}
}
i know the problem is in the printArrayD function somewhere, i think i need to switch soemthing around with the *inputarray=k line, i've tried for a while but can't figure it out.
this is the error message i get:
1>------ Rebuild All started: Project: Lab 03, Configuration: Debug Win32 ------
1>Build started 3/24/2011 12:44:54 AM.
1>_PrepareForClean:
1> Deleting file "Debug\Lab 03.lastbuildstate".
1>InitializeBuildStatus:
1> Touching "Debug\Lab 03.unsuccessfulbuild".
1>ClCompile:
1> dtripp3_Lab08_q3.cpp
1>c:\users\dave tripp\documents\visual studio 2008\projects\es1036\lab 03\dtripp3_lab08_q3.cpp(154): warning C4700: uninitialized local variable 'k' used
1>dtripp3_Lab08_q3.obj : error LNK2019: unresolved external symbol "void __cdecl printArrayD(int &,int)" (?printArrayD@@YAXAAHH@Z) referenced in function _main
1>C:\Users\Dave Tripp\Documents\Visual Studio 2008\Projects\ES1036\Debug\Lab 03.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.29
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped =========
Someone help me please and thanks!