jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are your ideas?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Remember, if backwards starts empty, all you need to do is add the character from word with +

That was going to be my big finish :) If you want to do it by index of backwards set backwards to word initially so you have the right number of spaces in the array.

WaltP commented: Sorry for blowing you big surprise :P +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Annotations in your code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    
    string word;
    int numchars=0;
    
    cout << "Enter word : " ;
    getline(cin,word);
    
    numchars = int(word.length());
    string backwards[numchars]; //makes an array of strings, not  
                                               //what you want
    
    for(int i=0;i<numchars;i++)
    {
       backwards[i] = word.at(i); //again, plot this one out on paper
//go through the loop by hand, you're copying one character to each of the arrays in the same order
    }
    
    for(int j=numchars-1; j<=0; j--) //see above
    {  //if your requirements were as such you could just use a loop to [I]display[/I] it backwards but I don't think that's what you want
       cout<<backwards[j];
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check the starting index on line 17, what's the last index of an array of length numchars?

You're on the right track with the loop but run through it by hand, you're always replacing the last entry of backwards with the next. See what you can come up with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

put the "cout << endl; " at the end of the first for loop. So do this :

for(i=1;i<5;i++)
    {
         for( j=1;j<6; j++)
         {
              infile>>random[i][j];
              cout<<random[i][j]<<endl;
         }
              cout<<endl;
    }

Maybe you caught it already but line 6 of the snippet should probably be cout<<random[i][j]<<" "; (no endl) that way you get the spacing and there's not the extra carriage return. Hopefully I have not misunderstood your requirement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. It wasn't evident outright. I had to step through it a few times dumping the dictionary as I went along.

diff eq at the same time

Fun is...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You didn't change your base case to reflect your new changes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hey back. If you trace your code you can see it: result=data[digits-1-position]*pow((double)2,(double)position); would do the trick (since you do want the low indexes to be multiplied by the higher values of 2^n and vice versa).

int binary(int data[], int position,int digits)
{
......
......
......       +binary(data,position-1,digits);  
}

digits gets passed all the way through and doesn't change with the recursion. You always have it around. There might be a better way but that was my thought.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It did remove station 3. Print out the key value pairs in the dictionary before and after. What happened is you delete the id but you never change the station.Next value for Park Place so that when you are stepping through your list you set station = station.Next and print it even though it doesn't exist anymore.
They are not in the right order because the dictionary holds them in the order it added them. Go through in order by index and see if the index exists and if so print it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's an extra semicolon at the end of line 52, but that's not the main problem.

This line (and all similar ones) is incorrect:

conjugated=verb[size]-verb[size-1];

Firstly, verb goes off the end of the array (elements go from position 0 to size-1). Secondly, I don't think the - operator can be used like the reverse of the + operator with strings. It compiled because you were taking the numerical difference of 2 characters (one, a "junk" value from an adjacent memory address and the other being the last character) which is really just a calculation with 1 byte integers.

Anything that references verb has to be changed (and remember an element of the string is just a single character so you need the whole string).

So you'll need to restructure those sections. Perhaps consider copying the result into a new array or something similar. It's nice to try to do it in place but it's making your life difficult.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you have an 8 digit binary number, you want to have it so you're multiplying the value in position n with 2^(7-n). You could send in the size of the number in digits as a third parameter to your function that wouldn't change.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
MPI_Send ((void *)&line, 1, MPI_CHAR, 1, 0xACE5, MPI_COMM_WORLD);

I think (can't test it unfortunately) should be:

MPI_Send (line, strlen(line)+1, MPI_CHAR, 1, 0xACE5, MPI_COMM_WORLD);

since line is a char array it is already a pointer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In reality you can make your loop something like while(Input >> num[j]) and increment j within the while loop. If you know you have a constraint of 100 items and no more you can incorporate that into the while as while(j<100 && Input>>num[j]) just make sure j is initialized.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, getche() and getch() work the same way. Hit a key and the program continues. You won't get a chance to hit the ENTER.

Sorry, when I wrote "enter" on line 3, I meant the stray newline in the stream from line 1. I may still missing something obvious, it's not intentional I promise.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it will not show the entire thread

I don't understand what you mean by this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you read the first line of your file using the getline method? That's what you need to do. Don't over think it, just reread my previous post.

http://www.cplusplus.com/reference/string/getline/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It would be lines 20 and 21 there giving me trouble now.

It's line 18. Look at what you are comparing.

(stationDictionary[startID] = resolves to string) != (currentStation = int)

lines 63 and 64 of the code before are giving me a null reference exception

Check over lines 61 and 62 again. Make sure there are no marked errors or warnings in your program before you try it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

that, and maybe "jonsca corrupted my stack" in mirror image letters on my forehead.... - jephthah

Good one. Not really the metaphor I would have gone with. :-/ lol

(that was too good to pass up, nothing personal I promise )

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it out for yourself first. Adding is probably the simplest you just have to manage the carries.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Assign it to a std::string or char array. Within your class you can design your own methods for doing operations with the numbers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't go over your code in great detail. I was able to run it with the following output:

There is no element at the given ID.
The ID of the station being added already exists.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2
There is no element at the given ID.
Name: Boardwalk, ID number: 1
Name: Boardwalk, ID number: 6
Name: New York Ave., ID number: 3
Name: Marvin Gardens, ID number: 2

I think (unless I am confused by the usage) you are using a roundabout and incorrect method of accessing the dictionary. I know you had another thread about this but it doesn't look like you were able to change it. I'll give you a couple of lines and you can fix the rest in turn.
Since your id is an integer you can use the [] notation to access elements at a particular integer key:
(from lines 61 and 62 of the second file)

insert.Next = stationDictionary[id].Next;
//since stationDictionary[key] give you Value for that key
insert.Previous = stationDictionary[id];

Also, when you are using the automatic properties you don't need to have an explicitly defined private variable to hold the data-- so you don't need lines 13 and 14 of the first file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here was my interpretation (I reserve the right to be wrong, so I'm just seeking for my own clarification here, so I'll beg the OPs pardon)

ans=getche(); //user inputs 'g' <enter> (only room for g in the 'ans')
if(ans!='n'||ans!='y')   //this is true
        ans=getch(); //I was saying enter gets picked up by this
                //apparently that's not the case?

On a peripheral matter, I thought this was funny (from the conio.h of a recent mingw):

/*
 * conio.h
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is a part of the mingw-runtime package.
 * No warranty is given; refer to the file DISCLAIMER within the package.
 *
 * Low level console I/O functions. Pretty please try to use the ANSI
 * standard ones if you are writing new code.
 *
 */

(my color emphasis added)
You can't make this stuff up...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.ignore() after the ans = getche(); line. The newline ('\n') from the when you entered y or n the first time was staying in the input stream and getting picked up by the getch() which took it as input and moved on. I don't know offhand if the cin.ignore() plays nice with the conio functions.

That being said, I would avoid the conio.h functions unless it's absolutely necessary to do so. Use cin.get() or getchar() (getchar requires <cstdio>) for portability.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried? Hint: read a line into a string, output the string (not the only way of course).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take it into a string and parse everything (either with your own function that multiplies out the place values or something like atoi) up to the slash as one integer and parse everything after as a second integer.

Or a simple way to do it would be have the user input the numerator, print out a slash and have them put in the denominator.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I wouldn't make lastLetter and nextToLast neither pointers nor arrays (there's not much point to having a 1 element array anyway). I would make them both chars and set lastLetter to verb[size-1] and the other to verb[size-2] (using the array notation for the string).

Another problem you are going to run into is you are not calling isVowel properly since you aren't passing it any parameters. You need to send in the nextToLast character.

Just a nitpicky thing but you don't have to use the whole if(statement) return true; bit, just return statement; if it's true it will return true and vice versa.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You still have the for loop within the while loop which I think someone had pointed out already. What happens when your file has 9 values in it? You don't need it anyway, just increment j within that while loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thankfully this issue hasn't lead to bonuses (or lack thereof) in my region. The scores of the standardized tests (similar to what Vernon was talking about) do count for the schools stature in the state and district so it can affect things like funding.
The problem is that the "benchmarkers" think it is fair to include kids that have special needs and kids for whom English isn't a first language. Nothing at all against those groups but if you were designing a "fair" way of counting the test scores you'd want to weigh them separately.
So if you were a teacher in a school with mainstreamed special education students in an area with a large bilingual population you would be penalized instead of rewarded for what progress you did make. Doesn't make sense to me, IMHO of course.

(which doesn't at all say that teachers should have the right to be mediocre and get away with it...)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Really you'd remember "to" and then "en" and then "em" and then in a shocking twist you'd remember "M."

That and for you, you'd have #include <stdio.h> tattooed on your arm and not remember why.

I don't know why, but every time i see this thread title Memento comes to mind. maybe it's because i just cant remember any other titles.

Ha ha. get it? I cant remember them!! LOL. you know, remember any ...

oh, never mind.

jephthah commented: that, and maybe "jonsca corrupted my stack" in mirror image letters on my forehead.... +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Disp and input should just take plain ol' strings. I'm not sure what you are trying to do with the [ ] but I don't believe it's correct. In the case on the last 2 lines you'll have to use something like sprintf to make a string out of the numerical values and the text and then display that string. I don't have a copy of Matlab to test it on but that's my recollection for the disp and input part.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yep. Reported and noted as possibly a new record for bumping (I think there was one from 2003 a couple months back). It must take a lot of effort to find that post and post on it rather than starting a new one. I'll never understand the motivation....

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're skipping over the design phase completely you're doing yourself a disservice. All of the work with the use cases, CRC cards, etc. should be done before you write a single line of code, that way you can include the OO principles from the ground up.

Salem commented: Absolutely! +20
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's an example that gives you something tangible when you click the button. Set the "Tag" property of each of the textboxes to "Text" (or some other moniker).

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	for(int i = 0;i<Controls->Count;i++)
		if(Controls[i]->Tag=="Text")	 
		{
	  	  dynamic_cast<TextBox^>(Controls[i])->Multiline = true;
		   dynamic_cast<TextBox^>(Controls[i])->Height = 5;
		}
}
tonymuilenburg commented: Wow, your post really saved me time and frustration! :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

SelectionStart is a property specific to TextBox. Text is a property that all Controls have. To access that property you need to downcast the controls to their particular type using a dynamic_cast to TextBox^ type. You'll have to do some checking to make sure that you have the right controls on your form, perhaps by tagging your textboxes and using that as a criterion to cast them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Got it to work by changing the include in main.cpp from "LList.h" to "LList.cpp" and only doing "g++ Main.cpp -o Main".

In this situation you should have left it as #include "LList.h" and compiled it as g++ LList.cpp Main.cpp -o Main that way LList.cpp gets compiled first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just create an intermediate string variable:

String ^ temp = String::Format("{0:F4}",pi);
after this, temp = "3.1416" you can do whatever you want with it
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you allowed to use std::vector or are you limited to arrays? A vector would let you expand your set as needed. See http://www.cprogramming.com/tutorial/stl/vector.html for a quick introduction.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

As long as caption takes a string^ the above should work. It must be some other kind of control since a label does not have a caption member. Is it some kind of datagrid?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm still confused. Is this for a WinForms application? I'm not sure what label you are talking about that has a caption (and I'm only guessing about what you mean by standard bar).

This will work for a generic label:

double pi = 3.141592654;
label1->Text = String::Format("{0:F4}",pi);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's still probably your static variables. They need to be initialized in your .cpp file and not just declared in the .h. Otherwise repost your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The way you have it will only store 255 characters, not 255 strings. Make your array 2D. For example, char arr[255][10]; would allow you to store 255 strings of 9 characters each (plus a '\0'). You could enter strings into them by using fgets(arr[i],sizeof(arr[i]),stdin); where I goes from 0 to 254. Just remember if there is room the fgets will put the newline character into the array from when you pressed enter. You could use scanf also but make sure you limit your input with the specifier to the number of characters you designate.

EDIT: He's got it ^^^^^^^^^^^^^^

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

>> What time is it?

Hammertime!

You can't tell me he's not still the hero of millions of Dutch school children, Niek.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is this c++? I don't think ref class CSquare: Rectangle or property int lt are valid c++ statements.

Dave

It's C++/CLI. If one needs .NET winforms in a C++ application it's basically the only avenue.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are many ways you can make your life easier on this one. I'll focus mostly on 62-77. You should make your array only 26 members long. That way there is not a lot of wasted array space to confuse the matter.
There's an easy mapping between chars and an appropriate array index, so if you have 'a' and you want to get to 0th index what would you subtract?
Next for line 65 you want to subtract that same quantity from "sentance[j]" to get an appropriate index. Account for all your arrays being 26 elements long in the loops.

Once you get to 76 transform the position in the alphabet you get back to a letter and return it. In following these steps I got the correct answer of 'l' for the phrases.

Now you can either make all the same changes to the other function or when calling the string version, use the c_str() method to get the null-terminated version of the string and call the char * version with that data.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

in that case when would i need the ClassName::Function syntax

In the implementation file when you write the method definitions like you have it in Password.cpp.

also when i take out the Password:: the compiler throws an error when trying to access class variables.

I get at least a warning for having them in there in Password.h You don't need them there.

A couple of problems: Some of the paths of passwordCapLetter and passwordNumber do not return anything. Even if there's an error your function should still return something (say -999) which you can check for in the calling function.

Also, you have static variables declared in the Password.h file but never defined anywhere. You should define them in Password.cpp as string Password::password=""; etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Characters are essentially nothing more than 1-byte integers. So if your letter that you were counting were 'a' what operation could you do to yield the index 0? How about for 'b' to yield 1? You'll kick yourself once you get it.

So the array will hold integers and be indexed by the above method. March along your string, once you encounter a letter, do the transformation to get the proper index and increment that particular bin. So if you encounter c you'll increment bin 2 (zero based). Then onto the next letter. Do a quick sketch on a piece of paper with a 4 or 5 letter word. Draw where each of the letters ends up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Lines 17 and 18 of password.h do not need the Password:: qualifier. Since they are being declared within the class it is assumed just like it is for the constructor/destructor.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do those functions take any arguments? No. So don't add in arguments where they are not necessary.

You're calling a function, you must use the (). So InterestDue should be InterestDue() just as if you had invoked it anywhere else.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Lines 15-31 in your code above would be what I would call pseudocode. If you're having issues with your code not compiling it's best not to add in more lines that it's going to reject, is all.

Regarding the snippet you just posted. InterestDue, TotalAmountDue, and Payment are all functions. You know how to call a function, you've called one on line 73 (and many others) in the code you posted before. If these functions are to return the values they promised and then send them along into the output stream they need to be invoked properly. Hint: just add ().