Solved

C++ Simulation Timer For ATM

Posted on 1997-05-05
6
882 Views
Last Modified: 2012-06-27
I want to run an ATM simulation. I am looking for code which will allow me to time-stamp cells (messages) at a source node and send these cells to a destination node. Ie: I'm looking for simple c++ code which will create a timer object and return time-stamps on invocation of some class method. The code should produce the same results on each run of the program.
0
Comment
Question by:CL050597
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:md041797
ID: 1163291
This uses the Win32 time system.  Any other system can be used in a similar way.

class TimeStamp {
public:
  TimeStamp () {StampIt();}
  void StampIt () {GetLocalTime (&TheStamp);}
  SYSTEMTIME &WhenStamped () {return TheStamp;}
private:
  SYSTEMTIME TheStamp;
  };

Good?
0
 

Author Comment

by:CL050597
ID: 1163292
If I were to use system time then my implimentation would be dependent on the CPU time of my computer. Ie: If my computer has 200 users vs 2 users then I will obtain different results each time I run my program. I want an implimentation which is  will give me the same results each time I run the program. This means that I have to come-up with a method which is independent of the system clock. Thanks for trying, but your solution is the obvious mistake, try again
0
 

Author Comment

by:CL050597
ID: 1163293
Edited text of question
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:md041797
ID: 1163294
Your problem is still vague.

When you say you want the same results every time you run the program are you saying you need a timer that starts from 0 every time the program starts up?

The routine I gave you uses the local time of day.  How would the time of day vary because you add more users?

When you say you want to send a message from one node to another, do you mean you want the system to communicate from one computer to another?  When you talk about a simulation, it sounds like you intend to run it as a single CPU process.

In short, what do you mean?




0
 

Author Comment

by:CL050597
ID: 1163295
Clarification: (1) If I were to have a timer which started at "0" that would be great! (2) If 2 users are using the same computer (cpu) then each would get about half of the cpu time; Thus, their programs would terminate faster than if 200 users were using this same computer (cpu). If 200 users were using the same computer then each would receive about 1/200 th of the cpu time; Thus, their programs would terminate (in real time) a lot slower.
Therefore, the 2 run times of the same program would would give different results. Eg: One run of the program would say this message took 1msec to reach destination, and another run would say the message took 0.5 msec to travel to the same destination.
(3) I want to run a WAN (wide area network) simulation on a single cpu, but "md's" 3rd question is irrelevent to the actual problem. Ie: I only want a timer and the application doesn't affect the timer, really!
0
 
LVL 4

Accepted Solution

by:
md041797 earned 50 total points
ID: 1163296
OK, so I think what you want is a timer class that will start at 0 on startup, and will give the same results regardless of the load on the system.

So, if I am assuming correctly (a dangerous proposition at best) this should work:


class TimeStamper {
public:
 double GetStamp {return difftime (clock(), TheStamp;}
private:
 static time_t TheStamp;
 };

TimeStamp::TheStamp = clock();


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now