Narue 5,707 Bad Cop Team Colleague

>But the easiest to code is standard qsort() method.
Which, despite the name, isn't required to be quicksort. ;)

Narue 5,707 Bad Cop Team Colleague

>so I thought that it will be more convenient if I
>check wheter it is valid before trying evaluate it...
Well, then you have to decide which you want more: the efficiency of validating during evaluation, or the convenience of validating before evaluation. If you want to validate separately, you're going to process the expression at least two times. There's no simple way of getting around that.

Narue 5,707 Bad Cop Team Colleague

>I thought if we input a very long postfix expression it won't be efficient.
Efficiency is relative. Don't forget that computers are pretty darn zippy, and something that doesn't seem efficient could very well be more than fast enough for your purposes. Programmers are notoriously bad at guessing where inefficiencies lie.

>Can it controlled without using a stack twice???
Your terminology is confusing. What do you mean by "controlled"? Presumably you're trying to evaluate a postfix expression with error handling. You didn't provide much code, so I'm a bit confused as to why you can't validate the expression as you evaluate it. That's one of the nice things about postfix, you immediately know when the next operation won't work and can fail intelligently.

Narue 5,707 Bad Cop Team Colleague

>I'm using the stack twice and I didn't find it efficient.
Are you just eyeballing it and thinking "that can't be efficient", or did you profile multiple executions and get hard numbers that proved it's consistently slower than your allowable limit?

Narue 5,707 Bad Cop Team Colleague

>after the 10 guesses or if the the guesser gets it correct it
>should ask if the player wants to play again and react accordingly.
So wrap the whole thing in another loop and prompt for whether the user wants to play again.

Narue 5,707 Bad Cop Team Colleague

>int iProduct;
You're using iProduct without initializing it.

while (iNumber <= iCount)
	iProduct *= iNumber;
	iNumber++;

C++ isn't Python. 99% of the time, whitespace means bupkis, absolutely nothing. If you have a loop or conditional with more than one statement, you must wrap those statements in parentheses:

while (iNumber <= iCount) {
	iProduct *= iNumber;
	iNumber++;
}
Narue 5,707 Bad Cop Team Colleague

Check your spelling, check the number of arguments, check the type of arguments, and if none of that works, make a tiny program that exhibits the problem so that we can actually compile and link it ourselves instead of trying to decipher the snippets that you think are relevant.

Narue 5,707 Bad Cop Team Colleague

>out<<num.a;
>out<<num.b;
First I'd suggest you separate those two values with something. Your actual output is 43,0.

if(i==1)
{
  num.a = line[i];
}

At position 1 in "7+i3" is '+'. So the first problem is that you're assigning the wrong character. The second problem is that you're assigning the value of the character and not the value of the digit it represents. So even if you change that test to i == 0 , you'll still get (most likely) 55 instead of 7. For single digits you can subtract '0' from the digit to get the proper value:

if ( i == 0 )
{
  num.a = line[i] - '0';
}

Rinse and repeat.

Narue 5,707 Bad Cop Team Colleague

srand seeds the random number generator. If you call srand too often, and the value you use as the seed (srand's argument) changes infrequently, you'll keep seeding the random number generator to the same thing and rand will produce the same sequence. This will give you an idea of how rand and srand work together, but the simple answer is that you should call srand once:

#include <stdio.h>
#include <time.h>

int gimme_random ( void )
{
  return 1 + rand() % 10;
}

int main ( void )
{
  int i;

  /* Call srand only once */
  srand ( (unsigned)time ( NULL ) );

  for ( i = 0; i < 10; i++ )
    printf ( "%d\n", gimme_random() );

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

>I created a Fibonacci Sequence array and tried to
>apply the same thinking to the factorial program
That's a beautiful approach. Take a problem you've already solved and morph it into something similar that solves your current problem:

#include <stdio.h>

int fibonacci ( int n )
{
  int last = 0;
  int curr = 1;
  int next;

  if ( n < 2 )
    return n;

  while ( --n >= 1 ) {
    next = last + curr;
    last = curr;
    curr = next;
  }

  return next;
}

#define LIMIT 10

int main ( void )
{
  int save[LIMIT];
  int i;

  for ( i = 0; i < LIMIT; i++ )
    save[i] = fibonacci ( i );

  for ( i = 0; i < LIMIT; i++ )
    printf ( "%d ", save[i] );

  printf ( "\n" );

  return 0;
}

Just because you couldn't figure it out doesn't mean that you don't have a promising thought process. I think you'll be a pretty good programmer if you keep at it. :)

Narue 5,707 Bad Cop Team Colleague

>can anyone please tell me how?
Use stringstream to handle the conversion for you. This relies on the existing formatted input code and saves you the trouble of writing the tricky algorithms yourself:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
  std::string line;

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

  if ( getline ( std::cin, line ) ) {
    std::stringstream conv ( line );
    int result;

    if ( conv>> result )
      std::cout<< result <<" squared is "<< result * result <<'\n';
    else
      std::cerr<<"Invalid input\n";
  }
}

If you write your own conversion it might look something like this C implementation:

#include <ctype.h>
#include <errno.h>
#include <limits.h>

const char *parse_int ( const char *s, int *value )
{
  /* Base of the final converted value */
  const unsigned base = 10;

  /* Largest value that won't ever overflow */
  const unsigned limit = UINT_MAX / base;

  /* Largest value that won't overflow beyond the limit */
  const unsigned top_digit = UINT_MAX % base;

  unsigned overflow = 0; /* True if integer overflow occurs */
  unsigned sign = 0;     /* Final sign of the converted value */

  unsigned temp = 0;     /* Intermediate converted value */
  unsigned n = 0;        /* Count of converted digits */

  /* Save and skip over the sign if present */
  if ( *s == '-' || *s == '+' )
    sign = *s++ == '-';

  /* Build the intermediate value */
  for ( ; isdigit ( *s ); s++, n++ ) {
    unsigned digit = …
Narue 5,707 Bad Cop Team Colleague

>But that's just my opinion of that FOR command
Well, your opinion doesn't define how the loop works. Neither does mine. Only the teacher teaching that pseudocode can tell us what he expects the semantics to be.

Narue 5,707 Bad Cop Team Colleague

Hi nitishssingh. I read the PM you sent me, and no, I won't help you cheat your way through school.

Narue 5,707 Bad Cop Team Colleague

>so with that being said then the loop would execute 9 times?
That would be my guess, but this is definitely something you should ask your teacher about. Pesudocode is arbitrary; there aren't any hard rules, so for something like this you need to find out what's expected.

Narue 5,707 Bad Cop Team Colleague

>You really are ridiculous <snip>
I'd recommend that you review the use of punctuation in written English. A dash isn't acceptable punctuation for correcting run-on sentences.

>I can see this is not a friendly forum and I will just take stuff out
>of the text like I was and get no explanation for what I am doing.
Okay. Bye bye. Oh wait, you were trying to martyr yourself, weren't you? Otherwise you would simply have left without making a big stink about how you've been slighted, we're all evil people, and you're going to run off to suffer, all alone with your book that doesn't teach anything.

Boo-hoo, cry me a river, play me a tune on the violin, then shut the hell up and go away already. You clearly aren't going to ask a smart question (look, I even linked you to it again), and it seems you're only interested in being a whiney baby. So shoo; go away and grow up a bit.

Narue 5,707 Bad Cop Team Colleague

>Even though you tell me print it to cout and outfile my book says nothing about
This is what I was thinking of for your table printing loop:

outFile <<gTable[i].getName()<<" "
  <<gTable[i].getExamOne()<<" "
  <<gTable[i].getExamTwo()<<" "
  <<gTable[i].getHomework()<<" "
  <<gTable[i].getFinalExam()<<" ";

if ( finalGrade > 90 ) {
  cout<< setw( 11 ) <<"A";   
  outFile <<"A"<<endl;   
}
else if ( finalGrade > 80 ) {
  cout<< setw( 11 ) <<"B";
  outFile <<"B"<<endl;
}   
else if ( finalGrade > 70 ) {
  cout<< setw( 11 ) <<"C";
  outFile <<"C"<<endl;
}    
else if ( finalGrade > 59 ) {
  cout<< setw( 11 ) <<"D";
  outFile <<"D"<<endl;
}   
else {
  cout<< setw( 11 ) <<"F"; 
  outFile <<"F"<<endl; 
}
Narue 5,707 Bad Cop Team Colleague

>Believe me, I wish I could just sit here and be done in 10 mins like you probably could.
I can empathize. Nobody is born knowing how to do this stuff. In fact, programming is very hard, and it takes a lot of dedication to become good at it. But still... ;)

Narue 5,707 Bad Cop Team Colleague

>I went to the apple site after trying to find GCC and i found this:
A cross-compiler probably isn't what you want. Just stick to a Mac compiler and keep to standard C++. Your code will recompile on other systems without a problem. Cross-compilers are used when you want to develop for a system that you don't have ready access to or to simplify development. One example is a cross-compiler/emulator for embedded processors that runs on a Linux box. That way you can develop on Linux, for your toaster, without having to deal with your toaster's development interface.

>I tried using terminal and console to find it, but had no luck.
Look for Xcode then.

Narue 5,707 Bad Cop Team Colleague

>I can think of other possibilities
I can't[1]. As a teacher[2] I have no problem with students going above and beyond. The only good excuse for holding someone back when he's willing and capable of more is being embarrassed at not being able to keep up.

[1] Though I haven't given it much thought.
[2] Not as my primary occupation, of course. I actually work for a living. ;)

Narue 5,707 Bad Cop Team Colleague

>Without actually naming letter grade how will it know to save it as that?
Dude, are you really this helpless? When you print the letter grade to cout, print it to outFile too. I completely fail to see how that's not the most obvious solution in the world.

Narue 5,707 Bad Cop Team Colleague

>There's a page 2?
There's a raging debate between Christians and atheists about the existence of page 2.

Narue 5,707 Bad Cop Team Colleague

>How do I get the finalGrade and letter grade to
>save to the file when its not part of the vector?
Repeat the previous solution: merge the file output code into the loop that calculates the finalGrade and letter grade.

Narue 5,707 Bad Cop Team Colleague

>and what do you mean by MFC,C++/CLI or win32?
There are a bunch of ways to write a GUI program on Windows. Win32 is the most hardcore as it uses the Windows API directly. MFC is a C++ wrapper library around Win32, and C++/CLI is the C++ language with .NET support stapled on.

>it's a win32 project.....does that answer your question?
Yes, and in return I'll answer your question with a link: http://www.foosyerdoos.fsnet.co.uk/

Narue 5,707 Bad Cop Team Colleague

>but I can se that i won't get any assistence here
If you keep failing to ask a smart question, that's probably an accurate observation.

>I will go back to winging it on my own like I was.
That's actually the best way to learn. Unlike you, I didn't have the internet. I didn't have ready access to all kinds of wonderful resources or experts willing to help. I like to think that the experimenting I had to do at the time is why I'm that much better than I would be if I were spoonfed everything like most of the beginners these days.

>And I suggest you find out situations before you accuse
I call it like I see it. If you don't like that, change how it looks.

>If you notice I have not asked another question since
>Walt had responded becauses I have not gotten to it yet
Okay, then I suggest you follow your own advice. If you can't be helpful (in helping us help you), why are you even replying?

>Instead I am wasting time at my job replying to this junk
It seems we have something in common then. :D

Narue 5,707 Bad Cop Team Colleague

>All I need to know is how to compile my projects into an executable
Ctrl+Shift+B, or select "Build Solution" from the Build menu. This places the executable in the project path under "Debug", or "Release" folder.

>and how to make my program DO SOMETHING when someone interacts with a control
That's going to depend on exactly what you're doing. The answer changes if you're using C++/CLI, Win32, MFC, or something else entirely.

Narue 5,707 Bad Cop Team Colleague

What exactly are you looking for a tutorial on? A tutorial on Visual C++ Express Edition is somewhat of a vague request. You'd be better off buying a book that covers Visual Studio if you want a detailed tutorial on how to use the application.

Narue 5,707 Bad Cop Team Colleague

>im not too sure what GCC is, or even where to find it.
GCC standards for GNU Compiler Collection. Open a command line and type "g++ --version" to see if the C++ compiler is installed and easily accessible.

>I was sending just the c++ file over, not anything else. Would that be fine?
It might be fine. Or it might not. It really depends on whether or not your code uses non-portable features.

Narue 5,707 Bad Cop Team Colleague

I believe GCC comes with Mac OSX. There's the Xcode IDE as well, but I'm not sure what compiler it uses. Unless you're using one of those Mac Minis, you should already have a compiler installed and ready to go.

>If i compile it on the Mac, will it work on a PC?
No. When you compile your code, it turns it into binary executable instructions that only work on the system that it was compiled for. However, if you write portable C++, you can recompile the code on the PC and it will work.

helixkod commented: awesome +1
Narue 5,707 Bad Cop Team Colleague

>What does the operator *= mean?
It means you should check your C reference. Not many people like to explain things that are easily discovered by looking in a book or searching google. In this case, *= means multiply and assign using the left hand operand as the left operand of the multiplication. It's functionally equivalent to this:

prod = prod * k;
Narue 5,707 Bad Cop Team Colleague

>There is a Buit in function called getpass in conio.h
Maybe on your compiler's flavor of C++. Just because it works for you doesn't mean it works for everyone, so at the very least mention your compiler and OS.

Narue 5,707 Bad Cop Team Colleague

>and they *deeply* frown upon using things we eh 'shouldn't' know yet.
Probably because they don't want you to discover that your teachers, who should be experts on what they teach, are actually only about half a chapter ahead of you in learning C++. ;)

>Ultimately, I was clarifying the instructions for the other student
I know, but I feel the need to stick my finger in most of the pies on this forum.

Narue 5,707 Bad Cop Team Colleague

>OK thanks its runs fine for about 9 messages
>and then it just prints '''''''''''''''''''''''''''''''''''''''''''''
It should only print four messages, because that's how many you've defined. In fact, that's precisely what it does for me. Did you post the actual code you're using?

Narue 5,707 Bad Cop Team Colleague

>I do not appreciate the last two comments
Don't worry. Others will appreciate them. :)

>and I have not seen any code similar to mine
Here's one: http://www.daniweb.com/forums/thread95911.html

>If I were cheating I would at least pick one that is done
I don't know, I've seen some pretty lame attempts to cheat over the years.

>If you cannot be helpful then why are you even replying?
I also can't be helpful because you really haven't asked a proper question yet. You've mentioned a formula, said you're having trouble finishing the program, and posted the code. This suggests you want the work done for you, which we won't do. Walt pushed you in the right direction as much as he could without giving you code for the solution, so where's your updated attempt?

Narue 5,707 Bad Cop Team Colleague

>Lol is there a way to kill treads, this one just seems useless.
Give it a few days. Useless threads tend to drop down the list until they vanish in the limbo that is page 2.

Narue 5,707 Bad Cop Team Colleague

>what I should enter in the code where you have written the word factorial?
That's a function. You don't have to write a function, but you do have to loop from 1 to n and store the running product to calculate a factorial. Something like this is a translation of the formula into code:

int prod = 1;
int k = 1;

while ( k <= n )
  prod *= k;
Narue 5,707 Bad Cop Team Colleague

>If I had no confidence in mankind I would say it was some sort of
>homework assignment, but ofcourse that couldn't be the case, could it?
Since I've also been seeing lots of different people with identical code, it strikes me that either we're being attacked by a bunch of cheaters in the same class, or it's just that time of year again where teachers roll out the generic homework problems.

Narue 5,707 Bad Cop Team Colleague

>Well, the math formula reads, for example:
Actually, it's more like: n! = \displaystyle\prod_{k=1}^nk, but yours is close enough. However, knowing the formula doesn't mean you can write the code to implement it. Can you write a function that when given a value of n, produces the factorial of n? My point is that calculating n! is independent of what you do with the result. If you have a function that gives you n!, you can store it in an array just as easily as printing it:

int fac[10];
int i;

for ( i = 0; i < 10; i++ )
  fac[i] = factorial ( i );

for ( i = 0; i < 10; i++ )
  printf ( "%d\n", fac[i] );
Narue 5,707 Bad Cop Team Colleague

>I have searched anywhere and ask many people but I couldnt find out the way to do it.
Did you bother to ask the teacher that's forcing you to do it? Teachers tend not to ask you to do something that you have absolutely no knowledge of.

Narue 5,707 Bad Cop Team Colleague

A lot of people are writing base conversion programs lately.

Narue 5,707 Bad Cop Team Colleague

>Example: If i convert a base 10 number (255) to base 2 i get 11111110;
I repeat. My testing does not show this behavior. If I run your program (exactly as posted), type 255 for the value, 10 for the input base, and 2 for the output base, the result is printed as 11111111. Your example is faulty, or your description of how to reproduce the program is faulty.

Narue 5,707 Bad Cop Team Colleague

Be more specific.

Narue 5,707 Bad Cop Team Colleague

So...when doesn't it work? So far you've given me one example that doesn't work for you but does work for me, and one example that works for you. An example that doesn't work for both of us would expedite the troubleshooting process just a smidge.

Narue 5,707 Bad Cop Team Colleague

>hope this helps u gettin final code...
>I have a soln for solving armstrong numbers
I take solace in the fact that people who give away homework solutions usually come from the shallow end of the programmer pool. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

You're storing the factorials in an array, but that doesn't change how you calculate the value. Do you know how to calculate a factorial?

Narue 5,707 Bad Cop Team Colleague

>For example if i convert 255 from base 10 to base 2
>i am getting 11111110 instead of 11111111.
That particular example works fine for me. Though your code has some...interesting aspects.

Narue 5,707 Bad Cop Team Colleague

Or you can use stringstream and getline with ':' as the delimiter. That's generally easier to get right:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
  std::stringstream in ( "A:B:C" );
  std::string token;

  while ( std::getline ( in, token, ':' ) )
    std::cout<<"Split token: "<< token <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>I have a question on an assignment that has me confused.
And confused you should be, because the question is ambiguous.

>The question is how many times does the following loop execute?
The real question is what language is that? If it's pseudocode that follows C++ rules, the loop will execute 9 times because 1 TO 10 probably denotes a half-open range [1,10) where the 10 is excluded (as is the convention in C++). So the output would be:

1 2 3 4 5 6 7 8 9

But the loop could also follow classic BASIC-style looping rules where the range is fully inclusive [1,10], and the 10 isn't excluded. In that case the loop will execute 10 times, and the output would be:

1 2 3 4 5 6 7 8 9 10
Narue 5,707 Bad Cop Team Colleague

I'm seeing a lot of the same code from supposedly different people.

Narue 5,707 Bad Cop Team Colleague

...

Narue 5,707 Bad Cop Team Colleague

The problem is that you calculate the final grade when printing the table, but don't calculate the letter grade until the next loop. At that point the final grade is set to whatever the final grade of the last student was. You need to merge those two loops:

cout<<"Student    Exam 1     Exam 2     Homework     Final Exam     Final     Letter\n";
cout<<"Name       Grade      Grade      Average      Grade          Grade     Grade \n";
cout<<"-------    ------     ------     --------     ----------     -----     ------\n";

for ( i = 0; i < Grades; i++ ) {
  double finalGrade =
      0.20 * gTable[i].getExamOne()
    + 0.20 * gTable[i].getExamTwo()
    + 0.35 * gTable[i].getHomework()
    + 0.25 * gTable[i].getFinalExam();

  cout<< setw(7) << gTable[i].getName()
      << setw(10) << gTable[i].getExamOne()
      << setw(11) << gTable[i].getExamTwo()
      << setw(13) << gTable[i].getHomework()
      << setw(15) << gTable[i].getFinalExam()
      << setw(10) << finalGrade;

  if ( finalGrade > 90 )
    cout<< setw( 11 ) <<"A";   
  else if ( finalGrade > 80 )
    cout<< setw( 11 ) <<"B";   
  else if ( finalGrade > 70 )
    cout<< setw( 11 ) <<"C";    
  else if ( finalGrade > 59 )
    cout<< setw( 11 ) <<"D";   
  else
    cout<< setw( 11 ) <<"F"; 

  cout<<'\n'<<endl;
}