-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.cpp
More file actions
80 lines (78 loc) · 1.59 KB
/
dictionary.cpp
File metadata and controls
80 lines (78 loc) · 1.59 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
int letterpos=0,var=0,query,i,ans;
string line,word,meaning;
ifstream myfile,myfile1;
ofstream outfile,outfile1;
while(1){
cout<<"1.New Entry\n2.Search\n3.Quit\nEnter your choice: ";
cin>>query;
if(query==1){
cout<<"Enter the new word you want to add to the dictionary: ";
cin>>word;
cout<<"Enter the meaning of the word: ";
cin.ignore(); //used before getline is called.if not used the string, "meaning" contains only a endline charecter.
getline (std::cin,meaning);
myfile.open("Vocabulary.txt");
outfile.open("Copy.txt");
while(getline(myfile,line)){
if(line[letterpos]-'0' < word[letterpos]-'0'){
outfile<<line<<"\n";
}
else if(line[letterpos]-'0'==word[letterpos]-'0'){
outfile<<line<<"\n";
if(var==0){
outfile<<word<<"-"<<meaning<<"\n";
var=1;
}
}
else{
if(var==0){
outfile<<word<<"-"<<meaning<<"\n";
var=1;
}
outfile<<line<<"\n";
}
}
if(var==0){
outfile<<word<<"-"<<meaning<<"\n";
var=1;
}
myfile.close();
outfile.close();
remove("Vocabulary.txt");
rename("Copy.txt","Vocabulary.txt");
}
else if(query==2){
cout<<"Enter the word you want to search: ";
cin>>word;
myfile.open("Vocabulary.txt");
ans=0;
while(getline(myfile,line)){
i=0;
string check;
while(line[i]!='-'){
i=i+1;
}
check.append(line,0,i);
if(!check.compare(word)){
ans=1;
cout<<line<<endl;
break;
}
}
myfile.close();
if(ans==0){
cout<<"Sorry! this word isn't present in the dictionary."<<endl;
}
}
else{
break;
}
}
return 0;
}