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.

WolfPack 491 Posting Virtuoso Team Colleague

I have found this tutorial online, which looks immensely helpful but unfortunately is for a previous version of Qt and is thus outdated:

What version of QT is used in the Tutorial? What version are you using?

WolfPack 491 Posting Virtuoso Team Colleague

OP means Original Poster, and that is you.

1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(57) : error C2065: 'c_file' : undeclared identifier
1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(57) : error C2228: left of '.attrb' must have class/struct/union
1> type is ''unknown-type''

c_file is being used before declaring it. That is the reason for the above error.

1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(64) : error C2065: '“c' : undeclared identifier
1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(64) : error C2143: syntax error : missing ')' before ':'
1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(64) : error C2017: illegal escape sequence
1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(64) : error C2017: illegal escape sequence
1>c:\users\1014034\documents\visual studio 2008\projects\p1 2\p1.cpp(64) : error C2059: syntax error : ')'

The “” in _chdir ( “c: \\dir1” ); are in an un-ascii code. That is why the errors in line 64 shows up. The compiler can't process it.
Replace it to _chdir ( "c:\\dir1" ); and errors in line 64 should dissappear. Better to type it by hand and see.

Anyway the below snippet should work.

_finddata_t c_file;
    intptr_t hFile;
    

    _chdir ( "c:\\dir1" );
    // Find any file in current directory 
    if( (hFile = _findfirst( "*.*", &c_file )) == -1 ){
        cout <<"Error! :" << errno  << endl; // This doesn't mean current directory is empty.  
    }
    else
    {
        do {
            // if the file is not a sub dir...
            if( ( c_file.attrib & _A_SUBDIR ) != _A_SUBDIR ){ // _A_SUBDIR = 0x10 (16 in decimal). Also note the single &. 
                cout << …
WolfPack 491 Posting Virtuoso Team Colleague

AD,
The OP is using the direct.h header so she is probably using the Digital Mars libraries. There can be various reasons the code is failing, incorrect input, spaces between directory names, etc. So without information from the OP on where it is actually failing, we don't have any way of resolving this issue.

WolfPack 491 Posting Virtuoso Team Colleague

Okay. So from what I understand, before setting up OpenCV, you have to setup Eclipse so that you can compile and link a basic C/C++ program, right?
Follow this link, and see if you can get to compile, link and run a basic Hello World program.
If you can't, post the problems you are having.
If you can, continue with the OpenCV setup for Eclipse.

WolfPack 491 Posting Virtuoso Team Colleague

No. I use visual studio. What problems are you facing when you follow the given link? Please be as descriptive as possible.

WolfPack 491 Posting Virtuoso Team Colleague

Do you know the meaning of this?

A square has 4 vertex then the degree of each vertex is 2.

WolfPack 491 Posting Virtuoso Team Colleague

If you just Googled "OpenCV and Eclipse CDT", you would have found this, and a lot of other helpful links, and saved the time taken to type and post in multiple forums.

WolfPack 491 Posting Virtuoso Team Colleague

My problem is that I can't get the blasted file(s) read in! I can read a single file (e.g."junk.txt") and do the comparisons, but I can't get the directory file thing to work. Also, one type of file (jpg) will be of an indeterminate size.

What does "directory file thing" mean exactly?
What part of the program fails? What is the last line of output you see?

WolfPack 491 Posting Virtuoso Team Colleague

Well, from how I see it, if the users find the new Google results push the more informative content down the list, they will move to a better search engine. I remember using Yahoo search as my primary search engine in the early 2000s but moving to Google for the same reason. Let's see what happens. It is the users who decide finally. Content doesn't get better just because it figures in the top of some machine generated list.

WolfPack 491 Posting Virtuoso Team Colleague

Since I am in Japan, I have no experience with the changes made by Google.

But a simple collection of keywords may have worked before to get traffic, but now, quality will have to be given importance above quantity. Not only the answers, but also the questions. I rarely wander out of the C/C++ forums, and there I think 90% of the questions are beginner level questions. Even then, considering the simplicity of the question, the depth of the thread is ridiculously too long. It takes at least 3-4 posts to get the OP to post some code. Developers don't have time to wade through dozens of pages to find a solution. It gets boring and wastes time. That is why Wikipedia is in the top of the search results. It may not have the complete answer, but it is a great starting point for anyone who is not a free loader. I for once haven't come across Daniweb during my work related Google searches. My main hits have been Wikipedia, Stackoverflow, Embedded.com etc. And they point me in the correct direction.

I read in a previous thread, that Dani has made changes targeting more advanced developers from the US/CANADA to post here more, so things will improve. But it won't be easy to reverse the damage the broken English homework students have done in these past 5-6 years.

Moderators will have to pay a lot of attention on the quality of the answers and …

AndreRet commented: I agree 100% +0
WolfPack 491 Posting Virtuoso Team Colleague

Lines 23 to 25 in your code seems to be useless. I don't think there is the need to move to the end of List1 in order to update LastNode which needs no updating.
Did a rewrite. Maybe buggy since I don't have the class declaration of node, so use it as an algorithm at best.

//overloaded plus equal (+=) operator
//data hold the data for the Node and next points to next node 
OList & operator += (const OList & other) { 
    Node<T> *temp;
    Node<T> *p1 = head;         //list on the left of operation a+=b
    Node<T> *p2 = other.head;    //list on the right 
    
    size += other.size;    //change size of current list to list size += right list size
    
    // Assumes P1 and P2 are already sorted

    // Haven't reached the end of List1 or List2?
    while ( p1 != NULL && p2 != NULL ) { 
        // For each P2 in List2, find P1 in List1 where P1.data > P2.data, and insert P2
        if (p1->data > p2->data) {
            temp = createNode(p2->data);
            temp->next = p1->next;
            p1->next = temp;
            p2 = p2->next; // Advance to the next item in List2
        }
        p1 = p1->next; // Advance to the next item in List1
    }
    if (p2 == NULL){ // End of List2 reached or List2 was empty from the start
        // All elements of p2 have been inserted to List1.
        // Nothing else to do.
    }
    else{ // Some items are left in List2
        // Append copies of remaining items …
WolfPack 491 Posting Virtuoso Team Colleague

Explaination is the same as what navedalam said. But I am surprised that this even compiles. At least there should be some compiler warnings. In any case, this kind of usage has to be handled with great care. int *ptr=10,j; ptr is a pointer to int . j is an int .
The types are different. So you won't be able to assign one to the other without a cast .

int *ptr = (int*)10, j;
    j = (int)(ptr+19);
WolfPack 491 Posting Virtuoso Team Colleague

You have created a Win32 Console Project . Select Win32 Project

WolfPack 491 Posting Virtuoso Team Colleague

The problem must be with how the assignment operator (operator=) is implemented. Is there any documentation regarding that?

daviddoria commented: Thanks, that was exactly the problem! +5
WolfPack 491 Posting Virtuoso Team Colleague

Post what you have done up to now.

WolfPack 491 Posting Virtuoso Team Colleague

The problem should be related to the one pointed out in this post.
Post whole code for the SequenceAds class.

WolfPack 491 Posting Virtuoso Team Colleague

Ah I see. Thanks both of you.

WolfPack 491 Posting Virtuoso Team Colleague

Isn't tagging it incorrectly, like posting C/C++ posts in the Web Development forum?
What is this user's deal anyway? What possible interest can he have in retweeting Daniweb posts blindly like that? And why #webdevelopment. I would ask him, but don't know who he is. Any ideas?

WolfPack 491 Posting Virtuoso Team Colleague

Isn't it odd that content with no relevance to Web Development are tagged as webdevelopment?

WolfPack 491 Posting Virtuoso Team Colleague

Without replacing the digits with x as you find them, remember the first digit you encounter while you scan the string. Move ahead until you find a non-digit. Replace sub-string from the first digit to the one before the non-digit with a single "X".
There are many ways to do this, but one basic algorithm would be as below.

Number_Start_Pos = -1
Number_End_Pos = -1;
read character while not end of string{
   If ( ( Character is a digit ) AND ( Number_Start_Pos == -1 ) ){ 
       Number_Start_Pos = current_position;
   }
   If ( ( Character is not a digit) AND ( Number_Start_Pos != -1 ) ) {
       Number_End_Pos = current_position - 1 ;
       Replace( Number_Start_Pos to Number_End_Pos with "X" );
       Number_Start_Pos = -1;   
       Number_End_Pos = -1;
   }
}