I need some serious help. I am trying to make this dictionary program and i cannot figure out how to take the input list which consists of a command then the word then the definition and then insert it into an array of structs and make the array alphabetized.
Here is my code. Please help!
/* PROGRAM Dictionary
AUTHOR: Joseph Westlake
UNIQNAME: jwestlak
GSI NAME: Clay Wood
EECS/CMPTRSC 183 - Winter 2002
Project Number: 6
Due Date: Monday 4/15/02
SUMMARY
This program will function like an interactive library. The data values will be
inputted from a text file that is specified by the user.
INPUT
- a file with the filename that is specified by the user
- the file will contain
- one of four commands
- ADD (add a word to the dictionary)
-the word and its definition
- LOOKUP (look up a word in the dictionary)
-the word that is to be looked up
- DUMP (print a table of the current dictionary contents)
- EXIT (exit the program)
BAD DATA CHECKING
The program should make sure that the data file has opened successfully, if not the
program must terminate and display a descriptive error message. It also needs to make
sure that the input commands are valid.
OUTPUT
The program will tell the user what the input is and what the program is doing for
each command. All valid input will be printed.
*/
//included header files
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
const int INSTRUCTIONS = 50,
MAX_LENGTH = 25;
struct Definition
{
string Word;
string Meaning;
};
typedef Definition Instruction [INSTRUCTIONS];
//user defined functions
int main()
{
Instruction Data;
int line;
string Comm,
fileName,
Command[INSTRUCTIONS],
Word,
Meaning;
cout << "============================================= " << endl;
cout << " Dictionary " << endl;
cout << "============================================= " << endl << endl;
cout << "Please input the file name of the dictionary ";
cin >> fileName;
ifstream inFile;
inFile.open (fileName.c_str());
do
{
for (line = 0; line < INSTRUCTIONS; line++)
{
getline (inFile, Command[line]);
Comm = Command[line].substr (0,6);
if (Comm == "ADD ")
{
Word = Command[line].substr (7,15);
Meaning = Command[line].substr (23,80);
cout << "I will add the word " << Word << endl;
cout << "It means: " << Meaning << endl;
SORT (Data, Word);
}
else if (Comm == "LOOKUP")
{
cout << "Lookup" << endl;
}
else if (Comm == "DUMP")
{
cout << "Dump" << endl;
}
else if (Comm == "EXIT")
{
cout << "Exit" << endl;
inFile.clear();
inFile.close();
}
else
cout << "The instruction " << Comm << " is invalid" << endl;
}
inFile.clear();
inFile.close();
}
while (inFile);
for (line = 0; line < INSTRUCTIONS; line++)
return 0;
}