errrr...

hello all,

umm..i have this program to make, it is suppose to be a dictionary.
we were given four tasks to include in our menu():

1. Add words to the dictionary.
2.Enter a passage
3.Check and suggest a word.
4.Exit.


1... i made any array that stores words in it.

2... am i suppose to save the passage entered by the user in a 2-D array?

3....i wasn't able to do this part... for eg:if there were two words to suggest struck and strange..then the prog is suposed to suggest the word closest to it..in alphabetical order..here it is 'strange' since the 'str' part is the same...i am aware of the fact that since a passage is entered it needs to be tokenized in order to make it easier but how do i do it?

4...who am i kidding..:P

i am doing all this in VC++..under the class CWords
i don't have the coding with me right now...i did it in my uni and forgot to save it in my usb drive..:(

i will be posting it in time...but in the mean time could someone please guide me with the check and suggest part?

thank-you.

Last edited on
hey hugsnbugs.
Until you post some code i will tell you this: "STL is you friend".
http://www.cplusplus.com/reference/stl/
the string class.
http://www.cplusplus.com/reference/string/

1... hmm why not a vector?
2... i'm not sure... here maybe you want a set or map again i i'm not sure or a 2d vector.
for 3 u can goggle for tokenizing string c++ or check <cstring> strtok function.

Jeff
Last edited on
hey,

thanx alot..(i'll search for the tokenzing thingie)... :)

and umm...this is my first semester at programming so m pretty new to this language...i don't really know wat u meant by 'vector' :S

and yea, i'll deffntly be posting the code by monday.

vectors:
http://www.cplusplus.com/reference/stl/vector/

other stl containers:
http://www.cplusplus.com/reference/stl/

Hm, maybe you should stick to arrays and c string(char *foo) then until you learn more about classes, templates and other OOP(Object-Oriented Programming) stuff.

EDIT
check the std strtok function too:
http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

J.
Last edited on
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include "string.h"
#using <mscorlib.dll>

#include <conio.h>
using namespace System;
#include <atlstr.h>
#include "words.h"
int _tmain()
{
char *passage;

Console::WriteLine("enter the number of words you want to store in dictionary\n");
String *str=Console::ReadLine();
int num=Convert::ToInt32(str);
CWords *dict=new CWords[num];
// CString str1(str);
char wish;
do
{ Console::WriteLine("***~~The main menu~~***\n");
Console::WriteLine("***~~[1]add word to dictionary~~***\n");
Console::WriteLine("***~~[2]enter a passage~~***\n");
Console::WriteLine("***~~[3]check and suggest~~***\n");
Console::WriteLine("***~~[4]exit~~***\n");
String*str2=Console::ReadLine();
int option=Convert::ToInt32(str2);

switch (option)
{
case 1:
{

for(int i=0;i<num;i++)
dict[i].addword();
break;
}
case 2:
{
Console::WriteLine("enter a passage\n");
String*str=Console::ReadLine();
CString str1(str);
char *passage;
passage=new char[str1.GetLength()];
strcpy(passage,str1);
break;
}
case 3:
{
/*for (int i=0;i<(strlen(passage));i++)
for (j=count;j='';j++)
strcmp( this->m_word,passage[j]==0);*/
break;
}
case 4:
{
exit(0);
break;
}
}

}
String *str3=Console::ReadLine();
wish==Convert::ToChar(str3);
while (wish=='y'||wish=='Y');
return 0;
}
#include "StdAfx.h"
#include ".\words.h"
#using <mscorlib.dll>
using namespace System;
#include <atlstr.h>

CWords::CWords(void)
{
}

CWords::~CWords(void)
{
}
void CWords::addword(void)
{
String *str=Console::ReadLine();
CString str1(str);
char*m_word;
m_word=new char[str1.GetLength()];
strcpy(m_word,str1);
}
void CWords::check(void)
{ char *passage;
for (int i=0;i<(strlen(passage));i++)
/*for (int j=count;j='';j++)
{
if strcmp( this->m_word,passage[j]==0)
else
str
count++;*/


}
and i know my 3rd task isnt right....i can't get it right!!!

m soooo confused...help required (and badly)...thank-u :)
"errr"...
Your code is kinda a mess i see MFC, C++/CLI and standard C++ stuff...
Since all you want is do some input/output to the console you can just stick to std c++, not only it will be easier to read and find errors it will be easier for other programmers understand your code.
You said:
"and umm...this is my first semester at programming so m pretty new to this language...i don't really know wat u meant by 'vector' :S"
Yet you try to use MFC, C++/CLI hybrid style in your code... thats probably what is confusing you.
Its not wrong to mix stuff but you must know what you are doing.
In the earlier learning stages the best thing to do is to stick to std C++, i'm sure your teacher agrees with me.
1
2
3
4
5
6
7
8
void CWords::addword(void)
{
String *str=Console::ReadLine();
CString str1(str);
char*m_word;
m_word=new char[str1.GetLength()];
strcpy(m_word,str1);
}


pretty redundant you (try) create 3 string just to copy one to the other.
char * strcpy ( char * destination, const char * source );
thats the declaration of strcpy, 2 c style strings (char *) not String * or CString.


more info:
http://www.cplusplus.com/reference/clibrary/cstring/strcpy.html
http://www.cplusplus.com/reference/clibrary/cstring/

Jeff
Last edited on
ooooo..my bad....that was supposed to be 'my first YEAR at proramming'..
that makes it 2ND semester..
but srsly i don't get wat u mean by "MFC, C++/CLI hybrid style"
i jsut know that we make our programs in VC++ 2003..in an IDE.. and we use console application....oh, and before this we were using win32..:S

plus, my teacher is a super genius on this particular subject but he is not good at conveying his geniaties to us... :P

n thank-you ever so much for helping me out...

thank-you

hugsnbugs
Last edited on
Hey hugsnbugs
I hope you do know what MFC and CLI/C++ is
if you don't:
www.msdn.com

I really wanna help ya but is C++/CLI a requisite?
If yes lets stick to that.

your method can be more flexible
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class CWord
{
public:
// other common operations
     void addWord(CString);
private:
CString m_word; // is this supposed to be an array or any other container?
};


void CWords::addword(CString w)
{
m_word = w
}


now your class is not limited to console application you can use it anywhere and ask for a CString anyway you want like dialogs and other controls
But not just console:
1
2
3
4
5
CWord myWords;
CString foo = "Potato";

myWords.addWord(foo);


Well yeah its just a example theres just too many ways to do this...

Good luck

Jeff
Last edited on
thanx alot.... :)
i'm really getting the hang of this now...slowly. :P
hey!

i tried implementing the additional code that u provided and it went pretty fine... (thank-you for that) but im still not able to do the spell check part...where the program is suppose to suggest me another word..better out of the ones present and the suggestion it makes should be in alphabetical order... for eg:

"strange" and "struck"

the first 3 letters are the same "str" but the letter next to them is an "a" and a "u"...obviously "a" comes before "u"...but how m i EVER going to accomplish this feat....(bin on this case since last friday):S


and the dictionary words r supposed to be stored in an array...(gets wierder)...:S
Topic archived. No new replies allowed.