Prabakar 77 Posting Whiz

Yes, thats right

Prabakar 77 Posting Whiz

Why ?? please help me!! this is my homework !!

Thats why you have to do it. Its YOUR homework.

Prabakar 77 Posting Whiz

Assuming that print forward is to print the data in ascending order all you have to do is inorder traversal
which should be something like this

void inorder(tree_ptr)
{
  if  ( tree_ptr -> left )
     inorder( tree_ptr->left);
//  print the value stored in this node
  if (   tree_ptr -> right )
     inorder( tree_ptr->right);
}

And reverse print is the opposite of the above algorithm. go right then left. Google inorder traversal for explanation.

And inserting a node in the tree is not that simple as you have wrote. google it

Prabakar 77 Posting Whiz

endl manipulator in istream? remove it.

Prabakar 77 Posting Whiz

AD has given the answer sometime back.

Prabakar 77 Posting Whiz

You can also use Shell(<address of exe as String>, AppWinStyle.Hide)

Prabakar 77 Posting Whiz

If you want to run MSWORD in multiple computers from a single computer then all you have to do is to send a UDP broadcast message to the clients, and the clients will just run the MSWord with the System.diagnotic.start("winword") You can also use Shell command but you'll have to give absolute address. So, I would prefer the first method. Its simple and it works:)

Prabakar 77 Posting Whiz

do you mean... System.Diagnostics.Process.Start( "winword" ) ?

Prabakar 77 Posting Whiz

Thanks for your help. The project is completed:)
It works fine. I did get stuck when the client had to return a message to the server but google helped me get the answer:)

Alex Edwards commented: That's right!! Google it! +4
Salem commented: Congrats +21
Prabakar 77 Posting Whiz

Yes, return value will be negative or positive or zero. Relearn the basics of strcmp()

Prabakar 77 Posting Whiz

Yes, once a second.

I did not think of broadcasting. I believe your answer is perfect for my need:)

But, as I said I don't know much about Networking. I will try to broadcast the message. If I am stuck while coding I'll come back here.

Thanks

Prabakar 77 Posting Whiz

I am going to download fedora live cd:) I have already downloaded Ubuntu. Its good too.

Prabakar 77 Posting Whiz

I have wrote a simple program in c++ that will constantly read a record from a database. Once there is a change in a field the program will open a executable file. An instance of this program or a copy of this program has to run in at least 80 computers. Initially I thought, if I could make all the 80 computers to share some memory in the server where I can store the database then all the instance of the program will have access to the database. But, I was told that 80 computers cannot share the same memory, the server cannot handle so many connections.
All I want is to read a record from a table in the sever database. That too not very often.

I don't know if there are other ways c++ can provide me to get a record from the server database.
I am a novice in network stuff. Please help me.

If it matters,

Server Configuration,
160 GB HDD
Windows 2000 Server
1 GB RAM
Pentium 4 (3 GHz speed)

LAN Connection speed 100 MBPS

Clients run in XP SP2 or Win2000 SP4. Mostly (Win2000 SP4)

I am using Visual Studio 2005

Prabakar 77 Posting Whiz

You can use also stringstream to convert to int

int final;
stringstream strm;
char * value_a = "123456";

strm << value_a;
strm >> final;

I never knew about that. This looks great

Prabakar 77 Posting Whiz

You can use the Library functions like atoi(), sscanf()

Prabakar 77 Posting Whiz

Why do you want to convert a character pointer to an integer? Such conversion are normally not done.

But the answer is int final = (int)value_a;

Prabakar 77 Posting Whiz

I apologize to you all for not replying for a month.
Actually I gave my hope on PCLinuxOS until last week.
I booted one of my college computers with PCLinuxOS and to my surprise I was able to connect to the Internet very easily.

*The One difference that I noted is that the LAN card was detected in College but not in my computer.*

So, I connected the modem to one of my USB port and then Yeah! I am connected to the Internet with PCLinuxOS. Daniweb looks a little different in this OS. But I am very happy that I am able to connect.


The Ethernet card came with a driver CD which has a source file for compiling in Linux
When I tried to compile the file I had so many errors that I gave up on it. As I said before I am happy what I have now.

And finally I thank you all for your suggestion & time that you spend helping me.

Prabakar 77 Posting Whiz

Perhaps you may have to toggle to plain text before coping the code. Here is the code again.

EDIT: and I saw the explanation. So flag is indeed need incase the word contains text & numbers. Well, add that in your code should be simple:)

Prabakar 77 Posting Whiz

c having several commands by using those commands we have to write programes very easily in some times the c commands are doesnot work properly at that time we have to use decission making statments.
===========================================================
lux

www.sofrware.com

What commands? When it does not work?

Prabakar 77 Posting Whiz

Oops, Some syntax errors. I changed it now.

Prabakar 77 Posting Whiz

Well, I have made some assumptions since you did not say what it is supposed to do.
I modified your code a little:)

#include<iostream>
#include<string>
#define isalpha(a) (((a)>='A' && (a) <= 'Z') ||((a)>='a' && (a) <= 'z'))

using namespace std;

class HowEasy
{
    public:
      int pointVal (string);
      string statement;
    private:
       int letterCount,wordCount;

};

int HowEasy::pointVal (string s)
{
    int len = s.length();
    int avgCount, i ;
    wordCount=0,letterCount=0 ;
    for(i=0; i<len ;i++)
    {
        if(isalpha(s[i]))
            letterCount++;
        else if(s[i]==' ')
            wordCount++;
        else
        { 
            while ( !isalpha(s[i+1])) i++ ;
            wordCount++;
        }
    }
    cout << "The no of letters in the string: " << letterCount << endl;
    cout << "The no of words in the string: " << wordCount << endl;
    avgCount = letterCount/wordCount;
    cout << "The avg letter count in the string: " << avgCount << endl ;
    if(avgCount<=3)
        return 250;
    else if(avgCount<=5)
        return 500;
    else 
        return 1000;
}

int main()
{
    HowEasy class1;	
    cout << "Type the problem statement: ";
    getline(cin, class1.statement);
    cout << "The string's point value is :" << class1.pointVal(class1.statement);
    cin.get() ;
}

Type the problem statement: Hi! This Statement should be fine. I hope so...
The no of letters in the problem statement is displayed below: 34
The no of words in the problem statement is displayed below: 9
The avg letter count in the problem statement is displayed below: 3

The problem statement's point value is :250

EDIT: I don't like using string data as a public member. I didn't care about such things …

Prabakar 77 Posting Whiz

I can answer the first question.

#include<stdio.h>

int main()
{
    printf ("\a" ) ;
    printf ( "Hi This text will not be seen" ) ;
    printf ( "\rHi this text will be seen ofcourse" ) ;
    printf ( "\nThe last letter will be modified" ) ;
    printf ( "\bD" ) ;
    getchar( ) ;
}

I don't know if they are used. Even if perhaps in C. In C++ iomanip will be used I guess.

Prabakar 77 Posting Whiz

Why not sort the list as you insert the node. It will prove to be very easy

Prabakar 77 Posting Whiz

I agree with you CoolGamer & refer to my post. I didn't get that warning in that line. It was the line before it, that's why I suggested a type cast.
x = x||y ; x||y will return ( false||true == 0||1 == 1 ) This int is being assigned to the type bool hence the warning.

Prabakar 77 Posting Whiz

What? Never heard of that. Don't tell me,
this don't work
x = bool (x||y) ;

Prabakar 77 Posting Whiz

Its kind of strange. In my turbo c++ compiler I got that warning for the line x = x||y ; Besides, you don't assign anything in the if statement.

Warning D:\TC\BIN\NAME.CPP 14: Assigning int to bool in function main()

Line 14: x = (x || y);
As I said before type casting would do.

Prabakar 77 Posting Whiz

Oh, I see it now.

Prabakar 77 Posting Whiz

sorry, a little mix up. I used Turbo C compiler instead of turbo C++ which is strict when it comes to type checking. You just have to convert the int returned by x||y to bool x = (bool) (x || y);

Prabakar 77 Posting Whiz

Thanks!

Prabakar 77 Posting Whiz

Why am I not able to see it? Should I register?

Well, Why go all that trouble. Doesn't Dani web allow us attach pictures or any file we want with a max of 10 MB, if my memory doesn't fail me.

Prabakar 77 Posting Whiz

I don't get it. I too use Turbo C++. I copied the code & run it. It had no problem(No Warning No error). But in Code::Blocks, Since bool was already known I had the error message. And then || operator returns integer as far as I know. returns 1 if true & 0 if not

Prabakar 77 Posting Whiz

I know I was just saying that because I putted the MS-DOS commands... but how trainers work then? The x=&a shows the address...I wandered if it's a way to change 'a' with another program like a trainer... :-/

Perhaps, Inter process communication may be an answer.
>>but how trainers work then?
I don't get it. What trainers?

Prabakar 77 Posting Whiz

Perhaps this:

#include<iostream>

int main ()
{
    unsigned long long u40=16825420246llu;
    unsigned long long u20=3171426llu;
    unsigned long long prod=u20*u20;
    double kx;
	
    kx=double(u40)/prod; 
    std::cout<< "u40: "<<u40<<" u20: "<< u20
        <<" Prod: "<<prod<<" kx: "<<kx;
    std::cin.get() ;
    return 0 ;

}
Prabakar 77 Posting Whiz

My friend said to me that in 1935 The US police killed an innocent person & his friend suicide because of that, thus US government declared Friendship day.

I searched the net but didn't see any such story. But I found it was somewhat right, that it was started in 1935 & by the US Congress Govt. Please clarify the reason.

-Prabakar

Prabakar 77 Posting Whiz

Thanks Salem & ArkM for your replies.
Unfortunately, the book "The Design and Evolution of C++" costs $44.40. Its too expensive to buy:(

Prabakar 77 Posting Whiz

>>But are you ready to get a fraction looks like
No, I will limit it to 5 decimal places;)
and the other ways.... Please

Prabakar 77 Posting Whiz

i am using an string array with 100 length..but i am inserting upto 10 values only...how to get that array existing element count as 10....

I think the answer is on top of your post. strlen() should work.

if i allocate space like this
int no[20];
and i store about 10 nos in the array, how do i check the no of elements on the array ?

How do you store the 10 nos in the array?
something like

for ( i = 0 ; /*expression*/ ; i++ )
{
    no[i] = something ;
}

if so then i has the count.
or if its a hash table where numbers are not entered in order then I am afraid you will have to loop the array for valid entries.

Hope this helps:)

Prabakar 77 Posting Whiz

Is there a way - sure.

You have to code it.

5.xxxx will become 5 (xxxx/10000) then just find the gcd of xxxx & 10000. Divide either with it & you have what you want. 3 ints representing the float.

There could be other ways.

Prabakar 77 Posting Whiz

Thanks for your reply, and I am a little confused with it.

Being const, the compiler is free to perform a value substitution at compile time. In that respect, simple consts in C++ resemble #defines in C.

If the compiler replaces const at compile time, then the statement int &I = 5 ; is completely wrong.
And then, I will leave the 1st question since its the problem of Turbo C++ & not mine.

Prabakar 77 Posting Whiz

You have reffered me but my post is'nt here. So I will take our chat conversation here. I did say fread can be used only with binary mode, but after browsing msdn, I found that the problem is with ftell() and not fread() as I originally mentioned.

Prabakar 77 Posting Whiz

I have mentioned this before, I have to use turbo c++ in class.

Problem:
I wrote the following code & to my surprise the code passed the compilation without any problem. I was even more surprised with the output.
I just don't understand whats happening. This code won't compile in any decent compiler.

The Code:

#include<iostream.h>
class ref
{
public:
    int a ; double b ;
    ref ( int A, double B ) { a = A, b = B ; }
} ;
int main()
{
    const ref obj ( 5, 5.5 ) ;
    ref &b = obj ;
    const int i = 5 ;
    int &I = i ;
    b.a = 10, b.b = 10.1 ;
    I = 10 ;
    cout << "Object: " << obj.a << " " << obj.b
         << "Its Reference " << b.a << " " << b.b ;
    cout << endl << i << " " << I ;
    cin.get() ;
    return 0 ;
}

Output:

Object: 10 10.1Its Reference 10 10.1
5 10

Question:
Even though turbo C++ may be an old compiler, why these errors?
1) I was able to modify the const object of the class ref
2) if 'I' is just the reference of 'i' then how come a memory location store 2 values 5 & 10.

Please comment on this.

Prabakar 77 Posting Whiz

records** myarray;
myarray = new records*[numRecords];
(*myarray).title = "w/e";//same as...
myarray->title = "w/e";

Storing values before allocating memory for 'em? I will be surprised if it works.

Prabakar 77 Posting Whiz

Why do you call this a pitfall? They are just general rules in evaluating expressions, Aren't they?
I just can't thing of any other way to evaluate these expression.
for (5 < -1u) the compiler is bound to return 1.

Prabakar 77 Posting Whiz

I just want to say one more optimization. Instead of using the regular math::sqrt() function which returns a double if we write our own code we need not give importance to the decimal value hence speeding up the process. Hope this helps:)

Prabakar 77 Posting Whiz

In that case this program prints 8 (on 32-bit int platform with sizeof(int) == 4). Next time it prints 4, next time (may be) it prints 5 (and so on)...

Strange I always got 4.
I guess I should have added a for loop.
Updated program

#include<stdio.h>
int main ()
{
    union findsize
    {
          unsigned char c[8] ;
          int a ;
    } obj;
    int i, bytecount = 0 ;
    for ( i = 0 ; i < 8 ; obj.c[i++] = 0 ) ;
    obj.a = -1 ;
    for ( i = 0 ; i < 8 ; i++ )
        if ( obj.c[i] == 0xff )
            bytecount++ ;
    printf ( "%d", bytecount ) ;
    return 0 ;
}

The only valid result from int a[2] is &a[1]-&a[0]==1 . It's not interesting thing (has nothing to do with sizeof(int)).

a[1] = *( a+1 ) which is not a regular addition. The compiler has to do some sort of operation at least similar to sizeof() a+1*sizeof(*a) But as Salem said before, a programmer need not worry about it.

@Salem. Thanks for the link, unfortunately the text file you gave is really big & I am still searching for the answer. I did not find it in 6.5.6..

Prabakar 77 Posting Whiz

I don't know why a[0] & a[1] are not assured to be in successive memory locations. But if that is the case, then how would this be assured of correctness?
&1[trick].c - &0[trick].c == &*(1+trick).c-&*(0+trick).c == &trick[1].c - &trick[0].c

And how my code is incorrect? Please explain.

Prabakar 77 Posting Whiz

Perhaps this

#include <iostream>

int main ( )
{
	int &x = *(new int[5]);
	(&x)[0] = 1;
	(&x)[1] = 1337;
	std::cout<<(&x)[0]<<(&x)[1] ;
	std::cin.get() ;
}

again not advisable, for the above reasons

Prabakar 77 Posting Whiz

lets say there are 2 classes date & dmy then
date a = new dmy() ;
needs a conversion.
this conversion routine may be in source(dmy) or in destination(date).
if it is in source(dmy) all you have to do is
operator date() {... }
if the routine has to be in destination then the constructor should be used
date(dmy t) {... }
I don't know how it works but it works.

Prabakar 77 Posting Whiz

Why should we worry about converting the number to hex or binary. Its already stored in binary format.

Prabakar 77 Posting Whiz

1) the overloaded operator << return a reference to the fin object
2) type casting to primitive data type is as follows.

class complex
{
       int r, i ;
public :
       operator int()
       {
           return r*r-i*i ; // some conversion to int
       }
       complex():r(0), i(0) { }
       complex ( int a, int b ) { r = a; i = b ; }
      
};

if both the source & destination are user defined then the function for the cast may be either in source ot in destination.
Conversion routine in source is similar to that of the primitive types. But in destination is a little different.

class dmy // source
{
    int day, mth, yr ;
 //methods
} ;
class date // destination
{
    char a[10] ;
// conversion routine
   public:
    date ( dmy t ){/*convert ints to char array*/}
};

Hope this helps:)