template<> 37 Junior Poster
bool isSame(double a, double b)
{
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
template<> 37 Junior Poster

34 is the right answer two minus becomes plus

http://wiki.answers.com/Q/Do_a_minus_and_a_minus_make_a_plus

template<> 37 Junior Poster

Why is it an unrealistic possiblity?

template<> 37 Junior Poster

But this code does not compile, so how could it effect your answer?

int main()
{
    int distance[15];
    distance = 0;
    return 0;
}
template<> 37 Junior Poster

similar to what you have, but max is not 2...

Also, personally, I would use a vector for input, less error prone...

#include <algorithm>
#include <ctime>

class MyRandom
{
public:
    ptrdiff_t operator() (ptrdiff_t max)
    {
        printf("max=%d-",(int)max);
        return rand()%max;
    }
};

int main () 
{
  srand ( unsigned ( time (NULL) ) );

  int numbers [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  int size = sizeof(numbers)/sizeof(int);

  MyRandom r;
  std::random_shuffle (numbers, numbers+size, r);

  return 0;
}
template<> 37 Junior Poster

use a printf to print max and show result

template<> 37 Junior Poster

ok, main calls random_shuffle,

where is the implementation of random_shuffle?

template<> 37 Junior Poster

max is most likely 2, because you must be passing 2

Code presented is incomplete, so its hard to figure out why.

template<> 37 Junior Poster

Stuff is always hard at first...

Take a stab at it, write some code to get started..

template<> 37 Junior Poster

What is your intent of distance=0?

You already initialized the contents of array.

Seem like you can just remove that statement.

void Graph::initialize()
{
for(int i=0;i<numOfVertices;i++) {
mark[i] = false;
predecessor[i] = -1;
distance[i] = INFINITY;
}
[B]distance = 0; //here is the problem...[/B]
}
template<> 37 Junior Poster

under Programs->Visual Studio->Tools there should be a Visual Studio Command Prompt

Selecting this should open a command prompt with the correct path settings

Then you can dumpbin from anywhere where ever your execuatble is located

template<> 37 Junior Poster

Depending on the input device used, most probably there is a start and end events generated. If so that would may be the cleanest solution to the problem.

template<> 37 Junior Poster

Perhaps an expression evaluator such as below...

http://www.arstdesign.com/articles/expression_evaluation.html

template<> 37 Junior Poster

Perhaps you can maintain state when a point is hit and only update when it changes.

template<> 37 Junior Poster

Perhaps a custom sort on the vector might solve your problem. See attached link for ideas

http://stackoverflow.com/questions/1380463/sorting-a-vector-of-custom-objects

template<> 37 Junior Poster

Most probably. Perhaps you only want to fire this code on the first mouse click (down or up) only.

template<> 37 Junior Poster

put a print statement before the for loop

printf("entering for loop...");

and see what happens...

template<> 37 Junior Poster

In that case its not clear what the problem is. Try to narrow it down and give us some sample code where the problem manifests itself.

template<> 37 Junior Poster

Do do not need to or want to put your executable in VC folder.

set the path to location of dumpbin (there should be a batch file that sets this path)

and run dumpbin on your executable where it is currently locationed

template<> 37 Junior Poster

What are the types for k and playerA.score, int?

template<> 37 Junior Poster

Please provide example

template<> 37 Junior Poster

Ok let design first; below is a high level description of the design, Depending on your needs you may want it differently, so feel free to take these thoughts and convert to your own. Try to picture each of the classes and the interactions in your mind until you’re one with the design. Adjust and tweak as needed.

Listener: This class listens to incoming client connections and creates an instance of Chatter for each connection. You already have implementation for Listener, try to encapsulate it in a class.

Chatter: This class sends and receives chat messages from each client. Once again you have the implementation, convert it into a class. Messages it receives are puts in a common Queue for distribution to other Chatters.

ChatApp: This is the main class that contains all the other classes and coordinates the interactions. ChatApp creates the Listener and has a list of IChatters. It also reads the Queue and distributes messages to all other Chatters.

IChatter: Interface to Chatter. The interface has a send method that ChatApp uses to distribute messages to other Chatters. Chatter class is derived from IChatter. (class Chatter: public IChatter)

Class IChatter
{
public:
   ~IChatter(){;}
   virtual void sendMessage(char *message_) = 0;
};

IChatApp: Interface to ChatApp used by Chatters to register and unregister them selves as they are created and destroyed. (class ChatApp:public IChatApp)

class IChatApp
{
public:
    ~IChatApp(){;}
        virtual void registerChatter(IChatter *chatter) = 0;  // add to list
        virtual void unregisterChatter( IChatter …
template<> 37 Junior Poster

ok, no c++

Do you know how to write a thread safe queue?

template<> 37 Junior Poster
template<> 37 Junior Poster

Are you familar with C++ and OO programming such as classes, objects etc?

template<> 37 Junior Poster

If you are permitted to do so, you can perhaps load your text file into a std::set and use that as your dictionary.

template<> 37 Junior Poster

This is an observer pattern problem. http://sourcemaking.com/design_patterns/observer Therefore you need an observer, which keeps a list of all dependents. When an update is received observer loops through and updates all dependents.

Using one thread per client is not going to scale very well if you intent to have many chatters. You may want to consider using IO completion ports in the windows platform (not trivial to implement) http://msdn.microsoft.com/en-us/magazine/cc302334.aspx. You also will simplify your problem by designing in terms of objects. (Chat, Listener, Observer, Connection etc)

For now lets assume one client one thread. A possible solution is as follows.

1. When client is created, register socket with observer
2. When client is terminated, unregister with observer
3. Each client thread reads message and places message in queue
4. The Observer waits for event in queue and when it receives message updates all dependents

Have fun, you will learn a lot if you can take this little project to completion!!!

template<> 37 Junior Poster

try it in c first, just for fun. Here is something to get you started, complete the function, use algorithm described by Narue..

char *reverse( char *input)
{



}
template<> 37 Junior Poster

Do you know how to program in c or c++??

template<> 37 Junior Poster
struct timeval { 
    unsigned long  tv_sec;   /* seconds since Jan. 1, 1970 */ 
    long           tv_usec;  /* and microseconds */ 
};
template<> 37 Junior Poster

C++ does name mangling to ensure method/function names are unique, C does not. So when calling C function from C++ you need to let C++ know it’s a C function. This can be done using the extern "C", read below for examples

extern "C" {
    #include "header.h"
}

http://yosefk.com/c++fqa/mixing.html

http://developers.sun.com/solaris/articles/mixing.html

JasonHippy commented: Great post! succinct, accurate and straight to the point! +9
template<> 37 Junior Poster
template<> 37 Junior Poster

Seems, fine, ensure you have the correct headers.

#include <vector>
#include <string>

int main()
{
    std::vector<std::string> TexName;
    TexName.push_back("mega.png");
    return 0;
}
template<> 37 Junior Poster

If you have a pointer to array, you can use it as an array...

int main()
{
        int a[]={1,2,3};
        int* p=a;
        int val=p[0];
}
template<> 37 Junior Poster

try using gettimeofday, will give you usec rather than seconds

sample code http://www.daniweb.com/software-development/cpp/threads/361138

template<> 37 Junior Poster

What input sequence causes core dump?
seems to work on my machine...

template<> 37 Junior Poster

1. Allocation means to create space for your application use
2. Initialize means to assign specific values to that space

Using malloc creates space, but contents of space undefined

template<> 37 Junior Poster
template<> 37 Junior Poster

Time critical application where context switching is a factor in building up latency as event goes through multiple transformations. Besides this is good information for all students, favorite Google interview question.

template<> 37 Junior Poster

Yielding CPU is not necessarily a context switch: control could be returned to the same context without remapping. I don't see anything forcing a switch.

The sample code gives a reliable lower bound of a system call/return though.

True if a single instance is run. However, if two instances are run simultaneously on a single core, since yield would occur before a thread quantum has expired and CPU is 100%, isn’t an implicit context switch expected? (ignoring all the other background process on the machine for now)

As indicated in the original post, on dual core simultaneously execution of 1 or 2 instances give an average of 0.5 usec, where as running three instance shows 1.3 usec.

A) The first case is mostly likely mostly function call overhead, since each process would have its own core and context switch is not required.

B) The second case, context switch would most likely occur frequently, which may explain the jump in time when 3 processes are running.

template<> 37 Junior Poster

Hello Community,

I am trying to figure a simple way approximate cost of context switching for a given OS/hardware combination under different loads.

For example on my 2 GHz dual core MAC OSX, running single instance clocks at 0.5 usec where as three instance at 1.3 usec. Below is sample, appreciate feedback, is this a valid approximation? If not why? Code below is compiled/tested on MAC OSX.

#include <iostream>
#include <sched.h>
#include <sys/time.h>

class Timer
{
public:
	Timer()
	{
	}
	void start()
	{
                gettimeofday(&_start, NULL);
	}
	double elapsed()
	{
		timeval stop;
                gettimeofday(&stop, NULL);

   		const int64_t USEC = 1000000;
		int64_t t1=_start.tv_sec*USEC+_start.tv_usec;
		int64_t t2=stop.tv_sec*USEC+stop.tv_usec;
		
		return (double)t2-t1;
	}
private:
	timeval _start;
};

void yield(int64_t loop)
{
    Timer timer;

    timer.start(); 

   for(int64_t i=0; i < loop; i++)
   {
         sched_yield();
   }

   double elapsed = timer.elapsed();

   double avg = elapsed/loop;

   std::cout << "yield loop=[" << loop << "] avg=[" << avg << "]" << std::endl;
}

int main(int argc, char *argv[])
{
        int64_t loop = 100000000;

        if( argc > 1 ) loop = atoi(argv[1]);

        yield(loop);
}
template<> 37 Junior Poster

If you reorganized, restructure and format you code so it easy to read and understand, it will simplify finding both logic and syntax problems. As your programs get larger, good code organization will save you lots of time and effort.

If I read correctly, line 31 is the end of main, so the rest of the code is just floating.

Comment your code from line 38 to end using /* and */ and recompile and fix and issues

Then incrementally move the comments and fix the problems.

template<> 37 Junior Poster

google c++ const

template<> 37 Junior Poster

Did you try to use a debugger to figure out what/where the problem is?

template<> 37 Junior Poster

I almost always disable the precompiled header, less problems in the long run.

template<> 37 Junior Poster

It returns the number of seconds since 1970, as you previously posted. It doesn't matter whether the parameter is NULL or not, it will always return the same value.

Although the c standard may be fuzzy on the topic, the posix standard appears to be more specific. Although exception are possible, common sense dictates if implementation didn’t follow convention, then interoperability is compromised; you’re both right, just looking at it from different perspectives.

http://en.wikipedia.org/wiki/Unix_time

http://vip.cs.utsa.edu/classes/cs3733/recitations/recB/usp302.pdf

template<> 37 Junior Poster

The code looks right but the linker is not seeing the definition, therefore the error. Another possible reason may be that client.cpp is not included in the visual studio project.

template<> 37 Junior Poster

What is not working??

template<> 37 Junior Poster

The simple sample below creates a similar error, if the definition of ~Client is missing. In your case althought the definition exists, the linker seems to not see it. When I get into this type of problem, I strip the code to its bare essentials and usually the problem becomes obvious.

class Client
{
public:
Client();
~Client();
};

Client::Client()
{
}

#ifdef MISSING
Client::~Client()
{
}
#endif
 
int main()
{
   Client c;
   return 0;
}
 
test2.obj : error LNK2019: unresolved external symbol "public: __thiscall Client::~Client(void)" (??1Client@@QAE@XZ) referenced in function _main
template<> 37 Junior Poster

Can we see the client.h and client.cpp code?