Narue 5,707 Bad Cop Team Colleague

You can do it with two stacks or with one. With two stacks you would have a stack of operators (single characters at a minimum, but full strings are more flexible). When you pop an operator off of the stack, use the operator itself to determine how many values to pop off of the other stack (binary operators take two, unary operators take one, etc...).

Or you can store strings in one stack while mixing the values and operators. The values go with an operator, so when you hit an unexpected type, you can perform the operation.

Q8iEnG commented: Thanks for the help :) +1
Narue 5,707 Bad Cop Team Colleague

>I'm just wondering how to start doing this problem?
Start by understanding the process of converting infix to postfix. Once you have that, it's not much of a stretch to see how a stack could be used to do it. Or you could do a google search and get one of the many existing implementations to use as a template.

Narue 5,707 Bad Cop Team Colleague

>Any help is good =]
I'm curious, can you define what you mean by "help"? Because it looks a lot like you want us to do your homework for you.

Anyway, this may help you.

Narue 5,707 Bad Cop Team Colleague

>so i can't fix this?
It's hard to fix something that isn't broken. If you don't like the current result, change your formatting to better suit the display medium, or change the display medium to something better suited for your formatting.

Narue 5,707 Bad Cop Team Colleague

>it does not work and it makes the header go down to a second line
Unless you're actually printing a newline character somewhere, the problem is your console window isn't wide enough and wraps around. Try redirecting your output to a file and I'd be willing to bet that it looks just fine.

>Is there a way to expand the actual command prompt?
Not that I know of, at least not without delving into the realm of creating your own windows.

Narue 5,707 Bad Cop Team Colleague

>I just can't get them all in one line using setw()
Show us your code that uses setw, an example of the output you're expecting, and an example of the output you actually get.

Narue 5,707 Bad Cop Team Colleague

>While compiling in turbo c++ change
> #include<iostream> to #include<iostream.h> >same goes for "string" I believe you know this already
First, when compiling in Turbo C++...don't[1]. Second, changing <string> to <string.h> won't fix anything because those two headers are completely different. <string.h> holds the C string library functions and types while <string> hold the C++ string class. The two headers are not interchangeable.

[1] Unless it's Turbo C++ Explorer, which is a modern compiler in the same product line.

Narue 5,707 Bad Cop Team Colleague

>this code isnt workin
This is a waste of keystrokes. Do you go to the doctor, say "I don't feel good", and expect an accurate diagnosis? Do you go to the mechanic, say "My car is broken", and expect the actual problem to get fixed? If you answered no to either of those, why would you say to us "This code isn't working", and expect any response other than "Be more specific!". Seriously, it doesn't take much brain power to figure out that we need more information to help you, and if you can't understand that much, you have no business writing code.

>m not able to solve the errors showing
The code compiles and runs fine for me on Visual Studio. Maybe if you told us what errors you're getting... :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Why not?

Narue 5,707 Bad Cop Team Colleague
if (cin.good())
{
  break;
  cin.sync();
}

The sync call will never be reached in this snippet because break leaves the loop immediately.

>why ??
Because when you type a value that cin doesn't expect (ie. a non-integer character when an integer is expected), cin goes into an error state. When cin is in an error state, all input requests do nothing until you clear the state.

What your first example does (in theory) is clear the state and then discard all of the characters in the stream so that you wipe the slate clean and can try again. The second example tries to discard all of the characters in the stream first, even though the stream is still in an error state and the sync call is effectively a no-op because of it.

I say "in theory" because cin.sync() isn't required to flush the input stream.

Salem commented: Doin' the safety dance! +18
Narue 5,707 Bad Cop Team Colleague

Using read and write to serialize your objects is generally a bad idea. At the risk of being too vague, I'll distill all of my experience into one piece of advice for your convenience:

When you want to serialize an object manually, convert each of the fields to a string, format them as desired, and then write the string to a file. When you want to deserialize an object manually, read the string from your file, parse the string in a constructor, and populate the data members.

In code form, such a solution would look like this:

#include <sstream>
#include <string>
#include <vector>

class student {
public:
  std::string name;
  std::vector<std::string> classes;
  std::vector<int> grades;
public:
  student() {}
  student ( const std::string& serialized )
  {
    std::stringstream src ( serialized );
    std::string class_name;
    int grade;

    // No error checking
    std::getline ( src, name, '|' );

    while ( std::getline ( src, class_name, '|' ) ) {
      classes.push_back( class_name );
      src>> grade;
      grades.push_back ( grade );
    }
  }
public:
  std::string serialize ( std::ostream& out )
  {
    // Assume grades and classes are parallel
    // No error checking
    std::stringstream serialized;

    serialized<< name <<'|';

    std::vector<std::string>::size_type i;

    for ( i = 0; i < classes.size(); i++ ) {
      if ( i != 0 )
        serialized<<'|';

      serialized<< classes[i] <<'|'<< grades[i];
    }

    out<< serialized.str();

    return serialized.str();
  }
};

This way you don't have to know the POD type rules, you don't have to worry about what's undefined behavior and what isn't, and you retain maximum portability.

Narue 5,707 Bad Cop Team Colleague

>'foo' by itself is the address of the fn.
You can do two things with a function: call it and take its address. Both foo and &foo do exactly the same thing, but I prefer the latter because it's more obvious that I'm looking for an address.

You can also omit the pointer junk from the actual call:

printf ( "%d\n", p() );

But I generally keep it for the same reason, it's more obvious what's going on.

Narue 5,707 Bad Cop Team Colleague

Don't forget the argument list when you call the function through a function pointer:

#include <stdio.h>

int foo ( void )
{
  return 12345;
}

int main ( void )
{
  int (*p)( void ) = &foo;

  printf ( "%d\n", (*p)() );

  return 0;
}
Narue 5,707 Bad Cop Team Colleague

>temp1=temp;
>temp1->next=start2;
You say start2 is a null pointer, right? Well when you assign temp to temp1, you're aliasing temp, not copying the data at that address. So when you set temp1->next to null, temp->next is also set to null implicitly.

You probably want something more like this:

temp1->data=temp->data;
temp1->next=start2;
Narue 5,707 Bad Cop Team Colleague

>I am simply adding in that Delphi and VB are capable of doing games
Any language can be used to make games. Any language that has access to a graphics API can write graphical games. This doesn't make all of those languages well suited to making games.

>but was not sure if the reasoning for not mentioning them was due to
>lack of help (in this particular forum), or if c/c++ were the better choice.
It's the latter. Invariably, the people asking about writing games aren't thinking about Flash games or simple Java applets. They're thinking about World of Warcraft, Halo, or something along those lines. And for those type of games C, C++, and assembly are the kings both in common use and prerequisite knowledge.

Narue 5,707 Bad Cop Team Colleague

>not sure what you mean by "in a position to objectively
>compare the languages for your needs"
Basically, if you don't know both languages well enough to choose the right one for what you're doing.

>mainly asking since both delphi and c are products of borland.
Delphi is specifically a Borland product. C is an internationally standardized language with many implementations, one of them being a Borland product. If you don't like Borland's IDE for C, you can choose among the others. A bunch of them are free.

>I would be happy to take up c as well but if the
>2 are capable of doing basically the same thing.
Put simply, C can do everything Delphi can and a great deal more because it's not restricted to a single platform (unless you count Kylix, which I would not).

>Don't understand why there isn't much help in the
>way of game code for Delphi as there is for c.
I don't understand how you missed the masses of links to help on google.

>But I do understand your point " it is the older generation, and some people don't
>like to change esp when the current language (c/c++) has been proven successful.
It's nice you understand, but that wasn't my point at all.

Narue 5,707 Bad Cop Team Colleague

>Is there any specific reasoning one would not recomend vb or
>more specific to my needs Delphi using DelphiX to design games?
Most of the questions are far too general to recommend anything but the most common and widely used languages. Due to their saturation of the field and the fact that many modern languages are based off of them, C and C++ are pretty much required if you want to be a professional game programmer and still remain competitive. Whether you actually use them depends on the games you intend to write.

>Should I move out of Delphi and start learning another language
I always recommend a firm background in C, period. I also recommend at least rudimentary assembly experience. Beyond that, learn what interests you and what you think you'll end up using.

>Would I be better switching languages?
If you aren't in a position to objectively compare the languages for your needs, you would be better off not switching.

Narue 5,707 Bad Cop Team Colleague

>Would anyone be willing to see if you can tell me where my issue is.
That's simple enough. Your issue is here:

int i, j;

And it manifests here:

grid[i][j].row = i;
grid[i][j].col = j;
grid[i][j].frequency = 0;

i and j aren't initialized. Unless you get very lucky and your compiler automatically initializes local variables to 0, i and j are extremely likely to have garbage values that are well outside the bounds of your array.

Narue 5,707 Bad Cop Team Colleague

OffsetX is a read-only property, so all you can do is get the value:

x = my_matrix->OffsetX;
Narue 5,707 Bad Cop Team Colleague

You first.

Narue 5,707 Bad Cop Team Colleague

>What would be the syntax to insert say "hello" and say 3,3?

test.insert ( make_pair ( "hello",  map<int, int>() ) );
test["hello"].insert ( make_pair ( 3, 3 ) );

Don't forget that you need to create a new map for the second half of the pair.

>Also, how would I display the contents?

map<string, map<int, int> >::iterator iter = test.begin();

cout<< iter->first <<'\n';
cout<< iter->second[3] <<'\n';

Once again, remember that the second half of the pair is a completely separate map. iter->second gives you the map object, not an iterator.

Narue 5,707 Bad Cop Team Colleague

>Works fine.
I'd guess one of the following:

1) iostream includes it somewhere along the line.
2) Your compiler is nice enough not to throw an error.
3) Your compiler is too old to conform to the C++ standard.

Narue 5,707 Bad Cop Team Colleague

>Try--
>srand( time(NULL) );
How is that supposed to fix the incompatibility of time's return value with srand's parameter? By the way, 0 and NULL are identical in C++.

>try using time without ctime
Then the declaration would be missing.

>ctime has a function called time_t time ( time_t * timer )
>which most likely masks the time function defined in std
It's generally a bad idea to talk about things unless you have a clue. Seriously, I can't imagine where you pulled that explanation from.

Here's the real problem. time(0) returns a value of type time_t. srand takes a parameter of type unsigned int. The warning is saying that for the OP's compiler, time_t is a larger integral type than unsigned int and converting from the larger type to the smaller type may affect the value.

The easy solution is to use a cast to explicitly tell the compiler you know what you're doing and to shut the hell up:

srand ( (unsigned)time ( 0 ) );

But because of standard restrictions on time_t, you can't be sure that this will work in all cases (though I don't know of any systems where it will fail). The 100% correct solution is not to use time_t directly, but rather a hash of the value for seeding rand:

#include <climits>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>

unsigned hash_time()
{
  time_t now = time ( 0 );
  unsigned char …
Narue 5,707 Bad Cop Team Colleague

1) This looks like a perfect place to run a simple test on your own:

#include <iostream>

class Base {
public:
  ~Base() { std::cout<<"Base\n"; }
};

class Derived: public Base {
public:
  ~Derived() { std::cout<<"Derived\n"; }
};

int main()
{
  Derived d;
}

2) Sure, if you want an array of Base objects. If you want to be able to store both Base and Derived instances you probably want to use pointers to enable polymorphism. And if you're going to be using Derived polymorphically, I would recommend making your destructors virtual to avoid slicing.

Narue 5,707 Bad Cop Team Colleague

>How is that occurring, by adding an extra dimension to array it takes both words.
It helps to know that the native string type in C++ is actually an array of char, and cin's >> operator is pretty smart about knowing what types you give it. When array is an array of char, cin>>array[i]; will read a word into it. when array is a single char, cin>>array[i]; will read a single character into it.

Narue 5,707 Bad Cop Team Colleague

>I tried to be as constant as possible... I got the following errors--
When I move around code, I do it for a reason. In this case, I moved the definition of mStruct outside of main because extern variables can't be initialized there. Oddly enough, your error says just that. :icon_rolleyes:

Here's some complete code for you to work with:

#include <iostream>

using namespace std;

struct MyStruct {
public:
  int x, y;

  MyStruct ( int first=0, int second = 0 )
    : x ( first ), y ( second )
  {};

  const int getX() const { return x; }
  const int getY() const { return y; }
};


class RestrictedTemplateClass {
public:
  template<const MyStruct &B>
  const static void displayParameters()
  {
    cout<< B.getX() << ", " << B.getY() <<'\n';
  }
};

extern const MyStruct mStruct ( 1, 2 );

int main()
{
  typedef RestrictedTemplateClass RTC;

  RTC::displayParameters<mStruct>();
}
Narue 5,707 Bad Cop Team Colleague

>Why is it that I cannot call th method in RTC::displayParameters() with
>the template-argument mStruct* when it is clearly a constant reference?
Because it clearly isn't. Let's start with the fact that <mStruct*> is a syntax error. The closest interpretation would be to call the instantiation of displayParameters using a pointer to mStruct. But mStruct isn't a type, and displayParameters doesn't even have a specialization that takes a type. So let's move that asterisk to a better location and work from your perceived problem:

const MyStruct * const mStruct = new MyStruct ( 1, 2 );

RTC::displayParameters<*mStruct>();

*mStruct is constant, but not the compile-time constant that templates require because you're using dynamic memory. But even if you remove that and make it a straight const object, it still won't work:

const MyStruct mStruct ( 1, 2 );

RTC::displayParameters<mStruct>();

Why? Because the local variable doesn't represent a compile-time constant either. To get a suitable constant object, the variable has to be non-local and have external linkage:

extern const MyStruct mStruct ( 1, 2 );

int main(int argc, char *argv[])
{
  RTC::displayParameters<mStruct>();
}

Furthermore, because the object has to be pretty darned constant, you need to specialize the template for that as well if you intend it to work:

template<const MyStruct &B>
static void displayParameters()
{
  cout << B.getX() << ", " << B.getY() << endl;
}

And of course, because the object is const, the member functions you use must be const as well:


       
Narue 5,707 Bad Cop Team Colleague

If you just want to use hash tables then the TR1 libraries are sufficient (assuming you have them). If you want to learn how hash tables work, then a good start would be this tutorial.

Narue 5,707 Bad Cop Team Colleague

>but can u just make the
>int x and int y public instead?
You can, but public data is typically a bad idea because it means you're giving full control over the values to everyone. Most of the time you don't want to do that, which is why public or protected member functions are used to give access without losing control.

Narue 5,707 Bad Cop Team Colleague

>I usually think of an "Expert Meanie"...
Well, I used to be an "Accomplished Meanie" until that whole TkTkorrovi episode. That pushed me well into the range of expert. :)

>In order to begin learning about Win32 and other programming languages
>for windows applications, I see C++ knowledge is a must.
The Win32 API has a strong foundation in C concepts, so even if you know C++, you'll find certain conventions to be awkward or even "unnatural" from a C++ perspective. MFC was designed as a C++ wrapper for parts of the Win32 API to fix that. I'd say that C knowledge is a must, but I say that for everything. ;)

>But after learning C++ is Win32 a completely different language with similarities.
Win32 is a library of functions and types that you can use from C++. And yes, it's very different, conceptually, from the basics that you're learning now, which likely uses a command-line interface.

Narue 5,707 Bad Cop Team Colleague

>i'm not so bad at picking out the experts and arrogant individuals either.
Which do you pick when an individual is both arrogant and an expert?

>do you mind telling me what the difference between a GUI and Application is?
A GUI is a type of interface for interacting with an application. Another interface type would be command-line. Others that come to mind might be an API or a domain specific language.

Narue 5,707 Bad Cop Team Colleague

Wow, this thread is all over the place, even compared with some of the tangents we get off on normally.

>I don't mind too much if others think I am dumb or anything as im LEARNING
Rest assured, we're generally very good at telling the difference between a beginner and an idiot. But also keep in mind that the programmers most qualified to help you around here are more likely to cut right to the chase and not sugar coat anything. You can find a good description of the "attitude" here.

Narue 5,707 Bad Cop Team Colleague

>I was asking for someone to point out there exists Win32!
Yep, that's immediately obvious from your original question of "What is C++ good for?". :icon_rolleyes: If I were to rate your question, it would be along with every other vague question that has no hope of getting an answer without a lot of dumb luck.

Narue 5,707 Bad Cop Team Colleague

>So your telling me what is being displayed on my windows
>screen is the output of a combination a C++ program?
I'm telling you that the Windows operating system is written in a combination of C and C++. Most of the programs you run are as well.

>but howwwwwwwwwwwwwwwwwww :O
Not to be rude or anything, but if you're as new to programming as it seems, you won't get it even if we told you. There's a lot of prerequisite knowledge that comes with understanding how non-trivial programs are written. As you learn more about programming and C++, you'll gradually come to an answer.

Narue 5,707 Bad Cop Team Colleague

>But I mean if I got a job which required C++ knowledge, what would they ask me to program?
You're not very quick, are you? If you get a job writing C++ code, and C++ can be used pretty much anywhere, then it stands to reason that they could ask you to write anything. It depends on what the job is. For example, I don't really expect anyone to ask me to write an operating system, because that's not in my job description.

>Can you name a specific program that used C++/C
>programming.... that people may be using everyday.
Windows, pick any version.

Narue 5,707 Bad Cop Team Colleague

>What are the PRACTICAL APPLICATIONS of C++ and even C for that matter.
Literally anything. Pick a program and it was probably written in some combination of C and C++, or written with a language that was implemented using C or C++.

Narue 5,707 Bad Cop Team Colleague

>Is the solution simply to accept it as a char* instead of a const char*?
Hardly. It's better to understand the error and correct your logic rather than bumble your way through a workaround that will end up mysteriously crashing your program.

>I thought it was always better to have things const if you weren't going to modify them?
Not only is it better to use const when you aren't planning on modifying something, it's better to use const everywhere and only remove it when you absolutely have to. That guideline is much more of a pain to adhere to, but the const correctness you get from it is worth the effort.

>ok, so assuming I pass the function a const char*
Assuming you want to support passing string constants, your best bet is to convert to a string object and use the concatenation operator:

#include <string>

void MyFunc(const char* Filename)
{
  cout << std::string ( Filename ) + ".tst" << endl;
}

>I'd need to convert it to a char* before I append anything.
No, because the pointer points to read-only memory. It really is const, so tossing away the const qualification is only going to move your error from compile-time to runtime. Your code is broken, and playing around with const isn't going to change that.

Narue 5,707 Bad Cop Team Colleague

>...And of course he has waited to the last minute so he needs it asap
Well, that's his problem, not ours.

Note that these answers assume that by "game developer", you mean a programmer rather than a graphic designer or one of the many other roles involved in creating a game.

>1. What would best prepare me for making a video game?
Professional games tend to ride the edge of hardware technology, so you should be very familiar (not to mention up to date) with computer hardware, especially graphics hardware, and how to interface with it. In my experience, game programmers are among the more talented programmers, so you should also have a strong foundation in programming theory and practice as well as the drive to compete in the industry.

>2. How long have you been working with video game making and designing?
I don't work in the game industry, nor is it a hobby. My focus is on developer tools and compilers, but I've consulted for professional game projects in the past on back-end code.

>3. What program is used to make a video game on the computer? Programs?
No single program is used, but you can expect a good development IDE, usually a 3D or 2D graphics package and a sound manager.

>4. How many steps are there in making or designing a video game?
Pretty much the same steps as any other end user software.

>5. …

majestic0110 commented: Better answers than mine :) +3
Narue 5,707 Bad Cop Team Colleague

You need to add the appropriate DLL as a reference. You can do that from the UI by right clicking on your project and choosing "References". From there you can add a new reference for .NET. Alternatively you can reference the DLL directly from your code with a #using statement:

#using <mscorlib.dll>

using namespace System;

int main()
{
  Console::WriteLine ( "Hello, world!" );
}
VernonDozier commented: This fixed the problem. +2
Narue 5,707 Bad Cop Team Colleague

>How can i do it in C?
File handling examples for C are all over the place, but I'm guessing you didn't bother to search this forum. Here's yet another example:

#include <stdio.h>

int main ( void )
{
  FILE *out = fopen ( "filename", "w" );

  if ( out != NULL ) {
    fprintf ( out, "Gold: 123" );
    fclose ( out );
  }

  return 0;
}

>I went to c++ forum and saw it but fstream doesn't work on C.
Well, duh. C++ isn't C.

Narue 5,707 Bad Cop Team Colleague

>2. Naruto
In my experience, people who have Naruto in their top 10 haven't seen many good anime. ;)

>3. Dragonball Z (if it counts)
It counts. I would say any anime that originated in Japan or any cartoon that has a noticeable anime influence (ex. Avatar or Code Lyoko) counts.

Narue 5,707 Bad Cop Team Colleague

>can anyone tell me if global variables are not liked
Experienced programmers tend to cringe when they see global variables.

>and why
Global variables are almost always an indication of poor design. They're such a small and innocent seeming thing, but the repercussions can be truly frightening if you know what to look for.

A good analogy for global variables is throwing a stone into a pool of water. You throw the stone in the pool and it makes a little splash. Then there are ripples all the way to the edges of the pool. Then the stone wedges itself in a submerged gas vent that builds up pressure for several days and explodes spectacularly, causing untold pain and chaos. ;)

jephthah commented: LOL :) +2
Narue 5,707 Bad Cop Team Colleague

>What do you think of Akira ?
It's a cult classic, but I never figured out why.

Narue 5,707 Bad Cop Team Colleague

1) Sailor Moon (for sentimental reasons)
2) Haruhi Suzumiya no Yuutsu
3) Tenshi na Konamaiki

Narue 5,707 Bad Cop Team Colleague

Wow, just wow. Here's the code you wanted, not that I think it'll help you any:

#include <iostream>

int main()
{
  int value;

  std::cout<<"Enter a number: ";

  if ( std::cin>> value ) {
    // The loop stops on 0, so
    // treat it as a special case
    if ( value == 0 )
      std::cout<< value <<'\n';
    else {
      while ( value != 0 ) {
        std::cout<< value % 10 <<'\n';
        value /= 10;
      }
    }
  }
}
Narue 5,707 Bad Cop Team Colleague

>As in selecting which line to start from.?
Sure, but unless the file is structured enough to seek, you'll have to actually read your way to the correct line. Writing is harder if you mean to insert rather than overwrite. In that case you need to save the subsequent lines and shift them over like you would insert into an array.

CodeBoy101 commented: somewhat helpful +1
Narue 5,707 Bad Cop Team Colleague

>about how this could be achieved i meant solutions
I gave you two solutions. The code is trivial.

>for "number % base" would i change them to my variable names
If you want it to work. In particular, if I have an integer called value and I want the least significant base 10 digit, I would say value % 10 .

Why don't you actually try these things instead of look for existing code and expecting handouts? You'll learn a lot more that way.

[edit]
It's terribly rude to replace your post with something completely different after submitting it.
[/edit]

Narue 5,707 Bad Cop Team Colleague

Here's a hint: What does fork do?

Narue 5,707 Bad Cop Team Colleague

>wanted to know if it could be done
If you find yourself asking if "<insert something here> can be done in C++", just go ahead and assume the answer is yes. It probably is.

>Could you please show me how this could be achieved thanks.
How about I tell you and you try it out on your own?

Solution 1: Convert the number into a string and reverse the string.
Solution 2: Use number % base to extract the least significant digit and print it until the number is 0. This method gives you the digits in reverse by default.

Narue 5,707 Bad Cop Team Colleague

Post the code that calls getRand.