[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C++ Simulation Timer For ATM

Posted on 1997-05-05
6
Medium Priority
?
901 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 100 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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