Solved

C++ Simulation Timer For ATM

Posted on 1997-05-05
6
892 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

749 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