Solved

C++ Simulation Timer For ATM

Posted on 1997-05-05
6
888 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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.

813 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

14 Experts available now in Live!

Get 1:1 Help Now