WolfPack 491 Posting Virtuoso Team Colleague


My client is on wingoze

What is wingoze? Whatever it is, it may be an Operating system, and there should be a socket API for it. Look that up.

Salem commented: random rep++ from salem +6
WolfPack 491 Posting Virtuoso Team Colleague

This is easy.
The letter E.

mattyd commented: the letter "E" +4
WolfPack 491 Posting Virtuoso Team Colleague

Sorry, I was looking for something a little simpler and little more free :P

Try the built in _CRTDebug Libraries of Visual C++.

SpS commented: Good ~~ SunnyPalSingh +3
Salem commented: Good answer - Salem +4
WolfPack 491 Posting Virtuoso Team Colleague

Yeah, Humourless ...... :cheesy: . Didnt even know that Wombats were such cool species until DMR came along. Now I wanna be one in the next life.

They don't get eaten by others do they? :eek: Cos upto now I have been doing the eating. Can't bear to have the tables turned in the next life.

~s.o.s~ commented: Aww man will seriously miss you, take care while you are gone *sniff* ~s.o.s~ +7
WolfPack 491 Posting Virtuoso Team Colleague

1. pick up the book (of course)
2. Read the preface, introduction, Chapter 1
3. Fall asleep
4. Repeat 1 -3 infinitely, occationally wandering to Chapter 2 and maybe 3.

Sulley's Boo commented: hehe =D thankO +2
WolfPack 491 Posting Virtuoso Team Colleague

Why are you using the strcpy function? These are C++ strings. Use the = operator.

thisRecord.fieldName =next
WolfPack 491 Posting Virtuoso Team Colleague

I beleive you wanted to update the static variable shipPos1 instead of the variable shipPos which I don't see defined anywhere.

mattyd commented: ty +1
WolfPack 491 Posting Virtuoso Team Colleague

This should serve as a good example. As the arrays are passed by reference, the modifications you make inside the function will be shown even after exiting it. So you can enter the values inside the function and use the contents inside main.

tehloki commented: useful resource +1
WolfPack 491 Posting Virtuoso Team Colleague

Plus im sure there are syntax errors in there as i cannot find much helpful info on vectors and i'm lost..

See if you can see anything useful here.

Jonezy commented: Replyin quick.. Useful links.. Awesome.. Thanks mate!! +1
WolfPack 491 Posting Virtuoso Team Colleague

Too long to make all the corrections. Make corrections for number 1 and number 19. You can understand as I have commented the changes. Do the others yourself and post if you have other problems.

#include <iostream>
using namespace std;
const double PI = 3.1415; 
// The constant pie. You may know that you can't output this as a fraction as pie has infinite decimals.
int main()
{
    float area;
    float base;
    float Sbase; //Small Base (Trapezoid Formula)
    float Bbase; // Big Base  (Trapezoid Formula)
    float Wbase; //Width of Base (Pyramid Formula)
    float Lbase; //Length of Base (Pyramid Formula)
    float circumference;
    float height;
    float length;
    float perimeter;
    float radius;
    float side;
    float sidea;
    float sideb;
    float width;
    
    int op; // make op an int. if it is a char it can only hold one character. So you can't input 10, 11, 12, .... That is why you got the multi character errors.
    char again = 'y';
    
    /* Removed your greetings to reduce number of code lines. Add them again */
    while (again == 'y')
    {
        //here the user chooses what he wants to find out    
        cout <<"FUNCTION LIST"<<endl;
        cout <<""<<endl;
        
        cout <<"\nArea of a Square = 1" <<endl;
        /* Similar couts for the other functions */    
        cout <<"\nVolume of a Sphere = 19"<<endl;
        cout <<"Surface Area of a Sphere = 20"<<endl;
        
        cin >> op;
        
        // Rather than using nested if else if statements, you could use a case statement too.
        // But I left it as it is.
        if …
Niklas commented: You helped me a lot thanks man +2
WolfPack 491 Posting Virtuoso Team Colleague
void Counter::display()
{ 
    std::cout << "The value of the counter is " << Count << std::endl; 
}

why wont it work?

This is correct. So no idea. Maybe you have not saved the correction. Or you are linking a different file. Anyway it is a problem with the linker, and not the source code. The sourcecode is correct. Double chekc the contents of the files you are compiling.

matrimforever commented: Awesome advice and help! +1
WolfPack 491 Posting Virtuoso Team Colleague

Leave it to the WoLfMaN to figure it out. :cheesy:
@Andor: Surely you are using hybrid mode in IE, and linear mode in Firefox.

Just so that to make it clearer, I attached an image so that you know how to change it (if you didn't already know)

I think it's because of the AJAX call when you used the quick reply box. Can you reproduce the error upon refreshing the page?

I dont understand (I'm not english speaker).

I don't think Dani was speaking English in this particular instance. :mrgreen:

andor commented: You are right (andor) +4
WolfPack 491 Posting Virtuoso Team Colleague

Voted and left a stinking comment. You explain to Lauren. :p

'Stein commented: Hehe thanks Wolfpack. :) -'Stein +3
WolfPack 491 Posting Virtuoso Team Colleague

Right. This is what you should do.
1. Open the file ( You have already done that)
2. Read the opened file line by line into a string (lets call it line ). You can use getline for this.
3. Create a istringstream object lets call it isstream , from the string line .
4. You can again use isstream and getline to get each word delimited by the '~' character.
5. Compare the first word with the user input and if it matches, display the 4th word.

Try it and post your effort. We will help if you encounter further difficulties.

WolfPack 491 Posting Virtuoso Team Colleague

Sorry. We don't do homework :)

Salem commented: Absolutely! - Salem +3
WolfPack 491 Posting Virtuoso Team Colleague
struct SongInfo
{
   int track_no,
       track_pos,
       track_len_min,
       track_len_sec,
       runtime;

   SongInfo *next;

   friend ifstream& operator>> (ifstream& ins, SongInfo *target);
   friend ostream& operator<< (ostream& outs, SongInfo *target);
};

ifstream& [B]SongInfo::[/B]operator>> (ifstream& ins, SongInfo *target)
{
   ins >> target->track_no >> target->track_pos >> target->track_len_min
       >> target->track_len_sec;
   return ins;
}

ostream& [B]SongInfo::[/B]operator<< (ostream& outs, SongInfo *source)
{
   outs << source->track_no  << setw(10) 
        << source->track_pos << setw(10)  
        << source->track_len_min << ':' 
        << source->track_len_sec << setw(10) 
        << source->runtime/60 << ':'
        << source->runtime%60 << setw(10);
   return outs;
}

oops. I forgot to tell you to delete the parts above in red. The final code should be like below.

struct SongInfo
{
   int track_no,
       track_pos,
       track_len_min,
       track_len_sec,
       runtime;

   SongInfo *next;

   friend ifstream& operator>> (ifstream& ins, SongInfo *target);
   friend ostream& operator<< (ostream& outs, SongInfo *target);
};

ifstream& operator>> (ifstream& ins, SongInfo *target)
{
   ins >> target->track_no >> target->track_pos >> target->track_len_min
       >> target->track_len_sec;
   return ins;
}

ostream& operator<< (ostream& outs, SongInfo *source)
{
   outs << source->track_no  << setw(10) 
        << source->track_pos << setw(10)  
        << source->track_len_min << ':' 
        << source->track_len_sec << setw(10) 
        << source->runtime/60 << ':'
        << source->runtime%60 << setw(10);
   return outs;
}
Grunt commented: Helps-[G] +2
WolfPack 491 Posting Virtuoso Team Colleague

He he. That is not a bad post flag. That is negative reputation. Just forget it. I think you have more than 400 reputation points if my calculations are correct (probably second only to her majesty the queen herself), so no need to worry about a small red dot. I am waiting for someone to give me one so that I can see how much is subtracted from my rep points. Your post wasnt out of place.
We have a saying that goes like DOGS bark, but the caravan goes on or The MOON does not heed the barking of dogs.

'Stein commented: Well Said -'Stein +3
WolfPack 491 Posting Virtuoso Team Colleague

Not sure whether it would work for TurboC and the old command.com shell, but you could try creating the command using double quotes to handle filenames with spaces. Don't know what will happen for long file names though.

e.g.

copy [B]"[/B]c:\yserver.txt[B]"[/B] [B]"[/B]c:\documents and settings\luffy-san\desktop\tcp1241_assignment3\lecture notes\server.txt[B]"[/B]
~s.o.s~ commented: good one [~sos~] +4
Salem commented: Good answer - beat me to it - Salem :) +3
WolfPack 491 Posting Virtuoso Team Colleague

Yes. That is all you need to start coding.
But If you are a beginner, first try the Visual studio express edition, which can be downloaded for free.

Grunt commented: Still one green dot...that's not fair [G] +2
WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

Change the registry key value for

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper
chunkmartinez commented: thanks real simple! +1
WolfPack 491 Posting Virtuoso Team Colleague

Thanks for the help! :)
But it still doesn't work properly.. It complains that the variable 'counter' is a private variable.. And it doesn't work if I cange it into a public one.
Any clues why?

The answer to this is in the web link I gave you in my reply. Something about the static variable being initialized globally. See if you can find it.

EDIT: I've also got another question if someone knows the answer..
I'm working on an assignment where you have to take an object of a class and have it as an membervariable of another class. How do I do this?

class A
{
public:
      int a;
};

class B
{
public:
      A member_var_of_instance_A;
}
WolfPack 491 Posting Virtuoso Team Colleague

Please post your question outside code tags. I corrected your first two posts, do this one yourself, or I will delete this thread. Since it has been only 2 minutes since your post, you can edit it now.

WolfPack 491 Posting Virtuoso Team Colleague

If you are sure that the string is in double conversible format like 1.2e-2, grunt's method is the eaisest. But if you want to check the input string if it can be converted as double, e.g 123abc will be converted as 123 in grunt's method. For easier error checking better use strtod. Just checking the value of end to be null will be enough.

#include <sstream>
#include <cstdlib>
int main ()
{
    std::istringstream stm;
    char* end = 0 ;
    
    double d;
    
     stm.str("123abc");// Invalid input string
    stm >>d;  
     std::cout << d << std::endl; // Returns 123
     
    stm.str("123e-2");
    stm >>d;  
    std::cout << d << std::endl;  

     d = strtod( "123abc", &end ); // Invalid input string
     if ( *end == 0 )
        std::cout << d << std::endl;
    else
         std::cout << "Error Converting\n"; // Reports error
         
    d = strtod( "123e-2", &end );
    if ( *end == 0 )
        std::cout << d << std::endl;
    else
        std::cout << "Error Converting\n";
        
    return 0;
}

PS:
To get the characters from num , use num.c_str()

WolfPack 491 Posting Virtuoso Team Colleague

Because if you are allowed to do so, creating one variable of that type will go on creating nested variables inside it and eat all available memory.

WolfPack 491 Posting Virtuoso Team Colleague

1. I'm making a program with a default constructor and an overloaded constructor. They're both called by different rules and produces a testline of text when called. The assignment is to give the overloaded constructor default arguments to see what happens. I wonder, what is a default argument i an overloaded constructor?

Lets take class A such that

class A
{
         int i;
         int j;
}

A default constructor is a constructor that doesn't take any arguments.
e.g. A::A(); An overloaded constructor is a constructor that takes arguments.
e.g

A::A(int int_i, int int_j )
{
      i = int_i; 
      j = int_j;
};

you can use the values of int_i and int_j to assign values for class A's member variables i and j .
If you write the overloaded constructor like this,

A::A(int int_i, int int_j = 0)
{
      i = int_i; 
      j = int_j;
};

calling the constructor like A a(2) , will create an object a with a.i = 2 and a.j = 0; calling the constructor like A a(2,9) , will create an object a with a.i = 2 and a.j = 9; If you have a default constructor defined, don't make all the arguments of the overloaded constructor default arguments. That is because the compiler will not be able to tell the difference between the two constructors.

2. How do you instance an object from a class in different scope?

I think you are asking about something like this.

Grunt commented: Nice and detailed explantion-[Grunt] +1
WolfPack 491 Posting Virtuoso Team Colleague

Steve Loughran's WinAPI FAQ

This isn't exactly starting material and maybe a bit outdated (created before Win2K). But overall covers most of the questions a newbie, who is new to programming in C and is fedup with creating Hello World console applications, may ask.

WolfPack 491 Posting Virtuoso Team Colleague

Although I don't like to be seen as a Windows bigot, I don't think Linux is for anyone who has limited time in their hands. I have tried god knows how many distributions of *ix, (Gentoo, Linux from Scratch, Ubuntu, Knoppix, Redhat 7.3 to 9, Fedora 1 to 5, Turbo 10 Japanese version, FreeBSD 4.*, 5.5, 6.*, Debian, Mandrake, CentOS 4.1 -4.3 the list is endless ), but I couldn't do anything worthwhile using any of those. It was only the CentOS 4.3 that I came at least came closer to sticking with. Mandrake is the best if you want to get things up and running fast, but some geeky friends ( who are Microsoft bashers of course ) of mine said that Mandrake is slow compared to the others. Maybe they do not see anything elite in using a distribution that is easy to use. Even now, as I rummage through my CD collection I get really mad thinking about the garbage that all this has generated.

Before the Download managers like APT and Yum came in to play, installing software was pure hell. Even now if the dependencies are not in the repository, good luck if you are trying to install a software that does not come with the distribution. (Realplayer for instance). Oh and how about configuring firefox and java so that you can chat? So ultimately I decided that all this is a waste of time and energy, and switched back to XP, and have …

Sulley's Boo commented: yeeeee you rock Wolfyyyyyyyy =D +2
WolfPack 491 Posting Virtuoso Team Colleague

Just put #include <iostream> after the #include "stdafx.h" line.
It would be better if you select the "Create Empty Project" option and then start from scratch. That gives you a better feel of things going on rather than using a template.

[edit] as dave said you need the using namespace std; line too. [/edit]

WolfPack 491 Posting Virtuoso Team Colleague

Try

int a = b - -c;

Stop the course which asks silly questions like this.

Grunt commented: Cute Trick [Grunt] +1
Salem commented: LOL - the old favourites are the best - Salem +1
WolfPack 491 Posting Virtuoso Team Colleague

Look for the API called FindFirstFile.

WolfPack 491 Posting Virtuoso Team Colleague

You can either use

char filename[MAX_PATH];
    GetModuleFileName(NULL, filename, MAX_PATH);

or
the command line passed to WinMain

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance, char* command_line, int show_command)
WolfPack 491 Posting Virtuoso Team Colleague

Congratulations.:cheesy:

~s.o.s~ commented: Just to let you know that this is not about reputaion, i come again to an unknown quantity +1
WolfPack 491 Posting Virtuoso Team Colleague
do
  {
     flag=arrange(array,num);
  }while( flag==-1);

This is the only place where flag is being used. So isn't it simple? flag is used to store the result of arrange and arrange is called while the flag is -1.

Now go to the arrange function. It returns -1 when two elements in the array is swapped. That means the original array didnt have it's data in sorted order. Now from that knowledge what can you say? If the original array was not in sorted order, arrange returns -1. So the above loop means

do
     arrange( array )
until ( the original array was sorted )

Rather inefficient, but a common sorting algorithm. Hope you understand.

WolfPack 491 Posting Virtuoso Team Colleague

Hi Guys,

I still didn't get answer for my question.

By reference to pointer I mean this

int * & x;

Here x is a refernce to a pointer

This code is illegal because a reference has to be initialized not assigned. There are exceptions but in this case it has to be initialized.

In the same way pointer to a reference is not allowed in C++.

int & * x;

. This will throw an error saying "pointer to reference is illegal".

Now what my doubt is, if reference is just an alias to an object pointed to by it. Then what is the problem in creating a pointer to it ???

The Standard does not specify whether references need storage or not. So if there can't be storage for a reference, there is no meaning for pointers to a reference.

It is unspecified whether or not a reference requires storage

There shall be no references to references, no arrays of references, and no pointers to references. The declaration of a reference shall contain an initializer (dcl.init.ref) except when the declaration contains an explicit extern specifier (dcl.stc), is a class member (class.mem) declaration within a class declaration, or is the declaration of a parameter or a return type (dcl.fct);

Dave Sinkula commented: Very nice! +7
WolfPack 491 Posting Virtuoso Team Colleague

I posted a link a bit later in my earlier solution. Check it out and see if the error can be corrected.

WolfPack 491 Posting Virtuoso Team Colleague

Please format your code properly.

  • Increase the Tab settings
  • put braces even for the places where there is only one statement inside a for loop

When debugging problems, you don't debug all of the functions at once. Check each function one by one. If there is a debugger in your development environment use that. Usually crashes like this are because of array accessing errors like out-of-bound accessing.

Anyway
change this code

randomArray = new int [arraySize];
    sortedArray=new int[arraySize];
    reversedArray=new int[arraySize];
    cout << "Enter the number of elements in the array: "; 
    cin >> arraySize;

like this

cout << "Enter the number of elements in the array: ";     
    cin >> arraySize;
    randomArray = new int [arraySize];
    sortedArray=new int[arraySize];
    reversedArray=new int[arraySize];

you are creating an array of 0 elements and trying to access more than 0 elements. strange that it worked even upto 6400.

WolfPack 491 Posting Virtuoso Team Colleague

You probably wouldn't need the temporary variable if you use something like this.

iifstream    file(filename);
string      line;
if (file)
{
    string token;
    stringstream iss;
    int i;
    while ( getline(file, line) )
    {
        iss << line;
        i = 1;
        while ( getline(iss, token, ',') )
        {
            cout << token << endl;
            i++;
        }
        iss.clear();
    }
}

edit:
Dragon has posted a more or less equal version before me. I considered deleting this but decided otherwise because of a subtle difference. That difference is that the stringstream variable is created before the while ( getline(file, line) ) block. I only wanted to refraining from calling the constructor over and over again. But the additional overhead (if any )due to the call of iss << line; and iss.clear(); should be inspected.

WolfPack 491 Posting Virtuoso Team Colleague

try

ifstream file(filename);
if (file)
{
    while ( file.getline(line,SIZE) )
    {
        tmp =static_cast<string>(line);
        vector <string> array;
        string token;
        istringstream iss(tmp);
        int i=1;
        while ( getline(iss, token, ',') )
        {
            array.push_back(token);
            v_List.SetItemText(nItem, i, token.c_str());
            i++;
        }
    }
}
WolfPack 491 Posting Virtuoso Team Colleague

Ok I done some more testing it only happens after I add inline code tags as well as normal code tags in the post.

This is a very good observation. I get the same thing at my end too. Both at Work and Home. Well Done. :!: :idea:

hollystyles commented: Alone we are week together we are mighty! +2
WolfPack 491 Posting Virtuoso Team Colleague

Short story: How do you compile two .cpp files at once?

Okay I will go with the short story.

You RTF(ine)Manual.
Well any decent compiler should be able to compile multiple source files at once. You should be able to compile it by dmc sourcefile1.cpp sourcefile2.cpp , without any trouble for simple files.

WolfPack 491 Posting Virtuoso Team Colleague

program a client to make a connection request from a single server, and display the server name or IP if the connection is granted, and logout.
Use it to make connection requests from each computer in the LAN. You will get a list of computer names where the server is running. You can also program the client program to save the server name if the connection is granted. Then you can have it for future reference.

WolfPack 491 Posting Virtuoso Team Colleague

Well I took a look at your problem. Regarding the bisection-method looks as if you dont have an idea with what you are doing. I will give you a brief algorithm here and try to see if you can understand it and implement it.

Eq is x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x ) - L = 0 The idea of the bisectional method is to first find two values of x so that the left part of the above equation is positive for one of those values and negative for the other value.

If you take x = 0 as one of the values, by substituting x = 0 to the above equation, the left side will be equal to -L.

So now we have to find another value of x such that the left part of the equation is of opposite sign of -L.

To do this

for ( x = 1 ; x < INT_MAX; x++ )
{
       value = x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x )  - L ;
       if  ( ( (-L ) > 0 and value < 0 ) or ( ( (-L ) < 0 and value > 0 ) )
       {
             secondvalue = x ;
             break;
       }

	// Maybe -x has a value where the sign changes
	value = (-x)[ 1 + k1*n1/(1 + k1*(-x) ) …
Sulley's Boo commented: Wolfffyyyy wocks! +3
WolfPack 491 Posting Virtuoso Team Colleague

Okay. Got it. You are trying to open the same file twice.
Here are the culprits.

case CM_FILE_SAVE:
{
	//...
	HANDLE hFile;
	hFile = CreateFile( WindowText, GENERIC_READ, FILE_SHARE_READ, NULL,
				OPEN_EXISTING, 0, NULL );
	// This function is successfull only when there is a file of name WindowText.
	if ( hFile != INVALID_HANDLE_VALUE )
	{
		// YOu are here because hFile is valid. i.e the File is open.
		// Now you are calling save File. Go to the SaveFile now.
		if ( !SaveFile( hwnd, GetDlgItem( hwnd, IDC_CHILD_EDIT ), WindowText )) 
		{
			MessageBox( hwnd, "Could not save file", 0, MB_ICONERROR );
		}
	}
	else
	{
	//...
	}
}
BOOL SaveFile( HWND owner, HWND hEdit, LPCTSTR pszFileName )
{
	HANDLE hFile;

	// We are here because hFile was valid. ie a File of pszFileName is open already. But you call CreateFile again.

	// Try to create a file of name pszFileName...
	hFile = CreateFile( pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
				FILE_ATTRIBUTE_NORMAL, NULL );

	// But we had opened it before calling this function remember?
	// Therefore this hFile should be Invalid with Access Error.

	if ( hFile != INVALID_HANDLE_VALUE )
	{
		// Will not go here if the file exists...
	}
	else
	{
	}
	return bSuccess;
}

Did you get where you are going wrong? You can fix it with a crude fix like this.

case CM_FILE_SAVE:
{
	//...
	HANDLE hFile;
	hFile = CreateFile( WindowText, GENERIC_READ, FILE_SHARE_READ, NULL,
				OPEN_EXISTING, 0, NULL );
	// This function is successfull only when there is …
WolfPack 491 Posting Virtuoso Team Colleague

Narue's method should work. But I could not get it to compile in my machine. It needs Windows XP or higher.

Here is a small piece of code that resizes the window. But the dimensions should be specified in pixels, not by the number of characters as in Narue's method.

You can find a Screen Clearing Program in the Code Snippets section submited by vegaseat.

#if (_WIN32_WINNT < 0x0500) // This switch is needed to make the program compile
#undef _WIN32_WINNT	    // because GetConsoleWindow needs it. See Documentation
#define _WIN32_WINNT 0x0500 // for GetConsoleWindow in MSDN.
#endif

#include <windows.h> 
 
int main() 
{ 
	system( "pause" );

	// Get the window handle for Console Window
        HWND hwnd = GetConsoleWindow( );
	int newX		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newY		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newWidth	= 500;	// New Width in Pixels
	int newHeight	= 100;	// New Height in Pixels
	// Position the console window so that the left and right corners are not changed but the height and width are.
	SetWindowPos(hwnd, HWND_TOP, newX, newY, newWidth, newHeight, SWP_NOMOVE); // Using SWP_NOMOVE will cause newX and new Y to be ignored

	system( "pause" );

	return 0;
}
SpS commented: Nice Post:Sunny +1
WolfPack 491 Posting Virtuoso Team Colleague

maybe this will help.

SpS commented: Nice Link +1
WolfPack 491 Posting Virtuoso Team Colleague

Hi all,
I joined DaniWeb maybe two days back. And I was thinking of what to say about me, other than I am an alchoholic ( work ). Well I guess I can start off by saying that I do programming for a living and also for leisure. My area of programming is C and C++. Although I have been at it for some time, I cant seem to memorize anything , so I am always searching through to MSDN site. :cheesy: I am also interested in Linux. Hope we can help each other through this site.
Regards.
WolfPack