Dictionary Program

The program I'm trying to write is simple. The user enters a word and if it is the "dictionary" text file it says so. If not it outputs the two closest words on either side of the entered one. I have the basics I just don't know how to implement the diction.txt file or how to use the compare to get the close words. Thanks for your help in advance!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<string>
using namespace std;


int main()
{
	string wordin;
	string worddict;
	string close1;
	string close2;
	
	cout << "Search the dictionary (or type quit): " << endl;
	cin >> wordin;
	if (wordin == "quit")
	{
		cout << "Bye." << endl;
	}

	else 
	{		
		wordsearch(wordin, worddict, close1, close2);
	}
		
}


void wordsearch (string wordin, string worddict, string close1, string close2)
{
	
	
	if (wordin.compare(worddict) == 0)
                                 
		cout << wordin << " is in the dictionary." << endl;
	
	else  

	{
		if (wordin.compare(close1) < 0 && wordin.compare(close2) > 0)
        cout << "The two words closest to the one you entered are" << close1 << " and " << close2 << endl;


	}
}
Last edited on
We haven't learned lower bound so I don't think i need to use that. Also, how do I implement diction.txt?
What has to be in the file? Words.
How do you read them?
How do you store them in memory?
How do you search them from your store?

Personally, I find it extremely revolting that one would be limited to what one already knows (although it might be useful for teaching purposes). If those are the rules, then thinking about the above questions might help.
So I talked to my teacher and she said use this http://imgur.com/XA6LZta to read in the words. I'm supposed to search through the txt file and compare the inputted word to all the words.
so I think I'm getting closer... I have this now. It quits if i say quit but if i enter a word it does nothing. so my wordsearch function is broken. i don't really understand ifstream still though and have no idea how to put the pointer back to the beginning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<string>
#include<fstream>
using namespace std;


int main()
{
	string wordin;
	string worddict;
	string close1;
	string close2;
	string dic;

	void wordsearch(string, string, string, string);
	void moveFilePointerToBeg(string);

	ifstream dictionary("D:\\diction.txt");
	string wordDic;
	moveFilePointerToBeg(wordin);
	dic == wordDic;
	
	cout << "Search the dictionary (or type quit): " << endl;
	cin >> wordin;
	if (wordin == "quit")
	{
		cout << "Bye." << endl;
	}

	else 
	{		
		wordsearch(wordin, worddict, close1, close2);
	}
		
}


void wordsearch (string wordin, string worddict, string close1, string close2)
{
	
	
	if (wordin.compare(worddict) == 0)
                                 
		cout << wordin << " is in the dictionary." << endl;
	
	else  

	{
		if (wordin.compare(close1) < 0 && wordin.compare(close2) > 0)
        cout << "The two words closest to the one you entered are" << close1 << " and " << close2 << endl;


	}
}

void moveFilePointerToBeg (string wordin)
{
	
	cout << wordin;
}
Topic archived. No new replies allowed.