WolfPack 491 Posting Virtuoso Team Colleague

Do any of these help?
I haven't tried any myself, although I plan to do so in the near future.

WolfPack 491 Posting Virtuoso Team Colleague

Please post the code.

WolfPack 491 Posting Virtuoso Team Colleague

Modify this.

WolfPack 491 Posting Virtuoso Team Colleague
  1. Why virtual functions can't be static?
    virtual functions are bound to an instance of a class, and you can't call it without an instance(object) of the class. static functions are bound to the class itself, and you do not need an instance of the class to call a static function.

  2. Why virtual functions can't be friend functions?
    Virtual functions are member functions internal to a class and friend functions are external to the class. So you obviously can't be both.

WolfPack 491 Posting Virtuoso Team Colleague

It does not. in_order_print(2) prints 2.
After that, in_order_print(3) prints 3.

WolfPack 491 Posting Virtuoso Team Colleague

First of all, I think there is a bug in line 8.
I think it should be if(p_tree->p_right != 0)
To understand the code, think about these three lines of the function, starting at the top node(6). If you write it down on paper, it will be easier to keep track on where you are.

if(p_tree->p_left != 0) in_order_print(p_tree->p_left);
cout << p_tree->num<<" ";
if(p_tree->p_right != 0) in_order_print(p_tree->p_right);





  in_order_print(6):
      Because the left node of '6' is not empty, call in_order_print with ( left node of 6 = 3 ).
      in_order_print(3):
          Because the left node of '3' is not empty, call in_order_print with ( left node of 3 = 2).
          in_order_print(2):
               Left node of '2' is empty, so do nothing 
               cout << p_tree->num<<" "; -> print 2
               Right node of '2' is empty, so do nothing.
          end of in_order_print(2)
          cout << p_tree->num<<" "; -> print 3
          Right node of '3' is empty, so do nothing.
      end of in_order_print(3)
      cout << p_tree->num<<" "; -> print 6
      Because the right node of '6' is not empty, call in_order_print with ( right node of 6 = 8).
     ...
WolfPack 491 Posting Virtuoso Team Colleague

Mike has summarized the process very nicely. If you wish to go into more details, I would recommend "Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications". I sort of learnt the process that Mike described through this book.

WolfPack 491 Posting Virtuoso Team Colleague

What you need to do is adjust 24 so that the string "$" is positioned making allowance for (number of digits before the decimal point ) + 3 digits.
Why 3? Decimal Point + 2 Digits after the decimal place

So in this case, it should work if you wrote
cout << "Shelby" << setw(24-5) << "$" << shelby << endl;

Now to figure out the number of digits before the decimal point.

if( 0 < value < 10 )
    x = 1
if( 10 <= value < 100 )
    x = 2
cout << "Shelby" << setw( 24 - (x + 3) ) << "$" << shelby << endl;
WolfPack 491 Posting Virtuoso Team Colleague

Once you change the scope of account_number, balance and passw to private scope,
you won't be able to access them directly from main().
So you will have to add public accessor functions for each of the above data members, and call them in main().

example:

class account{
private:
      int account_number; //account_number's scope is private

public:
      int GetAccountNumber( ){ return account_number; } // public accessor function
 };

 void main()
 {
 ...
        //if(acno==uxi[i].account_number) // Can't access account_number directly
        if(acno==uxi[i].GetAccountNumber())//Using the public accessor function instead
}
WolfPack 491 Posting Virtuoso Team Colleague

Yeah I guess using c_str() is overkill. Just posted what I thought of at first.
This should be simpler.

        newChars[j]=alphabet[j][0];
WolfPack 491 Posting Virtuoso Team Colleague

I am sure that you must have looked up the Wikipedia entry on this subject. I would select one from the list in that entry and research on it.

WolfPack 491 Posting Virtuoso Team Colleague

Just noticed, there seems to be a small typo.
It should be
newChars[j]= *alphabet[j].c_str();

WolfPack 491 Posting Virtuoso Team Colleague

You could use the c_str() member function to get the character array represented by the string. Remember to delete the newChars array before exiting the program, and also to use the C++ style header <string> , not the C-style version <string.h> .

    newChars[j]= *alphabet[i].c_str();
WolfPack 491 Posting Virtuoso Team Colleague

A bit off topic, but thought it may be good to provide feedback here since I bought the book after reading this thread.

Andrew,
Bought the C++ Primer to familiarize myself with the new C++11. Overall seems like a good book, but there may be a few typos and errors that you missed during revision. Is there an email address so that I can point them out to the authors?

Example that I just found..Trivial but for what it's worth.

Exercise 2.25(page 59) Determine the types and values of each of the following variables.
(a) int* ip, &r = ip;

clearly r is a reference to an integer, so it can't refer to ip which is a pointer to an integer. Confirmed the error on the Visual C++ 2012 compiler Version 17.00.50522.1.

WolfPack 491 Posting Virtuoso Team Colleague

Either you have not included all the necessary header files or you have used codeblocks specific code.

WolfPack 491 Posting Virtuoso Team Colleague

Can't find the problem with only one line of code.
Post the whole program.
The one you mentioned in your first post, and the one modified to accept multiple clients.

So I have a very simple server/client program using winsock. In C++. Using MingW as a compiler.

WolfPack 491 Posting Virtuoso Team Colleague

Post your attempt. Let's see what the problem is.

WolfPack 491 Posting Virtuoso Team Colleague

Not possible using only C++.
Window management is platform dependent so you will have to use the facilities provided by the operating system.
For Windows, this can be done by using the freely downloadable platform SDK.
For Linux, I don't know. Try a google search on Linux GUI programming or something.

WolfPack 491 Posting Virtuoso Team Colleague

getVerticeById is clearly O(n).
The part below of ListAdjGrafo<TV,TR>::distancia seems to be of O(n^{2}) complexity because of the cascading while loops.
So this algorithm is at least O(n^{4}) complexity.
Final answer would depend on the complexity of encvert_key , encvert_conteudo and distanciaMinimaVertice What relation does indice_origem have with the inputs ini and fim ?

Vertice<TV, TR> *apvertini = encvert_conteudo(ini); // O(? )
    Vertice<TV, TR> *apvertfim = encvert_conteudo(fim);// O(? )

    int indice_origem = apvertini->key;
    distancia[indice_origem] = 0;

    while (indice_origem != -1){ //  O(n2) because of the inner while loop called by this while loop.
        processados[indice_origem] = true;
        apvertini = encvert_key(indice_origem); // O(?)
        Ramo<TV, TR> *apramo = apvertini->apramo;
        while (apramo != NULL){ 
            int indice_destino = apramo->apv->key;
            if (!processados[indice_destino] && distancia[indice_destino]>(distancia[indice_origem] + apramo->rconteudo)){
                distancia[indice_destino] = distancia[indice_origem] + apramo->rconteudo;
                caminho[indice_destino] = indice_origem;
            }		
            apramo = apramo->apr;
        }	
        indice_origem = distanciaMinimaVertice(distancia, processados);	//O(?)	
    }

It is a bit difficult to explain unless I write a tutorial on O-notation which I am incapable and not interested in doing.
Also there are a lot of tutorials out there, so if you have read them, it is just a matter of learning how to apply them which I can't teach you anyway. here is one.

WolfPack 491 Posting Virtuoso Team Colleague

Post code for utilizadores.getVerticeById() , and utilizadores.distancia() .
If they are linear, then this function is of [TEX]O(n^{2})[/TEX] time complexity.

WolfPack 491 Posting Virtuoso Team Colleague

You can use the socket file descriptor returned by accept to distinguish between multiple clients connected to the server.

WolfPack 491 Posting Virtuoso Team Colleague

Run it and see if it's correct.

A single send will send it only to one client.
To send to multiple clients, you have to connect multiple clients and have the server do a send to each client.

WolfPack 491 Posting Virtuoso Team Colleague

Refer this link. It has most of the code that you need to implement a simple server/client to send/receive text.

You don't always have to do the busy for loop. You could just open the socket in blocking mode and wait until text arrives (research blocking). However, this will cause the receiver to halt its execution until something comes its way, so if you plan to do something else with your program as it waits for data, you should consider using a separate thread to do the waiting part.

As an alternative, Winsock has the WM_SOCKET_NOTIFY event that can be used to get notifications when an event for that socket has occurred. This will allow you to do other things, and switch to the data reading part when it actually arrives. But designing this a bit involved if you have no experience with the Windows API.

WolfPack 491 Posting Virtuoso Team Colleague

What is the problem?

WolfPack 491 Posting Virtuoso Team Colleague
switch(c){
		case '1':{ (...) ; break;}
		case '2':{ (...) ; break;}
		case '3':{ (...) ; break;}
	}
	if(f){
		switch(c){
			case '4':{ (...) ; break;}
			case '5':{ (...) ; break;}
			case '6':{ (...) ; break;}
		}
	}
WolfPack 491 Posting Virtuoso Team Colleague

I moved it to the Code Snippet Section.

WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

Not sure if this will work, but try

(LPCWSTR)L"Hello World"

just in case. If it doesn't I will look into this in detail. I remember having the same problem some years back.

WolfPack 491 Posting Virtuoso Team Colleague

Please tell us what part you are having problems with. Data reading from the file part? Sorting the names in ascending order? or Sorting the ages?
If you are getting compile or link errors, post them.
If you are getting incorrect output, post the input and the output(both expected output and actual output).
It is boring to look through 160+ lines of code without having no idea what we are looking for..

WolfPack 491 Posting Virtuoso Team Colleague

Since the List Box is a fairly basic control, there shouldn't be much difference in functionality between versions. This seems a fairly easy tutorial, and seems to be just what you want out of your application too.
1. Add items from the text box.
2. Remove the selected item.