jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, but what are you inheriting from string? Nothing. Use composition (that is, make a std::string a member of your class rather than inheriting anything).

The simplest solution to the problem your code is having now is to transform the entire string to lowercase and test whether that is a palindrome. Make a private "to lower" function for your class (a couple of lines, really), and call it from your constructor. Otherwise, you're creating a problem for yourself because 'h' is very different from 'H'.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If N=9 in your prior example, each pass you'd be writing into bd[9][9], right? Well, the array only goes up to bd[8][8]. When you declare an array, you give it's dimensions, but when you're accessing the elements you have to start numbering at 0.

In your loop, to access the (ith,jth) element, just use bd[j], which will work for input and when you're printing the values out. So within your for loops:

insert >> bd[i][j];
cout<<bd[i][j];  //add in your own spaces and newlines for formatting purposes
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you know where the header files are located on your system? (probably under an include subdirectory of where your compiler is). Open up and look into <cstring.h> and see how "string" is defined. If "string" in this context is just an alias for a c-string, you can use all of the c-string functions on it. Look into strstr() http://www.cplusplus.com/reference/clibrary/cstring/strstr/, which functions a bit like find.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no idea on on how to use 'vectors'.

Yeah, then don't worry about that.

my borland compiler doesn't recognize the find() and erase() function

Yes. I don't know that it supports std::string, that's why I was surprised to see "string" in your program. One possibility is to change everything into C-strings (char *, null terminated) so you can employ the functions from the C standard library (in <cstring>), or you could write your own find and erase functions. Again, there's no real need to erase anything, as you just ignore the ones you're erasing when you're writing the rest out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, when you read them in, they do need to be stored in memory somewhere. You could use an array of strings. If you don't know how many you have, you can either try to overestimate how many slots you need, or (and this depends on your progress in your course) try a container like a vector.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There is a problem with line 112 if ((prodname[i] == '9')||(noOfItem == '9')||(priceOfItem[i] == '9') ||(cprice[i] == '9')){ in that noOfItem, priceOfItem, and cprice are integer arrays, and you're testing them for equality with '9' which is equal to 57 (check your ASCII table).

I wasn't able to trace through where you went wrong with the profitRep(), as your code is kind of all over the place, and honestly not well formatted.

In terms of finding and deleting the items from the file, the most efficient way with a small file is to read it in, and not write out the stuff you need to delete. Finding where something is in the file and removing it, while shifting everything else is not effective.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

except that the calculation part gives me different figures

Please try to narrow the error down to a section of code. I can't compile the whole thing because it's been Borlandated.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, i did a random search and daniweb results come out.

I believe the change by Google affected the results in the US the most, and Fortinbra is getting those results in the States.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do your API call in a backgroundworker (http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx). It's the "easiest" way to do threading in .NET. The only thing is, you have to pass back your information to the GUI in a specific way (which I cannot remember right now).

triumphost commented: Thanks for all your help :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The StringF in Form1_Load() is a local variable, which masks the "global" (really it's a member of the Form1 class) variable. Remove the System::String ^ portion off of the one in Form1_Load and it should be all set.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

To do that with C++, you need something like libcurl (http://curl.haxx.se/libcurl/).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do you know it's not working, you didn't print out anything!

With the extraction operator >> you don't need to read in the whole line, as if that were the case, you'd have to parse out all of the integers. Get rid of lines 16-22, you'd only need those if you were reading in line by line, but since you know how many elements there are, the for loop is taking care of it for you. You don't need to redeclare bd, as it's being passed in from whatever parent function you are calling this function from.

Keep 24-29, but it needs some changes. Your array is 3x3, correct? Check your loop indexes, trace through the loops on paper and see which elements are being read. No matter what N is, bd[N][N] is not an element of that array anyhow, you're one past the end in both dimensions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've got some sense of the problem, but your code is incorrect.

You declare y as a string on line 7, but treat it like an array of strings on line 12. In addition, your index of that array is a char, which could be technically correct, but, for example, y would equal y[65] and that's not what you want. Keep it as an array, but use a for loop to step through it in reverse.

There are other issues, too. <iostream.h> should just be <iostream> (you may need the .h if you have a prehistoric compiler from before the standard, but you are using <string>, so I'm not convinced that is the case. Also, main needs to explicitly return an int. The way you have it the int is implied, and this is also a pre-standard vestige.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It is a good thing, I offset your negative vote.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How about Twitter points, too? ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Substitute bd[i][j] for a

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a popup error message should show up if you've reached it

I've never run into the error message. I've only known because the "View Reputation" link didn't appear next to the arrows and I was sure that I hadn't given that person reputation already that day (and any subsequent attempts resulted in the same thing). I can't remember how long ago this was, mind you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

itsRadius is a pointer, you need to dereference it before incrementing it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Eliminate line 19 from your code.

If you use the >> operator, you can read in the numbers to an int variable. Is it guaranteed that your text file will contain NxN numbers. A nested for loop will help you to read them in, and it will look like insert >> (the integer variable).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hmm. Apologies that I'm not quite getting this. Are you trying to write numbers that are in the lines of text into the "bd" array? If so, you have to extract them somehow. What does text.txt look like?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where are you printing out the array?

I'm very confused, because the code you pasted above reads in a line and immediately prints it out. Is that the text to which you are referring or another line of text?

You won't be able to select where the text goes unless you are able to use a console library.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

its at the bottom of the page instead of where the array is

I'm not exactly sure what you mean by that, can you show a sample output?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there going to be one number per line?

There many different ways to do it. I'll list two that come to mind.
One way is to read the data in just to count how many elements there are and then allocate an array that is that size. Then you read it in "for real" into that freshly allocated array.
The second way is to declare a fixed-sized array that's likely to be larger than what you need and read directly into that. That approach has the limitations that you may run short or end up wasting space.

The first approach can be accomplished by reading in the lines using fgets (assuming there's a fixed number of values per line) to get the initial count. Allocate your array using malloc. Then reread the data using fgets and then use sscanf to extract the numbers from the lines you read in. If you haven't been taught those things yet, you can probably get away with using fscanf.

For the second approach you'd just use the fgets/sscanf combo without doing the initial read.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather than initially trying to shuffle your code all around, make a new file with a new main.

Write the functions in that new file and test them with simple cases using the new main.

Then once you've got them tested, copy them back into the old main and prototype them. Find out where you need those calculations, and substitute the function calls for the block of code you were using to do the same task before.

I know that's probably not as specific as you wanted it to be, but give it a try and post back.

Just an aside, if all of your else ifs from 65-140 are doing the same work, why not combine them into one line. I think as long as you make it readable, it should be more effective, and I think the reader will understand your goals there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please show the code where you are resetting it to "".

Edit: Try his ^^^^^^ suggestion first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The line for rep count on the profile gets connected to zero if you haven't gained any rep yet that week, it doesn't mean there's been anything negative(if it had been negative, I think the entire graph shifts up so it's noticiable). In any case, I only saw an upvote when I went to look at that thread.

Is it possible you've reached the daily limit (I forgot how many times you have to give rep, but I seem to have reached it on occasion)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

http://www.amazon.com/Artificial-Neural-Networks-Robert-Schalkoff/dp/007057118X/ref=ntt_at_ep_dpt_5 is a great book. It's out of print, but a lot of libraries probably still have a copy. It starts you at the early stages with the Perceptrons and goes through Hopfield nets and associative memories. I haven't formally looked into these things in a long time, but I google around it from time to time.

Look into something like the backprop (for a nice well explained example see http://www.codeproject.com/KB/recipes/BP.aspx) and I think the reasoning behind the Perceptron will probably click for you. The Perceptron is just a weighted sum, so if you had two inputs to it and each of those connections had the weight of 1/2, you'd be finding the average. Depending on the threshold, if the sum is over the threshold, there's output (though that output depends on what type of thresholding function you use).

In this case, the threshold is at 0, so any sum above zero would cause an output of 1, otherwise 0.
Poached from http://www.mathworks.com/help/toolbox/nnet/hardlim.html#499620

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If You are helping someone with Knowledge and if you think you should limit yourself in offering help, based on that person, then your thinking is slain.

I don't think that's correct. I don't think anyone would argue that we're here as a homework or coding service.

Since any one of us could be in a role of asker or answerer, the prerogative of being "always right" is not suddenly extended to the asker at the expense of the answerer.


I think if an OP starts being abusive, you have every right to sick this guy on them:

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What language are you trying to do this in? (looks like Matlab to me)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're always going to get some highly motivated people that are truly stuck or wanting to supplement, have made the effort, and are grateful for the help. The other side of that coin isn't always so pleasant. Don't let those bad eggs grind you down.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you run into this one http://www.scribd.com/doc/43968817/Write-a-Program-for-Imlementing-Perceptron-Learning-Algorithm ? Which part of the cprog part is giving you trouble? The Perceptron is a pretty bare bones architecture, and there are lots of situations where it just plain doesn't converge.

What type of project are you adopting it into? (if it's not top secret, lol)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read and reread the first response to this question.
http://stackoverflow.com/questions/4205050/inheriting-and-overriding-functions-of-a-stdstring

std::string is a typedef for a template class, so you would have to take that into account with your inheritance, etc.

Adjust your class declaration

class PString 
{
    public:	//1 fct prototype and 1 full constructor 
      bool isPalandrome();
      PString(string str); //shorthand, add your initialization list code onto this, add your const correctness too.
    private:
      std::string mystring; //let the constructor set this
};
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why are you inheriting from string on line 5? There's no need to do that.

You should have a private member variable that's of type std::string to receive your aString variable on line 12. I don't believe what you are trying to do will work.

c++,html,javascript,PHP,SQL,and c#

Get a copy of Partition Magic that works on your brain and section some of those off... ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out http://www.winprog.org/tutorial/ for information on the Win32 API. If you want a strictly C++ approach, look into MFC, but you need the full version of Visual Studio to use it. There's also Winforms via .NET, but they use C++/CLI, which is a dialect of C++ and not the standard language.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make sure that Qt is on your path, or start up the "Qt 4.x.x Command Prompt" from the start menu. Switch to your code directory and type:

qmake -project 
(which sets up the project folders)
qmake hello.pro
(or whatever you want to name the makefile, but I think it must be .pro
make

This info is probably tucked away in a corner somewhere within the book you are reading. They should express it more clearly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

calling a native C++ DLL from C# is possible

See this recent thread http://www.daniweb.com/software-development/cpp/threads/355990 for the caveats of that statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

However with all the libraries available for C++, wont C++ still stay a bit head when developing native programs?

Yes, it will stay far ahead. C++/CLI was never meant to home in on the C++ market, but was just meant to be a tool that is right for some jobs.

I'm assuming then using .NET wont allow you to use the a program developed in C++\CLI to compile and run on say a Mac then, compared to a general c++ program that can be compiled and run on a mac ?

Not yet, but maybe not ever, I don't know. I know the mono project (http://www.mono-project.com/Main_Page) is trying to get C# and .NET to work across Windows/Mac/*nix, etc., but I don't know if they have any plans to port C++/CLI. A library like Qt (which has GUI elements, but also has other components for things like sockets and database access), is something that would serve you well in developing cross platform apps.

Sorry if my questions seem a bit naive just trying to cover all my bases

No worries, sometimes it's hard to find information out on the net about it. I think some people want to put it out to pasture. I just find it to be an interesting dialect.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

String::Split() apparently has performance issues

Wasn't aware. That's good to know.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is the String^::split method available in your API? -- you could split on '\n' and that will fill your array automatically.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C++/CLI is the dialect of C++ which you use under the CLR. Languages that use the CLI have their code converted to MSIL (which is like assembly language, but not quite the same). The MSIL code gets run on a virtual machine, and a just in time (JIT) compiler turns it into bytecode. (I may have glossed over some points, so Wikipedia has great info on all of this for further reading).

When MS created managed C++ (the precursor to C++/CLI) they intended it as a go between in the relationship of native C++ and C#. That is its biggest advantage, IMO. You can write code in C++/CLI, and call it directly from C# (or VB, etc.), whereas calling a native C++ DLL from C# is possible, but requires a more elaborate procedure known as a platform invoke (P/Invoke). Of course the C++/CLI approach isn't perfect, and still requires a lot of translating pointers when there's any native code present. One upside is the ability to write WinForms programs in .NET, rather than operating with Win32API directly.

The downsides are numerous. This is not standard C++ by any stretch of the imagination. Some of the syntax is different, managed pointers are known as handles, which behave largely the same, but require some getting used to (as the memory is now managed by a garbage collector since you're in .NET). It's a bit esoteric (that's kind of what I like about it, actually), so it's not necessarily something that's …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thank you for trying with the code tags, but you don't need to tag each line separately. Put all of the code in between a single set of code tags.

You have: retirement = pmt * ((1 + wr)n - 1) / wr); Since the computer doesn't understand algebra (unless you program it to), you need to put a * in wherever it's needed. retirement = pmt*((1+w*r)*n - 1)/(w*r);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're welcome. You didn't say you were working with jpegs, I assumed you were sending text. Anyway, glad it's working.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since you are within a method of the object (set()) you can assign to the private members of the class directly. Get rid of line 34, and insert

x = p1;
y = p2;

(or just take the values from cin directly into x and y)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, I think you were well within your rights to say that. He didn't offer you any constructive criticism/justification with the downrep, so I wouldn't take it to heart. You contribute a lot to the site, so just let the good reps counterbalance this one.

P.S. The real crime here is that some people still use VB4

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're not allowed to use if/else, are you allowed to use the ternary operator "? :" If so, check it out. If not, I can't think of a way offhand that doesn't use if.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out http://drdobbs.com/cpp/229218807?queryText=counting+references from Dr. Dobbs last month, I don't know if it's along the lines of what you are looking for.

And yes, I agree with thekashyap, at least tell us what you've Googled about.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make some attempt. What you have displayed shows only the most minimal effort.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the ifstream as you are doing, it's a more C++ way of doing it than calling fopen is.

gcount() might work to tell you the number of characters you are going to send, as that will tell you how many characters you actually read in. It wouldn't buy you much with the seekg, as you'd have to "unget" all of the characters you just got.

I was suggesting rewind because it takes care of everything for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But there is another problem: I tried to transfer the file using a TCP socket, but the received file seems corrupted

You could have put that in the question, too. lol. No worries. Try changing your second seekg call on line 20 to a rewind http://www.cplusplus.com/reference/clibrary/cstdio/rewind/. That will bring you back to the beginning and reset the error flag (just seeking won't help the fact that the stream is invalid due to reading to the end of the file on the first run).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you had a fixed-sized array, you can use sizeof:

char a[5];
cout<<sizeof(a); //5

but if you were to pass it into a function as a pointer, that information is lost (as the array is reduced to a pointer).

void myfunc(char a[])
{
   cout<<sizeof(a);   //4
}

int main()
{
  char b[5];
  cout<<sizeof(b); //5
  myfunc(b);

}