Hello, I am relativly new to programing, and I need some help on a lab project. If anyone out there can explain why I am getting the following errors.
55: inlab was not declared in this scope
In funtion void selectionSort(char (*)[25], int)
74:error: Stropy was not declared in the scope
77:error: Stromp was not declared in the scope
77: expected ';' before ) token
The Lab Assignment was to write a program so that the user reads 6 words or names into an array from a file. The unsorted array is then printed out on the screen.
Then using the Selection Sort for these words/names, they are sorted and the sorted array is printed out on the screen.
Below is the code I have written, How can I fix these errors. Any kind of help with this would mean a world of diffence. Thanx in advance.
// programmer: David Pfaff
// date: April 25, 2008
// username: dpfaff
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <iostream>
using namespace std;
const int MAXCHARS = 25;
const int MAXSIZE = 6;
typedef char String [MAXCHARS];
String array[MAXSIZE];
// opens an input file called in.dat
// outputs: if no failure, infile is open
// else prints message and program stops
// usage: openInputFile (infile);
void openInputFile (ifstream& infile);
// sorts a list of words
// inputs: array[0..size-1]
// outputs: array
// usage: selectionSort (nums, MAXSIZE);
void selectionSort (String array[], int size);
// enters a list of words
// inputs: a list of words
// outputs: a list of words in array
// usage:
void enter (ifstream& infile, String array[], int size);
// prints a list of words
// inputs: a list of words in array
// outputs: a list of words separated by commas
// usage:
void print (String array[], int size);
// prints a number of new lines
// inputs: num, the number of new lines
// outputs: num new lines
// usage: printNewLines(3);
void printNewLines (int num);
int main()
{
ifstream infile;
openInputFile (infile);
openInputFile(inlab.dat);
String array [MAXSIZE];
enter (inlab.dat, array, MAXSIZE);
print (array, MAXSIZE);
printNewLines(3);
selectionSort (array, MAXSIZE);
print (array, MAXSIZE);
inlab.dat.close();
return 0;
}
void selectionSort (String array[], int size)
{
int start, minIndex, minValue;
for (start = 0; start < size - 1; start++)
{
minIndex = start;
Strcpy(minValue, array[start]);
for (int index = start + 1; index < size; index++)
{
if (Strcmp(array[index], minValue) < 0))
{
Strcpy(minValue, array[index]);
minIndex = index;
}
}
Strcpy(array[minIndex], array[start]);
Strcpy(array[start], minValue);
}
}
// opens an input file called in.dat
// outputs: if no failure, infile is open
// else prints message and program stops
// usage: openInputFile (infile);
void openInputFile (ifstream& infile)
{
infile.open("inlab.dat");
if (infile.fail())
{
cout << "Error opening input file" << endl;
exit(1);
}
}
// enters a list of words
// inputs: a list of words
// outputs: a list of words in array
// usage:
void enter (ifstream& infile, String array[], int size)
{
for (int i = 0; i < size; i++)
{
infile >> array[i];
}
}
void print (ifstream& infile, String array[], int size)
{
printNewLines(2);
for (int i = 0; i < size; i++)
cout << array[i] << ", ";
printNewLines(2);
}
// prints a number of new lines
// inputs: num, the number of new lines
// outputs: num new lines
// usage: printNewLines(3);
void printNewLines (int num)
{
for (int k = 0; k < num; k++)
cout << endl;
}