Just one word!

Pages: 123
Nov 12, 2012 at 11:17pm
It's a minor problem, that can be fixed by ignoring 0 length strings when outputting. I suggest you solve the more pressing problem that is not so easily fixed - sorting.
Nov 12, 2012 at 11:20pm
So you say when in my printing function to ignore 0 length strings? So in my printTen function? The sorting I was thinking about. How did you sort when you did it?
Nov 12, 2012 at 11:23pm
I used std::sort on a std::vector of std::string with a custom comparison function.
Nov 12, 2012 at 11:40pm
I don;t use vectors we haven't learned them. Couldn't I just add a loop somewhere so it compares all of the letters maybe? Like currently I compare the first letters of the words what if I did like a loops to compare all letters.
Isn't that what you did essentially was to compare all letters?
Nov 12, 2012 at 11:51pm
http://www.algolist.net/Algorithms/Sorting/Selection_sort

The "visualizer" underneath the sample code is informative.
Last edited on Nov 12, 2012 at 11:53pm
Nov 13, 2012 at 12:09am
When I tried to rewrite mine like that I got this for output

Do Funny Lets Now One One
Say Six Stop Tell Ten This Touch again an an
backwards count counting each eight eight eleven eleven equals equals
fingers fingers fingers five five four friends hand hand hand
hand have hold it left left nine nine of of
on pausing pointing prove quickly right right say say say
seven six ten that the the the the this this
time to try two up will without you your your


My original sort algorithm was along the same like except that it compared the first letters at somepoint. How would I account for the addition of differences of words between cire's output and my own. Isn't there a way to just fix that snipet of code.?
Nov 13, 2012 at 12:13am
You just need to do a comparison where case doesn't matter.
Nov 13, 2012 at 12:15am
That's what I had in my original code. Thats why it was converted to lower and then compared. Are you just messing with me or something?


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
// Function to sort array of strings
void selectionSort(string list[], int size)
{
	
	int i = 0, j = 0, smallest = 0; 
    string temp = "" ; string str1 = ""; string str2= "";
	
	for(i = 0; i < size -1; i++)
	{
		smallest = i;
		
		
	for(j = i + 1; j < size; j++)
	{  
		if (list[j] != "" && list[smallest] != "")
		{
                         // This code below is where I compare where case doesn't 
                        // matter

			str1 = list[j];
			str2 = list[smallest];
			str1[0] = tolower(str1.at(0));
			str2[0] = tolower(str2.at(0));
		
		
			if( str1 < str2)
			{
				smallest = j;
			}
		}
	}
	    //swap
		temp = list[smallest];
		list[smallest] = list [i];
		list [i] = temp;
	}
}
Last edited on Nov 13, 2012 at 12:19am
Nov 13, 2012 at 12:26am
That's what I had in my original code. Thats why it was converted to lower and then compared. Are you just messing with me or something?


Your original code didn't sort correctly. You need to use a case insensitive comparison and sort correctly. The two can both be done together.
Nov 13, 2012 at 12:27am
1
2
3
4
5
str1 = list[j];
			str2 = list[smallest];
			str1[0] = tolower(str1.at(0));
			str2[0] = tolower(str2.at(0));
		


Is it not a case insensitive?

1
2
3
4
if( str1 < str2)
			{
				smallest = j;
			}
Last edited on Nov 13, 2012 at 12:28am
Nov 13, 2012 at 12:47am
Assuming that the only possible letter in a word that can differ in case is the first one (which seems to be true of the sample input you're given), yes.
Nov 13, 2012 at 12:49am
Dude you are really no help thanks anyways you are just playing some game
Nov 13, 2012 at 3:16am
@jlillie89

Dude you are really no help thanks anyways you are just playing some game


I would advise you not to discredit cire like that. He is very knowledgeable & gives great advice, and is certainly not into playing games IMO. He has over 1500 posts, the vast majority of those dedicated to helping people.

Don't bite the hand that feeds you, better to take a look at yourself and your attitude. If you don't understand, then think about questions you can ask so things can be explained differently.

Teaching others can be tricky because people understand things differently. The same advice could be given to 2 newbies, one will understand & the other won't.

Also be aware that hints or clues are given, so you have to do some thinking yourself.

People who help out others in this forum, expend quite a bit of time, energy & thinking to do so. So be aware of that.

IMO your should apologise to cire , if you are lucky he might continue to help you.
Nov 13, 2012 at 3:43am
TheIdeasMan (1296)

I know people spend a lot of time on this forum helping I'm happy that this website is here. My school doesn't have anyone to help me with programming. So don't think that I'm not aware of this, I am and appreciate it. I spent the past 2 days on this problem. I think he is messing with me. Which is why I say he is no help. He told me sort function OK OK I look at it change the function talk to him about output and he say's oh no you need case insensitive comparison. OK that's what I had in my original code you told me it was wrong. So this is why I think he is messing me with me and I did not want to continue to have him help me.
Nov 13, 2012 at 4:10am
Oh well, I disagree - but good luck (:+\)
Nov 13, 2012 at 8:44am
I think he is messing with me.

He is not.

OK that's what I had in my original code you told me it was wrong

I told you the problem was in your sort function (and... it was.) I didn't say making a case insensitive comparison was wrong (and... it wasn't.) In fact the only thing I said about making a case insensitive comparison was that you needed to.
Nov 13, 2012 at 1:21pm
I had a case insensitive comparison in the original function. Also my sort function appears to not differ except for the case insensitive comparison to the sort function you directed me to. Also if I do a cout in the onlyAlpha. You tell me it's wrong my sort function and you give no evidence. Except tell me to do something that is already there this is why I think you are messing with me. If you say you are not then you are not. But what is the evidence for you thinking that the sort is off.
Nov 13, 2012 at 1:51pm
I think you should change approach to reading words.
Instead of your function

1
2
3
4
5
6
7
8
9
//To fill array of strings
void fillString(ifstream &fin, string inputarray[], const int size)
{
	// Loop to fill input array
	for(int i = 0; size > i; i++)
	{	
		fin >> inputarray[i];
	} 
}



I would use the following

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//To fill array of strings
int fillString( ifstream &fin, string inputarray[], const int size )
{
	int i = 0;
	std::string s;

	// Loop to fill input array
	while ( i < size && fin >> s )
	{	
		onlyAlpha( s );
		if ( !s.empty() ) inputarray[i++] = s;
	} 

	return ( i );
}


In this case your array will contain only words of alpha symbols. The function return value will point out the number of words and can be used further in other functions as the actual size of the array.
Last edited on Nov 13, 2012 at 1:55pm
Nov 13, 2012 at 2:04pm
As for your original question then it is obvious that you do not output *word* (11) which has no alpha symbols. So the question arises do you have to output this word or do not have?
Nov 13, 2012 at 2:08pm
Alright I will give it a try and just use i as the array size I suppose possibly that will clean this mess up. Thanks dude I will let you know how it goes.
Pages: 123