Narue 5,707 Bad Cop Team Colleague

>WOULD THIS HELP YOU INSTEAD OF ACCUSATIONS OF LAZYNESS??
Yes, as a matter of fact it does. By the way, do you realize that num1 is even if "num1 mod 2 = 0" and odd otherwise? You have your conditionals flip-flopped.

Narue 5,707 Bad Cop Team Colleague

Problem:

delete pointArray;

You allocate memory with new[], so you should release it with delete[]. Otherwise the behavior is undefined, and because the memory manager is usually very fragile, I wouldn't be surprised if that were your problem.

Narue 5,707 Bad Cop Team Colleague

I don't have any problems with it:

#include <iostream>
using namespace std;

int main()
{
  int number, dig1, dig2, dig3;
  char answer;

  do {
    cout << "Enter a Positive Integer from 0 to 999." << endl;
    cin >> number;
    while ((number < 0) || (number > 999))
    {
      cout << "Error: Negative Number or Number Greater than 999\n" << "Reenter that number and continue: \n";
      cin >> number;
    }

    dig1 = number / 100;
    dig2 = (number % 100 - number % 10) / 10;
    dig3 = number % 10;

    for ( int i = 0; i <= dig1; i++ ) {
      for ( int j = 0; j <= ( ( i == dig1 ) ? dig2 : 9 ); j++ ) {
        for ( int k = 0; k <= ( ( j == dig2 ) ? dig3 : 9 ); k++ )
          cout<< i << j << k <<endl;
      }
    }

    cout << "Do you want to continue (y/n)?\n";
    while ( cin.get ( answer ) && answer != '\n' )
      ;
    cin >> answer;
  } while (answer != 'n');

  cout << "goodbye!\n";

  return 0;
}

I even added a paranoia check to flush the input stream because that sounds like the problem you're having.

Narue 5,707 Bad Cop Team Colleague

The entire program should be nested in your do..while loop:

int main()
{
  int number, dig1, dig2, dig3;
  char answer;

  do {
    // Everything else in here
  } while ( answer != 'n' );
}

And you should consider allowing 'N' as well as 'n' to be more user friendly.

Narue 5,707 Bad Cop Team Colleague

>sorry but that didnt answer my ?
Clearly you weren't paying attention then. I said build what you need. If you expect to need more in the near future, build for that. As I don't know what you need, I can't possibly suggest any detailed equipment.

>thx for nuthin
Thanks for wasting my time.

Narue 5,707 Bad Cop Team Colleague

While I can sympathize with your situation, that still doesn't give you a free lunch card. Instead of coming here and trying to get someone else to do your work for you, go talk to your instructor and work something out. If they're incapable of making extraordinary exceptions then get another instructor.

Narue 5,707 Bad Cop Team Colleague

>I would be highly grateful if u give me the code
I'm sure you would. Do your own work, it's much more rewarding.

Narue 5,707 Bad Cop Team Colleague

>i just want to whether there is a replacement for getch() in C++.
There isn't a standard equivalent for getch in either C or C++.

>my friend said getch() is C function.
No, getch is a compiler extension. You can use it in either C or C++ if your compiler supports it, but for the most part you don't need to.

For what purpose were you intending to use getch? The most common by far is keeping a console window from closing when you run the program from a Windows IDE:

#include <conio.h>

int main()
{
  // Your program here

  getch();
}

That's not a recommended solution, and most experienced programmers will recommend that you use cin.get:

#include <iostream>

int main()
{
  // Your program here

  std::cin.get();
}
Narue 5,707 Bad Cop Team Colleague

Consider your boundary conditions. For each digit, unless the next outer loop is on the last iteration, you want to print 0 through 9. Otherwise you print 0 through the digit value. There isn't a very clean solution; you either use conditional expressions or long and redundant if sequences:

#include <iostream>

using namespace std;

int main()
{
  int a, b, c;
  int number;

  cout<<"Enter a number from 0 - 999: ";
  cin>> number;

  a = number / 100;
  b = (number % 100 - number % 10) / 10;
  c = number % 10;

  for ( int i = 0; i <= a; i++ ) {
    for ( int j = 0; j <= ( ( i == a ) ? b : 9 ); j++ ) {
      for ( int k = 0; k <= ( ( j == b ) ? c : 9 ); k++ )
        cout<< i << j << k <<endl;
    }
  }
}
Narue 5,707 Bad Cop Team Colleague

>Which language would be the best intial language to learn to get the most education as a programmer.
Python is a good start, so is Java.

>BCX is the way to learn it!
Funny, in all my years of programming with C++, this is the first time I've heard about BCX being the best way to learn the language. :rolleyes:

>BCX is written in BCX, just to show you the power!
Are they paying you to advertise for them or something? You have three posts so far and all of them plug BCX. I find it rather irritating that the only answer you have for every question is to use some basic interpreter that you like.

Narue 5,707 Bad Cop Team Colleague

Writing windows programs in C/C++ can be a bear for even experienced programmers. I started out with the DEV C++ package and quickly switched to BCX. This is a basic to C/C++ translator that uses simple basic code and allows inline asm and C code. If you are familiar with basic you can then look at the generated C/C++ code and learn a lot!

Write your basic code on the included editor and compile and run it from the editor or even fancier, from the included visual IDE. This program has excellent help files and a good selection of examples. You can look at the C code it produces. You can make win-gui or console programs. BCX is written in BCX!

The whole free package can be downloaded, including the PellesC compiler, from:

http://www.rjpcomputing.com/programming/bcx/

There is quite a nice group of users at
http://groups.yahoo.com/group/bcx/

:cool:

Would you please stop plugging your favorite BASIC-like wrapper? It's akin to this:

"I want to learn C++, where do I start?"
"Start by learning <so and so language completely different from C++>, it's a much better language and stuff."

Narue 5,707 Bad Cop Team Colleague

>How can I become good at VB6?
If you have common sense then you can be good at VB6. ;) But seriously, the only way to become proficient in any programming language is to read about it and use it. A lot.

Narue 5,707 Bad Cop Team Colleague

Any computer you buy or build will be obsolete in a few months. For the most part you won't need to upgrade at all for some time if you built the box to fit your needs in the first place. When it comes to upgrading, I consider slots and room for extra drives. Other than that you're talking about simple hardware replacement or hardwired equipment replacement and if you need to replace something hardwired then it's probably time to build a new system. :)

Narue 5,707 Bad Cop Team Colleague

>Can somebody help me write a perl script which totals the total amount of time that each user is using on the
>system, as well as the number of processes the user is using.
Pipe the result of a call to ps through your script and parse it, saving the items you want and calculating your totals. ps is different for every system, so do a man ps and when you have more information and you've actually made an attempt, come back and we can help more.

Narue 5,707 Bad Cop Team Colleague

>i guess but couldn't you just take like ten compilers and put em into one program.
Yes, but you would have the same problem if this were some kind of smart supercompiler. The problem is figuring out which language is being used and then calling the proper internal program. The only way that this could be done without serious coding effort on the part of the compiler writer would be to use a compilation switch:

$ sc -lang=C src.c
Compiling C code...

$ sc -lang=Pascal src.pas
Compiling Pascal code

$ sc -lang-Fortran90 src.f90
Compiling Fortran90 code

And so on. Anything else would introduce some form of common comment that specifies which compiler to call or requires the lexical analyzer to figure out from context what kind of language is being used. The former kills portability to other compilers and the latter would be a nightmare. The switch option is a good one, though the effort expended in developing this supercompiler wouldn't be worth the convenience gained by using a switch instead of a different compiler.

Narue 5,707 Bad Cop Team Colleague

>So far my attempts have not been successful
What attempts have you made? What are you having trouble with? Opening the file? Reading from the file? Calculating the distance? Or setting up the matrix and filling it properly?

Narue 5,707 Bad Cop Team Colleague

>but when i run it it does not do the conversion
You don't print the value of ch after the conversion.

>#include<iostream.h>
This is an old header that is no longer a part of the C++ language. Use <iostream> instead. You also need to consider namespaces, but for now simply adding using namespace std; will suffice.

>#include<conio.h>
This is a nonstandard header that is not supported by all compilers. Even those compilers that do support it offer different contents. That's definitely not conducive to robust and portable programs. Remove this and replace getch with cin.get.

>void main()
main does not, and never has, had a return type of void. The return type of main is int, and anything else is wrong.

>clrscr();
This is one of the functions that is pretty much only supported by Borland. Clearing the screeen when running a console program is almost always antisocial and it serves no useful purpose, so you shouldn't do it.

>{
There's no need to introduce a block before your first if statement. You can safely remove it because it's just clutter.

>if((ch>=65)&&(ch<=122))
Don't use the ASCII values for a test like this, they're not portable at all. A slightly better way would be:

if ( ch >= 'A' && ch <= 'z' )

But there are two distinct issues with this. The first is that between the upper case letters and the lower case letters in …

Killer_Typo commented: damn! a great reply i must say +6
Narue 5,707 Bad Cop Team Colleague

>What, if we want to pass more than one value through one argument of a function, here is place where pointers comes.
That's a pretty roundabout way of saying that you can pass an array as a function argument. :rolleyes:

main()
{
int a=23,*add_of_a;
add_of_a=&a;
show_value(add_of_a);
}

There's really no need to declare a pointer just for the purpose of passing it to a function. This works just as well:

int main ( void )
{
  int a = 23;

  show_value ( &a );
}

But the example is silly as there's no point in passing a as a pointer. The two primary reasons for passing a pointer to T is so that the original object of T can be changed within the function, which is a great boon for modularization, or if T is so large that passing it by value would end up copying too much data, in which case a pointer to T is smaller and more efficient. Your example has neither of those attributes.

main()
{

char STRING[]="BOSS";
char *add_of_first_element_of_arr;
add_of_first_element_of_arr=&STRING[0];

show_string(add_of_first_element_of_arr);
}

Once again, there's no point in saving the address of the first element of the array in a pointer. This conversion is done implicitly anytime an array name is used in value context, such as when it is the argument to a function:

int main ( void )
{
  char string[] = "BOSS";

  show_string ( string );
}

Because the array name is converted to a pointer, there's …

Narue 5,707 Bad Cop Team Colleague

>Tell me how to create a C++ program using ADT to represent the (X) player in a tac tic toe game.
What have you done by yourself so far?

Narue 5,707 Bad Cop Team Colleague

>Hee hee. Well, I'm both lazy AND arrogant.
:D

>This is new to me... could you expand on this please?
I don't have my copy of the standard available at the moment, but if I remember it right, 1E-9 is the implementation limit imposed by the committee. IEEE expands this to something like 2.220...E-16. The details are lost to me right now though, sorry. :o

Narue 5,707 Bad Cop Team Colleague

>any criticisms for this?
You code looks a lot like C but you use the single line comment style without mentioning C99. ;) Other than that I have no criticisms except for the use of epsilon instead of DBL_EPSILON. Your value of 1E-10 exceeds the standard minimum requirement by 1 IIRC, so it isn't technically portable.

Narue 5,707 Bad Cop Team Colleague

>What I underestimated ( quite a lot I must admit ) is the level of recoursion that occurs in computing the factorial of a number.
Factorials grow incredibly fast. Whenever you have a sequence like that, you need to be aware of your limits. :)

Narue 5,707 Bad Cop Team Colleague

>sorry for beeing that stupid.
I wouldn't say stupid because that would be mean without being constructive. But it is always a good idea to know what the limitations of your system are, and even better the limitations placed on you by the language standard. Then you can more easily determine if you exceed those limitations using common sense. It seems to me that the problem was just a lack of information concerning the size of a double. The fact that your implementation didn't throw a floating-point exception but instead did something nice didn't help at all. It just hid the fact that your code was doing something it wasn't supposed to do.

Narue 5,707 Bad Cop Team Colleague

>#include <getch>
If your compiler supports getch, it will most likely be in conio.h. But because getch is not a standard function, cin.get() is recommended instead:

#include <iostream>

using namespace std;
// Any other headers you need

int main()
{
  // Your program here

  cin.get();
}

This will work except in cases where cin>> leaves a newline in the stream. This occurs more often than you might think, so it would be a good idea to flush the stream first and then call get:

#include <iostream>
#include <limits>

using namespace std;
// Any other headers you need

int main()
{
  // Your program here

  cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  cin.get();
}

There are other ways to flush the input stream, most of them are nonstandard. One nifty standard way is to use rdbuf:

cin.ignore ( cin.rdbuf()->in_avail() );

Though whether that's better than numeric_limits is debatable. And there's always the brute force loop:

char c;

while ( cin.get ( c ) && c != '\n' )
  ;
Narue 5,707 Bad Cop Team Colleague

>explain why I did not recognize the mistake in the first place.
I can understand not knowing that floating-point overflow is undefined, but it should be immediately obvious that a double couldn't possibly hold a factorial anywhere close to 3999!.

>but code snippets should be seen as starting points or suggestions, not finished product.
I agree. Unfortunately, those that we help aren't quite so forgiving. They have a tendency to see code we post as set in stone answers that "must" be correct. As such, rather than end up teaching bad habits, we should try to be as accurate and correct as possible.

>None of the snippets or suggestions I make are ones I've built and tested
That's your choice. I prefer to only post code that I've made sure works as expected. However, you should mention that your code wasn't tested and you only "hope" that it works.

>only ideas to get the thread-opener's juices flowing.
That's fine, I do it myself. But I make sure that the example is still correct so that the juices aren't sour.

>Some of my posts have been nit picked for syntax or stuff that misses the bigger picture
That's a rather narrow view I think. It seems to me that it was you who missed the bigger picture. If you don't want to be nitpicked on syntax then give pseudocode. It still conveys the idea and avoids people like me who think that …

Narue 5,707 Bad Cop Team Colleague

>I want to learn Java Servlets, Oracle 8i & Linux Administration.
Cool.

>I have tried the Sun's site for Java but I can not follow it.
I assume you started here and then moved on to here? If that's too much then you really should get a good beginner's book. Reviews can be found here.

As for Linux administration, you need to start by getting Linux on your machine. :) The easiest way to get your feet wet is through a live CD distribution. These can be found all over the place, but the one that I would recommend first is Knoppix.

When you want to go all the way and actually partition your hard disk drive with Linux, a good starter distribution is Mandrake simply because the installation procedure is dead easy.

As for Oracle, reading as much as you can find and working with the software is the best thing you can do.

>You can, I think, code Java on Linux.
Yes.

Narue 5,707 Bad Cop Team Colleague

Download the latest AGP filter driver from NVIDIA and install it, then try again.

Narue 5,707 Bad Cop Team Colleague

>It would just be cool if there was some super compiler.
Yes, it would. But the lexical analyzer would be a bitch to write.

Narue 5,707 Bad Cop Team Colleague

>but with my compiler the result is still correct
That's nice, but your code is still wrong even if the compiler that you use happens to interpret "undefined" as something intelligent.

Narue 5,707 Bad Cop Team Colleague

>What's the HARDEST program you've written?
Operating system. Well, technically I didn't write it, but I did patch it into behaving and that consisted of replacing about 90% of the code.

Narue 5,707 Bad Cop Team Colleague

>This is due tomorrow
Bummer.

>and i am absoltuly lost
Try paying attention in class.

>can anyone help with some examples or point in the right direction
Sure, post your attempt and we'll help. Nobody is going to do your homework for you. Especially since it seems like you're terribly lazy. I wrote this program in about 30 seconds, including the time it took to create, write and save the source file and the time to compile it.

Narue 5,707 Bad Cop Team Colleague

>what is the best compiler
What's the best pizza topping? Try again.

>what is the best compiler out there that you can use for a variety of languages. Like is their a compiler that can compile c++, the basics, java, etc.
Better. No such compiler exists. The closest you will get is a C++ compiler that can also handle C. Try again.

>I am just looking for a good compiler that is free and if possible can compile more than one prog. lang.
Now I know what you're looking for. Here is your best bet.

Narue 5,707 Bad Cop Team Colleague

[fix]
I use a nested while lo0p because it's much easier for me
[/fix]

Not everyone feels the same way as you, so don't push your opinions on anyone unless you state explicitly that they're opinions first.

>Doing this process is not hard at all.
No, it isn't.

>I commented the code to help you understand.
Too bad the code does something completely different from the OP's problem. If you had read the code posted originally then you would have seen that the problem was not this:

#include <iostream>

int main()
{
  for ( int lines = 0; lines < 5; lines++ ) {
    for ( int stars = 0; stars <= lines; stars++ )
      std::cout.put ( '*' );
    std::cout<<std::endl;
  }
}

But rather this (code enhanced to avoid plagiarism):

#include <iostream>
#include <iomanip>

int main()
{
  const int lines = 5;

  for ( int i = 1; i <= lines; i++ ) {
    std::cout<< std::setfill ( ' ' ) << std::setw ( lines - i ) <<"";
    std::cout<< std::setfill ( '*' ) << std::setw ( i ) <<""<<std::endl;
  }
}

An assignment that would most likely give way to this:

#include <iostream>
#include <iomanip>

int main()
{
  const int lines = 5;

  for ( int i = 1; i <= lines; i++ ) {
    std::cout<< std::setfill ( ' ' ) << std::setw ( lines - i ) <<"";
    std::cout<< std::setfill ( '*' ) << std::setw ( i * 2 …
Narue 5,707 Bad Cop Team Colleague

>for ( int i = 1; i < 4000; i++ ) {
>e += 1.0 / fakt(i);
Wow, I'm impressed if you can fit up to 3999! into a double. I just get undefined behavior when the limit of double is exceeded. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>but i cannot make good quick sort algorithm
There are three immediate improvements to the basic algorithm. First, you want to come up with a partitioning scheme that finds a pivot point as close to the median as possible so that the recursive branching is balanced. Second, you want to avoid recursing for small sets but adding a cutoff when the partitions are small. Lastly, you can partition three or more ways and then work out an elegant handling of duplicate values.

The first improvement is usually made by either choosing a random pivot as cscgal did, or by choosing three values in the partition and using the median of those three as the pivot. You could use more than three, but that means extra work and extra time, just like calling a random number generator. Both are undesirable in an efficient sorting routine. The second improvement is usually made by setting a cutoff in the recursive path and then using insertion sort to finalize the routine. Because insertion sort is zippy on almost sorted files, this increases quicksort's speed.

The last improvement is complicated and I don't see it much, so unless large amounts of duplicate values are a problem for you, you can ignore it. :)

The most obvious problem with your code aside from the syntax errors in spilt is that you mix prototypes with old style function definitions. This is a huge no-no. Let K&R C die and use proper ISO C …

Narue 5,707 Bad Cop Team Colleague

Ah, yet another mindless Microsoft hater who clearly isn't aware of the issues and thinks that calling Bill Gates evil will say everything that needs to be said. Blanket statements like that just serve to indicate your idiocy and lack of awareness. But to answer the request, I have nothing against Bill Gates. He's an intelligent man and has done very well for himself. I even met him once, he's also very friendly and certainly not what I would call evil after a few minutes of chatting.

Narue 5,707 Bad Cop Team Colleague

i have a homework assignment using the calculatecharges function...we use C++...but my book doesnt have the actual usage for it in it. we have to calculate parking charges for cars in a parking garage...could someone please explain exactly how you would use this function to do that ...
thank you

Let me get my crystal ball so that I can divine the everything you need. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>i tried iostream without .h...and i get even more fatal errors...i guess i should reload?
No, you should consider namespaces. An easy fix is to say using namespace std; after you include all of your headers. This isn't the best fix, but it is quick and usually works if you don't have other errors.

Narue 5,707 Bad Cop Team Colleague

I'm having a problem with my sorting algorithm.
before I made quick sort which used insertion sort, but I don't want to use this insertion sort. I want to use recursive algorithm.

Also, I want to get new idea, so If you know any quick sort algorithm, reply for me.Please~ :rolleyes:

Good quicksort implementations use insertion sort as the final step. Or do you mean you wrote an insertion sort algorithm and called it quicksort? :rolleyes: The basic recursive algorithm is simple:

void quicksort ( type a, int l, int r )
{
  int i;

  if ( r <= l )
    return;

  i = partition ( a, l, r );

  quicksort ( a, l, i - 1 );
  quicksort ( a, i + 1, r );
}

Because your post was appropriately vague, I'll do the same and not include the implementation of partition. ;)

Narue 5,707 Bad Cop Team Colleague

>If you have some solution then kindly help.
Get a newer compiler. Your problem is that you're trying to use modern C++ with an ancient compiler that doesn't know what modern C++ is.

>then which compiler should i use and from where i can get one?
Dev-C++ is a good one. Search google for Bloodshed's web site where you can download it for free.

Narue 5,707 Bad Cop Team Colleague

>plz explain me with syntax "how to pass pointer to a function or pointers to a function "
For each level of indirection in the function argument list, add an asterisk. If the argument isn't already a pointer of the same type as the argument list, dereference or add & as necessary.

>plz tell me if there any big tutorial which can solve my problem providing a deep knowledge about it
http://pweb.netcom.com/~tjensen/ptr/pointers.htm

>what is incorrect int following program.
A lot, actually. First and foremost you forgot to include stdlib.h, an error that the casting of malloc's return value hid and is a good example of why you don't cast the return of malloc. Second, you don't provide a prototype for func even though the definition is after the first call. a is a pointer to a pointer to int yet func expects a pointer to int so that's a type mismatch, you test for null pointers after dereferencing the allocated memory so the damage would already have been done by that point. All in all, the code could be improved greatly, but I'll leave that to you after you look at the link I gave you.

Narue 5,707 Bad Cop Team Colleague

Self-rebooting problems that I have seen were usually something to do with the power source. How far into the POST have you gotten?

Narue 5,707 Bad Cop Team Colleague

1) sec and s refer to the same object, thus they have the same value. Subtracting 5 from 5 is 0. Replace 5 by x and you have the basis of what you're doing, x - x == 0.

2) It returns the time difference, but Sec remains the same because you don't modify it. Because you don't do anything with the return value, this isn't obvious.

Narue 5,707 Bad Cop Team Colleague

>pliz clarify this:is C++ dying or what coz this is the lang. am specialising in.
No, C++ is not dying and anyone who says it is is very confused.

Narue 5,707 Bad Cop Team Colleague

It depends on how much crap you intend to hook up to your computer. 250 is the bare minimum, but for a powerhouse you'll be looking at 350 to 400+.

Narue 5,707 Bad Cop Team Colleague

AMD used to be inferior to Intel, but not so anymore. I would say that they're evenly matched these days. Of course, I don't overclock, so I can't help you there.

Narue 5,707 Bad Cop Team Colleague

Don't worry as much about the style as the form factor. That's what effects your choice of components. For example, if you want one of those cute mini-ATX form factor cases then your motherboard choice is more limited than if you chose a mini-tower or a tower.

Narue 5,707 Bad Cop Team Colleague

Just about any store that sells computer parts will offer several different form factors. Or you could search the web for computer cases to see what your options are. As for specific brands, I'm partial to Lian Li.

Narue 5,707 Bad Cop Team Colleague

>what kind of processor, mother board ect. do i need to get.
It really depends. The processor and motherboard should be made for each other, such as an AMD motherboard with an AMD CPU. The motherboard depends on the case that you want. If you get a small case then your motherboard choices are limited but if you get a standard size case then most motherboards will fit it. So start looking at cases to get a good idea of sizing and type issues, then look into what you want to do with the computer. From there you can work out power and cooling issues and you'll have a much clearer understanding of what hardware you need.

Most importantly, make sure everything is compatible. Also keep in mind that high performance hardware tends to have costly requirements (such as memory). If you're on a tight budget then the latest and greatest may not be best for you.

Narue 5,707 Bad Cop Team Colleague

>how do you get to calculae a power. is it pow(...)
Yes, that's one way.