Counting the number of times I've tested a program

P

pauldepstein

How do I count the number of times I tested a program?

My first attempt was this:

#include <iostream>

using namespace std;

int main()
{
static int times_tested = 0;

times_tested ++;

cout << times_tested;

system("PAUSE"); // Yeah, I know the experts don't like "PAUSE"
but blame my // teacher

}

Obviously, it doesn't work -- the static times_tested retains its value
outside the loop but, of course, it doesn't remember the value after
the program has finished completely.

It seems that I need a sort of extremely-static designation which not
only retains the value after the loop but even after the program has
run.

Is there a way of doing this?

Thank you,

Paul Epstein
 
O

osmium

How do I count the number of times I tested a program?

My first attempt was this:

#include <iostream>

using namespace std;

int main()
{
static int times_tested = 0;

times_tested ++;

cout << times_tested;

system("PAUSE"); // Yeah, I know the experts don't like "PAUSE"
but blame my // teacher

}

Obviously, it doesn't work -- the static times_tested retains its value
outside the loop but, of course, it doesn't remember the value after
the program has finished completely.

It seems that I need a sort of extremely-static designation which not
only retains the value after the loop but even after the program has
run.

Is there a way of doing this?

I would create a data file with a single variable containing say n_tests. I
would always increment that variable and close the file as soon as possible
after I started execution. If you save the value with the '<<' operator,
you can read the file with Notepad.
 
J

JustBoo

How do I count the number of times I tested a program?

Good advice has been given. As your program evolves, I suspect you'll
want to know more and more about what your program is doing. This is
where a "Log File" comes in quite handy. You can even use it to debug
your program. A simple usage is to output various state variables
while the program runs.

Google on: iostreams log file. I received 19,700 hits.

Good Luck.
 
N

Neil Cerutti

How do I count the number of times I tested a program?
It seems that I need a sort of extremely-static designation
which not only retains the value after the loop but even after
the program has run.

I just wanted to note that I found your idea of adding 'extremely'
to the list of C++ keywords to be an amusing idea. It made me
chuckle. Thanks!

class Person
{
extremely private:
PersonalInformation *pi;
/* etc... */
};

void foo()
{
extremely const int zero = 0;
/* etc... */
{


void bar()
{
/* etc... */
switch (she.loves(me))
{
case true: me.happy(); break;
case false: me.unhappy(); break;
case extremely false: me.listen(music("The Cure")); break;
}
}
 
P

pauldepstein

The idea of adding "extremely" to the list of key words, despite being
amusing to you, is not at all a silly or ridiculous idea. Indeed,
there's no reason the language could not have been written that way.

Classes could have been designated public, private, extremely private
instead of public, protected, and private.

There could also be three integer types: short int, long int, and
extremely long int.

You wouldn't be finding the concept so hilarious if the evolution of
c++ had been very slightly different.

Paul Epstein
 
J

JustBoo

Classes could have been designated public, private, extremely private
instead of public, protected, and private.

Okay, I will take the bait. What would extremely private do that
private doesn't already do?

I'd go for a "final" keyword, for sure. (So your class could/should
not be derived from.)
There could also be three integer types: short int, long int, and
extremely long int.

The first 2 already exist, at least for me and my compilers. I thought
the last one was long long.
You wouldn't be finding the concept so hilarious if the evolution of
c++ had been very slightly different. >Paul Epstein

A butterfly flapping it's wings in China *could* cause a really severe
paper-cut in America. Um... yeah.
 
R

red floyd

JustBoo said:
Okay, I will take the bait. What would extremely private do that
private doesn't already do?

Here's my take on it:

Your friends can access your private data, but not your extremely
private data. Similarly, extremely const data could not have const
casted away.
 
J

JustBoo

Here's my take on it:

Your friends can access your private data, but not your extremely
private data. Similarly, extremely const data could not have const
casted away.

Hmm... okay. Good for library authors and such?

To paraphrase one of the old-time regulars here: "You can either
change your code or change the programmer." :)

I've found if really determined and/or dumb people want to be evil
there isn't much you can do to stop them. I had a fairly heated
exchange with a guy who didn't want to "fill-in" the virtual functions
he had inherited from a base class so he went into SourceSafe and
changed the base class so they would not be virtual. <sigh> To hell
with everyone else, I guess.

But sure why not. :)

"I like a man who grins when he fights." - Winston Churchill
 
B

Bob Hairgrove

The idea of adding "extremely" to the list of key words, despite being
amusing to you, is not at all a silly or ridiculous idea. Indeed,
there's no reason the language could not have been written that way.

But then it wouldn't be the C++ that we all know and love ... or would
it??
Classes could have been designated public, private, extremely private
instead of public, protected, and private.
There could also be three integer types: short int, long int, and
extremely long int.

According to the C++ standard, there are already more integral types
than that, even without "extremely...":

bool
char
short
long
long long
and just plain old int (... not to forget the unsigned types!)
You wouldn't be finding the concept so hilarious if the evolution of
c++ had been very slightly different.

Paul Epstein

[Is this a troll? Does a bear sh*t in the woods? Oh well...]

What about "wantonly public / extremely public / public / somewhat
protected / protected / extremely protected / rather private / private
/ extremely private / paranoid / extremely paranoid / psychotically
paranoid / ..."

What about friends? We would have to re-classify friend access as
well:

partner for life
one and only very best friend
very best friend
best friend
great buddy
friend
friend of the boss
good acquaintance
passing acquaintance
(etc.)

You have to draw the line somewhere...I think I'll stick with the
available options as we have them today.
 
J

Jim Langston

red floyd said:
Here's my take on it:

Your friends can access your private data, but not your extremely private
data. Similarly, extremely const data could not have const casted away.

Well, of course you could extremely_const_cast it away...
 
P

puzzlecracker

use small trick; I will give you a backbone and you built upn it

std::string filename="test.out"
class TestingCounter: public boost:: Synchronized{
private:
long counter;
public:
explicit TestCounter(const string &):Synchronized(filename){

Synchronized::clearWrite( Synchronized::readLong()+1);
}

}testCounterUtility;


int main (int argc, char* [] argv)
{



}


I suggest to re-write above using singleton patter;
 
J

JustBoo

Or supremely_const.
elaborately_const?
excessively_const?
-Mike

Maybe we can get CUJ to come back from the dead to cover the New C++
MAD (Mutually Assured Destruction) Features Race. They could show the
carnage. There might be an actual nose-bleed. "If it bleeds it leads
baby."

Hey, watch out or I'll whip out my
monster_uber_overlord_tell_your_mommy_const_destructor_detonator
in a heartbeat jack!

No offense to anyone I'm just being a goof-nuat. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top