Print 

Author Topic: C++ Help!  (Read 6087 times)

Offline BFM_Edison

  • Captain
  • *
  • Posts: 3074
Re: C++ Help!
« Reply #15 on: March 05, 2008, 04:59:34 PM »
- Yes, there are cosmetic errors in my pseudocode.... (That's why there are junior programmers and compilers, you know!  ;) ) Heck, I didn't even throw in all the REQUIRED commentary!  :P  :winkgrin:

- 'Better learn about arrays BEFORE you even learn about "for" loops!!  ::)

That didn't really look like simple pseudocode which tends to not have that type of format. And comments are not required! I have to add comments to my Internal Assessment for Java and it gets boring.

I learned about for loops way before arrays. I think we mainly used for loops for string manipulation for stuff like reversing the order. Although, in a sense, a string is sortof an array of tokens. You can also use them for incremental counting type stuff, like printing out the fibonacci sequence, square numbers, a pyramid thing, etc. Of course, this is rarely useful >.>
52.87   60.07   46.40   72.73   68.23   55.10   98.27   84.73

Offline AR~Archon

  • Senior Poster
  • ****
  • Posts: 846
  • No surrender, no retreat
    • MacFire (Xfire for Mac)
Re: C++ Help!
« Reply #16 on: March 05, 2008, 09:05:39 PM »
- Yes, there are cosmetic errors in my pseudocode.... (That's why there are junior programmers and compilers, you know!  ;) ) Heck, I didn't even throw in all the REQUIRED commentary!  :P  :winkgrin:

Point taken, Mxy ;D.  Looked like C++ code to me :P.

Quote
- Given the extraordinary optimizations that have gone into today's compilers (pretty much ALL of them) and into the CPU devices themselves, if you're ever going to do any "small" sequence more than two times your better off using a loop.... (In fact, tight loops are also the fastest code for today's CPUs to execute, since it stays in L1 cache....)

Yes and no.  Certainly tight loops are better for cache locality (as you indicated).  In this particular trivial case, it seemed to me to be extra effort for little practical gain.  It probably takes a few more than just 2 iterations to really make a difference.  But, that may just be me.

Quote
- Tale: I once wrote a "case()" statement that was SO HUGE it exceeded the compiler's MEMORY JUMP RANGE and busted up our (Fortune 1000 Co's) COMMERCIAL, SHIPPING COMPILER!  :siderofl: :siderofl: (The down side: It produced NO ERROR during compilation, it just jumped to some "random (okay addr-32KB... Ya KB, I'm OLD! But then, our entire OS ran in 4MB! ::) )" location in memory during execution and continued on its merry way!  . . . Debug THAT bugger!!!  :o )

:siderofl:  A couple of years ago I was evaluating the next version of our vendor's ARM7 instruction set simulator.  The test script/code crashed the simulator spectacularly, with the Program Status Register set to 0xDEADBEEF.  :o


Okay, so i need more help now.  I will go to my professor, i just want you guys' input:
.....

I'm not familiar with your environment specifically.  C++ does not have a built-in complex string type.  The 'string' type is a class.  You may have to do a:
Code: [Select]
#include <string>
at the top of the file.  Let me know if that works.  (There is another potential complication, depending on your environment.)

:munch:

;D
The minstrel boy to the war has gone...
Understanding is a three edged sword.  Your side, their side, and the truth.
Who are you?  What do you want?  Why are you here?  Where are you going?




Offline MrMxyzptlk

  • Posts Too Much
  • *****
  • Posts: 9208
  • Never backward,           always forward!
    • My 5th Dimensional Homepage
Re: C++ Help!
« Reply #17 on: March 05, 2008, 09:51:07 PM »


#include <string>

Yeah, I was gonna say that same thing, since include methods are not all that portable. (Some development environment one's will do them for you automatically, but if you truely compile it on another machine ... no worky.)

Mr. Mxy's current Word Corner word is catachresis    

Offline Goalie

  • Posts Too Much
  • *****
  • Posts: 2462
  • Congrats Jordan Lynch, 3rd place in Heisman!!!
    • York Set/Tech Crew
Re: C++ Help!
« Reply #18 on: March 05, 2008, 11:23:35 PM »
Tried, #include <string>, doesn't work.
Like I said, I just want it to work on my laptop, but I can do it somewhere else if it becomes an issue.

Dev C++ is a free program that works for Vista, so that's why I'm using it.  The computer labs have licensed software on their computers, so its better in some ways.
You blame me?  Remember it had to get past 10 other players before I saw the ball.

Thanks to Spidey for this sig!                                                                                                                  .

Offline Contact

  • Posts Too Much
  • *****
  • Posts: 1325
  • You will give my Hoggie back!
Re: C++ Help!
« Reply #19 on: March 06, 2008, 01:43:53 AM »
They are still teaching C++ on that side of the pacific  _idk_

Most Uni's (College's) here are now going for Java or C# - depending on their affiliation to a particular OS


Offline Taipan™

  • Posts Too Much
  • *****
  • Posts: 1297
Re: C++ Help!
« Reply #20 on: March 06, 2008, 04:51:14 AM »
they still do here Contact at newie as well

If i was doing IT instead of Electrical engineering in second semester first year I would of had to do C++, however for first semester last yr I did Java (god knows what that has to do with electrical engineering)

Offline AR~Archon

  • Senior Poster
  • ****
  • Posts: 846
  • No surrender, no retreat
    • MacFire (Xfire for Mac)
Re: C++ Help!
« Reply #21 on: March 06, 2008, 07:54:05 PM »
Tried, #include <string>, doesn't work.
Like I said, I just want it to work on my laptop, but I can do it somewhere else if it becomes an issue.

Dev C++ is a free program that works for Vista, so that's why I'm using it.  The computer labs have licensed software on their computers, so its better in some ways.

What error do you get?

I took a quick look at the Dev-C++ web site.  From what I can tell (without actually trying Dev-C++), it looks it uses relatively recent versions of GCC.  Therefore, I think you need to include a namespace directive.  I purposefully omitted it from my previous post because I wasn't sure whether it was necessary (in the not-too-distant past, some C++ compilers did not properly implement or support namespaces).  And, I'm sure namespaces are way beyond where you are at in your class.

Try this:

Code: [Select]
#include <string>
using namespace std;


They are still teaching C++ on that side of the pacific  _idk_

Most Uni's (College's) here are now going for Java or C# - depending on their affiliation to a particular OS

C++ is a perfectly good language (if a bit schizophrenic in design), and still very widely used.  It's utility depends upon what you're trying to do.  I've read lengthy discussions on whether to use Java, C#, or C++ in curricula.  They all have their advantages and disadvantages.  When I took the algorithms and data structures class, my class was among the last to use C++; they switched to Java the next year, IIRC.
The minstrel boy to the war has gone...
Understanding is a three edged sword.  Your side, their side, and the truth.
Who are you?  What do you want?  Why are you here?  Where are you going?




Offline BFM_Edison

  • Captain
  • *
  • Posts: 3074
Re: C++ Help!
« Reply #22 on: March 06, 2008, 08:41:14 PM »
The IB (International Baccalaureate) classes, which are international, all use Java, as far as I know. The official book is on Java and the tests are, although I don't think the book is very good...
52.87   60.07   46.40   72.73   68.23   55.10   98.27   84.73

Offline Goalie

  • Posts Too Much
  • *****
  • Posts: 2462
  • Congrats Jordan Lynch, 3rd place in Heisman!!!
    • York Set/Tech Crew
Re: C++ Help!
« Reply #23 on: March 06, 2008, 08:47:38 PM »
We do use namespace.  I accidentally forgot to put that in when I typed up the code.  Maybe that's what's wrong.  i'll get back to ya.

That did it.  I'm always forgetful.  Thank you, I think that's all for now.  If anything else comes up, i'll let yall know.
« Last Edit: March 06, 2008, 08:51:02 PM by Goalie »
You blame me?  Remember it had to get past 10 other players before I saw the ball.

Thanks to Spidey for this sig!                                                                                                                  .

Offline AR~Archon

  • Senior Poster
  • ****
  • Posts: 846
  • No surrender, no retreat
    • MacFire (Xfire for Mac)
Re: C++ Help!
« Reply #24 on: March 06, 2008, 10:11:18 PM »
Glad I could help :).  It's been a long time, but I don't think we learned about namespaces until later in the course :P.
The minstrel boy to the war has gone...
Understanding is a three edged sword.  Your side, their side, and the truth.
Who are you?  What do you want?  Why are you here?  Where are you going?




Offline Goalie

  • Posts Too Much
  • *****
  • Posts: 2462
  • Congrats Jordan Lynch, 3rd place in Heisman!!!
    • York Set/Tech Crew
Re: C++ Help!
« Reply #25 on: March 06, 2008, 10:15:26 PM »
Well, we haven't learned how to properly use namespace or what it does exactly, but we use "using namespace std;" and that's it.
You blame me?  Remember it had to get past 10 other players before I saw the ball.

Thanks to Spidey for this sig!                                                                                                                  .

Offline Goalie

  • Posts Too Much
  • *****
  • Posts: 2462
  • Congrats Jordan Lynch, 3rd place in Heisman!!!
    • York Set/Tech Crew
Re: C++ Help!
« Reply #26 on: April 11, 2008, 01:28:33 PM »
Back for more help, that I am.  So now we are working with arrays (oooooooo, aaaahhh), and I have to send multiple arrays from main() to another function.  When I compile, it gives me this error:

In function 'int main()': cannot convert 'doublex' to 'double' for argument '1' to 'void buildArrays(double, double, double)'

These are the lines that pertain to this problem:

Quote
     double gas[NUM_MON], elec[NUM_MON], water[NUM_MON];
     buildArrays(gas, elec, water);
Quote
void buildArrays(double gas[], double electricity[], double water[])
{
}

NUM_MON is a constant int with the value 12.

For those of you that don't understand C++:
The call statement for buildArrays does not have to have the same variables as the function.  It knows the numbers/arrays by position (gas = gas[], elec = electricity[], water = water[]).
Numbering each position in an array always starts with 0.  That means since there are 12 positions in the array, numbering goes from 0 to 11 (which also means that the error is referring to the 2nd position, numbered "1").

According to my professor's lecture notes, I am doing this correctly.  Any ideas what is wrong?
As stated with my earlier problem, I use a different C++ program than my professor.  This may contribute to the problem, but I doubt it.

Any help would be greatly appreciated. Java is very similar to C++, so those that know Java can also cotribute their 2c.

Thanks in advance!
You blame me?  Remember it had to get past 10 other players before I saw the ball.

Thanks to Spidey for this sig!                                                                                                                  .

Offline AR~Archon

  • Senior Poster
  • ****
  • Posts: 846
  • No surrender, no retreat
    • MacFire (Xfire for Mac)
Re: C++ Help!
« Reply #27 on: April 11, 2008, 08:52:03 PM »
Double check to make sure your declaration of buildArrays is consistent with the definition of buildArrays.  That is, make sure your function or method prototype doesn't look like this:

Code: [Select]
void buildArrays(double gas, double electricity, double water);

When I try that with gcc 4.0.1, I get the same error you do.  I don't get a definition inconsistency error due to operator/method overloading.
The minstrel boy to the war has gone...
Understanding is a three edged sword.  Your side, their side, and the truth.
Who are you?  What do you want?  Why are you here?  Where are you going?




Offline Goalie

  • Posts Too Much
  • *****
  • Posts: 2462
  • Congrats Jordan Lynch, 3rd place in Heisman!!!
    • York Set/Tech Crew
Re: C++ Help!
« Reply #28 on: April 11, 2008, 09:02:59 PM »
This is what my prototype says:

void buildArrays(double, double, double);

It looks okay.  Not sure what the problem is.
You blame me?  Remember it had to get past 10 other players before I saw the ball.

Thanks to Spidey for this sig!                                                                                                                  .

Offline BFM_Edison

  • Captain
  • *
  • Posts: 3074
Re: C++ Help!
« Reply #29 on: April 11, 2008, 09:03:18 PM »
I prefer to create only one variable per line, as it is easier to see. I don't know if it's different in C++, but in Java you declare it this way: double[] ArrayName = new double[numElements]; So maybe the problem is you didn't initially declare them. You can do that with primitive variables, but not things like String and Arrays.

You might also need your parameters to be double[] as opposed to double, because the one with brackets indicates an array. In fact, I think that's the problem, because the raised x might indicate an array, and it can't convert an array of doubles to a single double. So double[] gas instead of double gas[].

That's all I can think of.

52.87   60.07   46.40   72.73   68.23   55.10   98.27   84.73

Print