Narue 5,707 Bad Cop Team Colleague

kbhit typically takes no arguments and returns either 0 if there are no keyboard events in the queue and non-zero if there are. You might use it like this:

#include <stdio.h>
#include <conio.h>

int main ( void )
{
  int last_key;

  while ( !kbhit() )
    ; /* Do nothing */

  last_key = getch();
  cprintf ( "Last key pressed: %c\n", last_key );

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

>Yes, you can call other functions from inside a bool.
Then you're not using the proper terminology. A bool is true or false, that's it. There's no way to call a function from inside a value. I suspect that what you're thinking of is calling a function in a conditional test:

#include <iostream>

using namespace std;

bool f()
{
  // Do something and return true or false
}

int main()
{
  if ( f() )
    cout<<"f() was true"<<endl;
}

or calling a function that returns bool from another function that returns bool:

#include <iostream>

using namespace std;

bool f1()
{
  // Do something and return true or false
}

bool f2()
{
  if ( f1() && something else )
    return true;
  else
    return false;
}

int main()
{
  if ( f() )
    cout<<"f() was true"<<endl;
}

>but I would appreciate some respect if you respond to me!
I do respect you for various reasons, but I don't respect your complete lack of an attempt to express yourself in a way that is conducive to getting help. I'm not going to guess what you want simply because you don't know how to ask the question in a way that we can understand. So let's go over this one more time.

A bool is a data type with two values. Functions can return bool, expressions can result in bool, but the only thing that can be inside bool is true or false that map to non-zero and …

Narue 5,707 Bad Cop Team Colleague

Okay, first you need to decide how to represent the stack. A stack is an abstraction that can be represented a number of ways, the most common being either an array or a linked list.

>please tell me how to enter no's in a stack
This would be the push operation. It's very simple using either an array or a linked list. Simply add the number to the end of the array and increment the top index for an array based implementation, or insert a new node at the front of the list for a list based implementation.

>and how to check for overflow & underflow using push & pop function.
For an array based implementation, if the top index is 0 then the stack is empty, if the top index is N then the stack is full. For a list based implementation, if the head node is nil then the list is empty and so is the stack. There is no overflow in a list based implementation except when you run out of some critical resource in creating nodes.

Narue 5,707 Bad Cop Team Colleague

>It's just a problem that we discussed with some professor and he asked if we can solve it or not.
That sounds a lot like homework to me. Just because you aren't being graded on it doesn't mean that begging for the answer is a valid solution.

>I tried my best but I couldn't
What did you try? Trying your best is a very vague measure. In fact, I've helped people who thought that trying their best was posting a request for the complete solution on a forum like this one. I've been doing this for a while, and as you can imagine, it gets tiresome seeing the same thing over and over:

Hello, here is my problem: <Insert problem here, usually a direct copy of the homework assignment or similar>

I tried really really really hard to solve it, but I couldn't come up with anything. <Notice the lack of detail about what was tried>

So since I can't do it, why don't you do it for me? Then I can change it around a lot to make it look like something I'm capable of so I can palm it off as my work.

Thanks in advance for being a dumbass and hurting me down the road by giving me something that I should figure out on my own.

>if you donno how to solve or u don wanna solve it
I do, and I did. If you took the stick out of your ass …

Narue 5,707 Bad Cop Team Colleague

>How about I have....
I see...

>Im new...
That's no excuse for being lazy.

>There are sooo many implementations of stuff out there
So go grab one and play with it! Is tinkering such a foreign concept to you people these days? You know, when I started programming we had to figure it all out on our own. The web wasn't the treasure trove of solved problems that it is now. In fact, I'm shocked and amazed that anyone needs to ask questions around here because it's so EASY to get started with a search. Hell, most of the time it's not even a start that you get, but the entire solution!

Anyway, here's another full implementation since you seem incapable of finding one on your own. Insertion sort is one of the more useful quadratic sorts, and it's a wonderful introduction into sorting without resorting to bubble sort:

#include <stdio.h>
#include <stdlib.h>

void insertion_sort ( int a[], int left, int right )
{
  int i, j;

  for ( i = 1; i < right; i++ ) {
    int save = a[i];

    for ( j = i - 1; j >= left && a[j] > save; j-- )
      a[j + 1] = a[j];

    a[j + 1] = save;
  }
}

int main ( void )
{
  int a[15];
  int i;

  for ( i = 0; i < 15; i++ )
    a[i] = (int)( 1.0 * rand() / RAND_MAX * 100 );

  for ( …
Narue 5,707 Bad Cop Team Colleague

>x(!)^n
>Factorial(pow(current,power))
Either your mathematical notation is wrong, or your code is. And the parens are mildly confusing, can you be more specific as to their purpose?

Narue 5,707 Bad Cop Team Colleague

>There is no need to take Naru's comments too serious.
Anyone who takes me serious here is lazy, stupid, and foolish. :D;)

Narue 5,707 Bad Cop Team Colleague

>I need a getch(); which aint actually waiting for the input itself or in other
>words, a function to simply return the value of the last pressed key.
Try using a combination of kbhit and getch. I'll assume that you have those on your implementation because you mentioned them.

>How can I make use of keys like the arrows keys or the f-keys under Dos
Searching is easy and lucrative, you should try it sometime.

Narue 5,707 Bad Cop Team Colleague

>Could you help me with this particular program
Your question asks for help yet the rest of your post implies that you expect us to do it all for you. Try again.

Narue 5,707 Bad Cop Team Colleague

I would be more worried about creating a button in the first place. No detail == no answer.

Narue 5,707 Bad Cop Team Colleague

><iomanip.h> is a (deprected) C++ header
Nope, iostream.h was removed completely. Deprecated presumes that the header is still valid C++, but not recommented as it might be removed in future revisions. As it is, iostream.h is nonstandard and should be treated as such.

Narue 5,707 Bad Cop Team Colleague

>I can't get anything to work on the hybrid version. Can anyone help, provide tips or pointers?
Oddly enough, I posted the full implementation for an optimized quicksort in the code snippets on this site. One of the optimizations is terminating recursion on small subfiles and then calling insertion sort on the "almost" sorted file. An alternative is to use insertion sort during recursion, but that typically has less desirable properties than waiting until after the recursive steps. Because you're testing performance, it couldn't hurt to implement both and see what you get. :)

I also give examples of two other improvements to the basic algorithm, one common and the other not so common because it's rather difficult and not well known.

>to recurse to the point where insertion sort is more optimal than quicksort
This really needs to be tweaked by the implementor, but a cutoff somewhere between 5 and 25 will work nicely in general and that's where you usually find yourself setting it.

Narue 5,707 Bad Cop Team Colleague

>It may help if you search for bubble sorting. It's a famous algorithm for sorting all types of data.
Famous for being the canonical example of a bad algorithm, sure. Please don't teach it because there are no reasons to favor bubble sort over any of the other quadratic sorts.

>LOL ...........
:rolleyes:

>Struggling for survival here
It looks more like you're waiting for us to do your research for you and hand you everything you need to do the project. I offer you six letters that will change your life: G.O.O.G.L.E.

Narue 5,707 Bad Cop Team Colleague

>I think your'e confused.
For some reason I kept typing return when I meant compute. I have no excuse.

And please use the correct terminology, I hate to be corrected by someone who says radiants when they mean radians. It just makes me feel even dumber to be corrected by someone totally clueless.

Narue 5,707 Bad Cop Team Colleague

>I can't figure out a code to sort the total in accending order
You aren't trying very hard then, are you? Sorting is a very well known classical problem in computer science. If you search for anything even related to sorting on google you'll get millions of hits.

Narue 5,707 Bad Cop Team Colleague

>>Can someone please help me with a statement to calculate the median when the array is even.
>Take the median of the two middle items: a and a.
Wouldn't that be the mean of a and a[size / 2 - 1]?

Feh, you're no fun. ;)

Narue 5,707 Bad Cop Team Colleague

>I think it's a wee bit unfair
Life isn't fair. Deal.

>the fact that some studentd expect other people to solve their home work doesn't mean that all the students are the same
I don't recall ever saying that they were. But the majority that come crying to us for help are, which is why I savor the very rare student that actually cares about learning and has an honest problem and a good question about it.

Narue 5,707 Bad Cop Team Colleague

>pls solve me the following problem.
No, do your own freaking homework you lazy bobo.

Narue 5,707 Bad Cop Team Colleague

>I need the shortest first
The shortest name? What if they're all the same length? There's a function that you can use in the string.h header called strcmp, it returns <0, 0, or >0 depending on the relation of the first and second arguments. Working out how to print in ascending order from there is simple.

Narue 5,707 Bad Cop Team Colleague

>Can someone please help me with a statement to calculate the median when the array is even.
Take the median of the two middle items: a and a.

Narue 5,707 Bad Cop Team Colleague

>Is it possible?
Yes, by patching the libraries and executables you gave to the client, but this is not a topical question, so please direct your query elsewhere unless you have a specific problem concerning C or C++.

Narue 5,707 Bad Cop Team Colleague

Are you so impatient as to insult everyone on this board by starting a new thread when nobody answers your followup question on the other thread? It hasn't been that long.

>I need to add a name in each of my arrays.
You're thinking about the problem wrong. You need to attach a name to the use of each array.

>myValue[0][0] = Greg;
>myValue[0][1] = 53,000;
This will never work in a language like C++. How about something more like this:

#include <string.h>

...

char name[3][20];
int myValue[3][3];

...

strcpy ( name[0], "Greg" );
myValue[0][0] = 53,000;
myValue[0][1] = 5;
myValue[0][2] = 1;
Narue 5,707 Bad Cop Team Colleague

>Can anyone help?
What have you tried so far? Do you know how to get form fields and accept them as CGI input for your script? Do you know what platform your host server is using so that you can call the correct mailing program the correct way?

Narue 5,707 Bad Cop Team Colleague

>because I couldn't figure out how to use the switch
The switch is fine, it's the illegal nested function that's your problem. Functions cannot be defined within other functions.

Narue 5,707 Bad Cop Team Colleague

>whats the reason for defining s1 and s2 as constants?
Does the function modify either s1 or s2? No, so why not let the compiler tell you if you make a mistake and try to change either of them? It's surprisingly easy to type = instead of !=, you know. Why make programming harder than it already is? Are you a masochist? ;)

Narue 5,707 Bad Cop Team Colleague

>the link is (#include <math.h>) ok
math.h is the header that contains declarations. Did you link to the math library that has object code as I gave an example for? If not then the next question is moot because your code will never compile.

>somebody says the output is in radiants while other say in decimal numbers
...You're confused. There are two potential representations for the value returned by sin, radians and degrees. sin as defined by the standard returns radians and it's trivial to convert radians to degrees, just multiply by 180 / pi. As for decimal numbers, I assume you mean floating-point, which is the type that sin returns.

Narue 5,707 Bad Cop Team Colleague

>but I need to call a function or another bool from inside a bool!
Work on your terminology first, because I have no clue what you want. Let's get this straight, bool is a type. bool has two values: true and false. You don't call squat from inside a bool because all it does is represent true or false, nothing else. You can have functions that return bool, or statements that result in bool, but they're not bool and shouldn't be referred to as such if you want to have meaningful conversation with intelligent parties.

Narue 5,707 Bad Cop Team Colleague

>I can't open the program. program doesn't work.
What program? Is this a reply to a thread and you just hit the wrong button?

>If you have any different ideas please contact me.
I have an idea, be more specific about your problem. But this is the only way I'll contact you because I don't care about your problem. You're just lucky that I'm answering threads in a spare moment.

Narue 5,707 Bad Cop Team Colleague

>could any one give me the code for this...
No, give it an honest try first, then try to cheat.

Narue 5,707 Bad Cop Team Colleague

>warning: no newline at end of file
Go to the end of the file and hit enter. Save and recompile.

>undefined reference to `sin'
Did you link to the math library?

gcc src.c -lm
Narue 5,707 Bad Cop Team Colleague

How do you know that it doesn't work if you don't use the return value? :rolleyes: Try something like this:

int begins ( const char s1[], const char s2[] )
{
  int i;

  for ( i = 0; s1[i] != '\0'; i++ ) {
    if ( s1[i] != s2[i] )
      return 0;
  }

  return 1;
}

Of course, now (as if you didn't before) you have an issue where s2 might be shorter than s1, I'll leave that fix to you.

Narue 5,707 Bad Cop Team Colleague

>No ONE can answer this?!!
You can't answer it, why should you expect anyone else to? Anyway, have you tried something along these lines?

T ::= T, K, T |
      nil

Or were you just waiting on someone else to do your research for you?

Narue 5,707 Bad Cop Team Colleague

Show us the class, I'm tired of playing this guessing game.

Narue 5,707 Bad Cop Team Colleague

>this.diff;
This doesn't do very much, maybe you should assign diff to it:

public Clock ( int hours, boolean isTicking, Integer diff )
{
  this.hours = hours;
  this.isTicking = isTicking;
  this.diff = diff;
}

Though that might not be such a good idea because Integer is an object reference, and this.diff would then be a reference to the object that diff refers to. You might consider cloning diff and assigning it to this.diff:

public Clock ( int hours, boolean isTicking, Integer diff )
{
  this.hours = hours;
  this.isTicking = isTicking;
  this.diff = diff.clone();
}
Narue 5,707 Bad Cop Team Colleague

>what else do i nned to change
It depends. Does it work when you paste it into your HTML file? I don't see anything wrong, so the only issue would be whether the link is valid or not.

dlh6213 commented: Thanks for helping my son with this; he's surpassing me in some areas! -- dlh +1
Narue 5,707 Bad Cop Team Colleague

>I know this will upset Narue
I don't have a problem if it's on-topic and related to the original question. :)

Narue 5,707 Bad Cop Team Colleague

Everywhere my code uses on.gif, you use down.gif and everywhere I used off.gif, you use up.gif. It's a simple substitution, then where I have "link", change it to "http://www.whateveryoururlis.com". The a href tag creates a hyperlink, like the following:

www.google.com

The img src tag displays an image and by nesting it in an a href tag, you create an image hyperlink where the link is an image rather than simple text.

Narue 5,707 Bad Cop Team Colleague

>none deal w/ messages
You aren't up to a point where messages are meaningful, your instructor is just using weird terminology to confuse you.

Because the problem suggests that officeAC is a variable that already exists, you can simply do this:

officeAC = new AirConditioner();

officeAC.turnOn();

>P.S. I have 2 books
p.s. I don't know of any Java book that doesn't cover basic constructor usage.

Narue 5,707 Bad Cop Team Colleague

It depends on the language used. For C++ you will generally use a text editor to write the code, save it with a special file extension such as .cpp. Then you'll run it through another program called a compiler that will translate the code into machine instructions and spit out an executable file.

On the other hand, VB code is very much integrated with it's own development environment. That's what makes writing VB so fast and easy, most of the drudgery is abstracted away into a few mouse clicks.

Narue 5,707 Bad Cop Team Colleague

>i prefer to just make my site in some sort of pagebuilder
Even easier. A page builder should have a function that lets you insert a rollover without even touching the code. Unless it's a super cheap builder provided by a free web host. ;) In that case you'll pretty much have to get your hands a little dirty.

>html code(or is it javascript)
It's both. a href and img src are HTML tags. The onMouseOver and onMouseOut events and properties are Javascript.

Narue 5,707 Bad Cop Team Colleague

>But I cant see where!
That's because you're doing so much that could cause it! An access violation is when you access memory outside of your address space. This is most often caused by writing to uninitialized memory (through a pointer) or by overrunning the boundaries of an array (either statically or dynamically allocated).

If you don't have a good debugger, litter your code with debug statements that tell you exactly what the limits of your arrays are and what the values of the indices you're using are. Then print the value of your pointers to ensure that they're pointed where you want them to be, and pay careful attention to your dynamic allocation. An off-by-one error there will usually show up when the memory is reclaimed. The memory manager is a fragile beast and you must be especially careful.

Narue 5,707 Bad Cop Team Colleague

>would u plz help me to learn graphics in C++
C++ doesn't support graphics natively. You need to choose a graphical library or API before someone can help you with it. A few good starters are Allegro, Qt, and SDL. A quick google search will give you reams of information on them.

Narue 5,707 Bad Cop Team Colleague

>Thank you so much!
Anytime. :)

Narue 5,707 Bad Cop Team Colleague

>I am hard on spending money
I feel your pain.

>how positive are you about these 2 books?
Well, I don't have a beginner's perspective, but the "for dummies" book is most certainly not a good introduction to C++, whether it's easy to follow or not. Accelerated C++ as I said is my usual recommendation because I can find no faults with it. Whether it works for you as a text, I don't know because as I said I can't look at books from a beginner's perspective anymore. However, from the standpoint of someone experienced with the language, Accelerated C++ is top notch and I can't see it being too difficult for a novice.

>how much would a copy of Visual C++ cost
At least $100US for the standard edition, more for the more powerful editions.

>how much would the Accelerated C++ book be?
The average for a programming book is $35US-$60US. My copy says $33.95US on the back.

>And what in heck can I do with this C++ for Dummies book
They make nice paperweights. ;)

In the end, it's your choice which book you get. But if I had my way you would only get good books to ease your learning of C++. One book will never be enough to learn the entire language, so if you're serious you'll be getting more. I have well over 300 programming texts on various topics, and my C and C++ library …

Narue 5,707 Bad Cop Team Colleague

>cout << "loop.\n"; does this play any role or its just an output -> "n"
I assume you mean \n. It's an escape character that tells cout to print a newline.

>Why did we have to equal the min and max to number...? Which is 0?
min and max denote the smallest and largest value encountered, respectively. Because at this point the only value encountered was number, both min and max must be that value.

>Are max and min are reserved word for C++.
Yes and no. The rules are a bit tricky, but in this case there's no problem.

Narue 5,707 Bad Cop Team Colleague

Why not just change getNext like so:

// Untested
bool getNext ( LIST& list, int& dataOut )
{
  if ( list.pos == NULL )
    return false;

  dataOut = list.pos->data;
  list.pos = list.pos->link;

  return true;
}

Then you can write printList like so:

// Untested
void printList ( LIST& list )
{
  int data;

  list.pos = list.head;

  while ( getNext ( list, data ) )
    cout<< data <<endl;
}

The biggest confusion is how getNext does so much. It would be better to separate this function into getData and getNext so that the user of the list knows what to expect. And the concept of a list having its own internal iterator causes more problems than if you gave the user control of iterators.

Narue 5,707 Bad Cop Team Colleague

>so I'll have to annouy a few of you experienced users with a stupid question now and then.
There are no stupid questions, only poorly thought out ones.

>Any suggestions?
It depends on your distribution. I have a Unix background and a lot of that slides into Linux nicely. So, Unix Power Tools and Unix Systems Programming (and of course anything coming from this general area :D) are a great help. For distribution specific features, you'll need to get a book for your flavor of Linux. You should be able to find some reviews at www.accu.org.

Narue 5,707 Bad Cop Team Colleague

This is a problem with several parts. What you want to do is work on each part separately. First, work out a way to read words:

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

string get_word ( ifstream& in );

int main()
{
  ifstream in ( "input.txt" );

  if ( !in ) {
    cerr<<"Error opening input file"<<endl;
    return EXIT_FAILURE;
  }

  for ( ; ; ) {
    string s = get_word ( in );

    if ( in.eof() && s.empty() )
      break;

    if ( !s.empty() )
      cout<< s <<endl;
  }

  return EXIT_SUCCESS;
}

string get_word ( ifstream& in )
{
  char ch;
  string s;

  while ( in.get ( ch ) ) {
    if ( ch == ' ' || ch == ',' || ch == '.' || ch == '\n' )
      break;

    s.push_back ( ch );
  }

  return s;
}

Okay, it's ugly but it works. From there we can calculate the number of words and number of letters in the file since we know that the words we read are what we want:

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

string get_word ( ifstream& in );

int main()
{
  ifstream in ( "input.txt" );

  if ( !in ) {
    cerr<<"Error opening input file"<<endl;
    return EXIT_FAILURE;
  }

  unsigned int words ( 0 );
  unsigned int letters ( 0 );

  for ( ; ; ) {
    string s = get_word ( in );

    if ( in.eof() && s.empty() )
      break;

    if ( !s.empty() ) …
Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

>Its called "C++ for Dummies."
I've come to the conclusion that the "dummies" part of the title is referring to the author. I suggest you look at another book. :) I always recomment "Accelerated C++" by Koenig and Moo as an introductory text.

>has anybody ever gotten the GNU program installed correct
Which GNU program? G++? To be perfectly honest, you would be better off starting with an IDE based program. A good one is Bloodshed's Dev-C++. Ironically, it also uses the GNU compiler as a back-end, so nothing lost. :)