Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #9511 > unrolled thread

Am I not confident enuff to do this?

Started byHeck <heckja_in@ordertostymieharvestersverizon.net>
First post2011-08-30 16:31 -0400
Last post2011-09-12 03:31 +0200
Articles 16 — 14 participants

Back to article view | Back to comp.lang.c++


Contents

  Am I not confident enuff to do this? Heck <heckja_in@ordertostymieharvestersverizon.net> - 2011-08-30 16:31 -0400
    Re: Am I not confident enuff to do this? Paavo Helde <myfirstname@osa.pri.ee> - 2011-08-30 15:50 -0500
      Re: Am I not confident enuff to do this? Heck <heckja_in@ordertostymieharvestersverizon.net> - 2011-08-30 23:50 -0400
        Re: Am I not confident enuff to do this? Ian Collins <ian-news@hotmail.com> - 2011-08-31 16:00 +1200
          Re: Am I not confident enuff to do this? "Waldek M." <wm@localhost.localdomain> - 2011-08-31 18:43 +0200
      Re: Am I not confident enuff to do this? Juha Nieminen <nospam@thanks.invalid> - 2011-08-31 06:24 +0000
    Re: Am I not confident enuff to do this? hanukas <jukka@liimatta.org> - 2011-08-31 01:13 -0700
      Re: Am I not confident enuff to do this? Edek <edek.pienkowski@gmail.com> - 2011-08-31 22:55 +0200
    Re: Am I not confident enuff to do this? Krice <paulkp@mbnet.fi> - 2011-09-01 00:00 -0700
      Re: Am I not confident enuff to do this? "hugo_ribeira@hotmail.com" <hugo_ribeira@hotmail.com> - 2011-09-01 03:27 -0700
    Re: Am I not confident enuff to do this? James Kanze <james.kanze@gmail.com> - 2011-09-01 15:56 -0700
      Re: Am I not confident enuff to do this? red floyd <no.spam.here@its.invalid> - 2011-09-01 17:01 -0700
        Re: Am I not confident enuff to do this? Joe Greer <jgreer@doubletake.com> - 2011-09-02 15:34 +0000
          Re: Am I not confident enuff to do this? Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-02 10:47 -0500
    Re: Am I not confident enuff to do this? Daniel Bradley <daniel@bradley.mx> - 2011-09-07 14:58 +0000
    Re: Am I not confident enuff to do this? "Thomas J. Gritzan" <phygon_antispam@gmx.de> - 2011-09-12 03:31 +0200

#9511 — Am I not confident enuff to do this?

FromHeck <heckja_in@ordertostymieharvestersverizon.net>
Date2011-08-30 16:31 -0400
SubjectAm I not confident enuff to do this?
Message-ID<rchq57132mpjq7hc75ccb5ivcfin294vl5@4ax.com>
I was given a programming question on a tech test that made me doubt
myself.  It seemed too simple.  Did I miss something?  This is the
text of the question exactly as I got it:

Without defining any new variable or passing an argument to function,
I want you to be able to increment a number every time this method is
called. (Chose a language of your choice and write a fully compilable
method)

At the very least, this is a poorly framed question.  What number
should be incremented?  Where is it located, what is its scope and its
lifetime?  If I should create no new variables, how is this number to
come into existence?  Else, it must already be in existence and the
method I create has to be able to access it.  Such a combination of
characteristics is a static variable with file or class scope.  

Is this question for real, or did I really miss someting that will at
least make me feel stupid, or worse, reveal to me that I am stupider
than I allow for?                                         

TIA

[toc] | [next] | [standalone]


#9512

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-08-30 15:50 -0500
Message-ID<Xns9F51F274DC701myfirstnameosapriee@216.196.109.131>
In reply to#9511
Heck <heckja_in@ordertostymieharvestersverizon.net> wrote in 
news:rchq57132mpjq7hc75ccb5ivcfin294vl5@4ax.com:

> I was given a programming question on a tech test that made me doubt
> myself.  It seemed too simple.  Did I miss something?  This is the
> text of the question exactly as I got it:
> 
> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called. (Chose a language of your choice and write a fully compilable
> method)

#include <errno.h>
void f() {
    	++errno;
}

I believe this fully qualifies :-)

[toc] | [prev] | [next] | [standalone]


#9533

FromHeck <heckja_in@ordertostymieharvestersverizon.net>
Date2011-08-30 23:50 -0400
Message-ID<gibr57h6bgu8v9b254posmu39od3hce49f@4ax.com>
In reply to#9512
On Tue, 30 Aug 2011 15:50:03 -0500, Paavo Helde
<myfirstname@osa.pri.ee> wrote:

>Heck <heckja_in@ordertostymieharvestersverizon.net> wrote in 
>news:rchq57132mpjq7hc75ccb5ivcfin294vl5@4ax.com:
>
>> I was given a programming question on a tech test that made me doubt
>> myself.  It seemed too simple.  Did I miss something?  This is the
>> text of the question exactly as I got it:
>> 
>> Without defining any new variable or passing an argument to function,
>> I want you to be able to increment a number every time this method is
>> called. (Chose a language of your choice and write a fully compilable
>> method)
>
>#include <errno.h>
>void f() {
>    	++errno;
>}
>
>I believe this fully qualifies :-)

Thank you very much, I believe it does.  I like that yours is a
slightly impertinent answer, and, your answer answers my more personal
question concerning my confidence and lack thereof.  I was too
intimidated.  I raise my glass to the wise-ass.

[toc] | [prev] | [next] | [standalone]


#9535

FromIan Collins <ian-news@hotmail.com>
Date2011-08-31 16:00 +1200
Message-ID<9c5pu6F5dgU6@mid.individual.net>
In reply to#9533
On 08/31/11 03:50 PM, Heck wrote:
> On Tue, 30 Aug 2011 15:50:03 -0500, Paavo Helde
> <myfirstname@osa.pri.ee>  wrote:
>
>> Heck<heckja_in@ordertostymieharvestersverizon.net>  wrote in
>> news:rchq57132mpjq7hc75ccb5ivcfin294vl5@4ax.com:
>>
>>> I was given a programming question on a tech test that made me doubt
>>> myself.  It seemed too simple.  Did I miss something?  This is the
>>> text of the question exactly as I got it:
>>>
>>> Without defining any new variable or passing an argument to function,
>>> I want you to be able to increment a number every time this method is
>>> called. (Chose a language of your choice and write a fully compilable
>>> method)
>>
>> #include<errno.h>
>> void f() {
>>     	++errno;
>> }
>>
>> I believe this fully qualifies :-)
>
> Thank you very much, I believe it does.  I like that yours is a
> slightly impertinent answer, and, your answer answers my more personal
> question concerning my confidence and lack thereof.  I was too
> intimidated.  I raise my glass to the wise-ass.

Given the loose wording, how about

int f() { return 1+1; }

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#9570

From"Waldek M." <wm@localhost.localdomain>
Date2011-08-31 18:43 +0200
Message-ID<14z82ywojk4sg.dlg@localhost.localdomain>
In reply to#9535
On Wed, 31 Aug 2011 16:00:06 +1200, Ian Collins wrote:
>>>> Without defining any new variable or passing an argument to function,
>>>> I want you to be able to increment a number every time this method is
>>>> called. (Chose a language of your choice and write a fully compilable
>>>> method)

> Given the loose wording, how about
> 
> int f() { return 1+1; }

LOL!

Though I think it doesn't yet make it.

class F {int f() { return 1+1; } };  would.


Br.
Waldek

[toc] | [prev] | [next] | [standalone]


#9539

FromJuha Nieminen <nospam@thanks.invalid>
Date2011-08-31 06:24 +0000
Message-ID<4e5dd3ab$0$4380$7b1e8fa0@news.nbl.fi>
In reply to#9512
Paavo Helde <myfirstname@osa.pri.ee> wrote:
> Heck <heckja_in@ordertostymieharvestersverizon.net> wrote in 
> news:rchq57132mpjq7hc75ccb5ivcfin294vl5@4ax.com:
> 
>> I was given a programming question on a tech test that made me doubt
>> myself.  It seemed too simple.  Did I miss something?  This is the
>> text of the question exactly as I got it:
>> 
>> Without defining any new variable or passing an argument to function,
>> I want you to be able to increment a number every time this method is
>> called. (Chose a language of your choice and write a fully compilable
>> method)
> 
> #include <errno.h>
> void f() {
>        ++errno;
> }
> 
> I believe this fully qualifies :-)

  Technically speaking including <errno.h> declares a new variable, even
if this declaration is hidden inside that other file. If one would be
really pedantic, this would disqualify the solution.

  I'm not exactly sure what the original question wants.

[toc] | [prev] | [next] | [standalone]


#9544

Fromhanukas <jukka@liimatta.org>
Date2011-08-31 01:13 -0700
Message-ID<8c7f29fb-9ae0-4295-9715-a2930f21d1ff@i21g2000yqd.googlegroups.com>
In reply to#9511
On Aug 30, 11:31 pm, Heck
<heckja...@ordertostymieharvestersverizon.net> wrote:
> I was given a programming question on a tech test that made me doubt
> myself.  It seemed too simple.  Did I miss something?  This is the
> text of the question exactly as I got it:
>
> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called. (Chose a language of your choice and write a fully compilable
> method)
>
> At the very least, this is a poorly framed question.  What number
> should be incremented?  Where is it located, what is its scope and its
> lifetime?  If I should create no new variables, how is this number to
> come into existence?  Else, it must already be in existence and the
> method I create has to be able to access it.  Such a combination of
> characteristics is a static variable with file or class scope.  
>
> Is this question for real, or did I really miss someting that will at
> least make me feel stupid, or worse, reveal to me that I am stupider
> than I allow for?                                        
>
> TIA

The correct answer out in the real world would be: "Please specify
more exactly what you want to be done, sir."

[toc] | [prev] | [next] | [standalone]


#9577

FromEdek <edek.pienkowski@gmail.com>
Date2011-08-31 22:55 +0200
Message-ID<j3m79l$5mr$1@node2.news.atman.pl>
In reply to#9544
On 08/31/2011 10:13 AM, hanukas wrote:
> On Aug 30, 11:31 pm, Heck
> <heckja...@ordertostymieharvestersverizon.net>  wrote:
>> I was given a programming question on a tech test that made me doubt
>> myself.  It seemed too simple.  Did I miss something?  This is the
>> text of the question exactly as I got it:
>>
>> Without defining any new variable or passing an argument to function,
>> I want you to be able to increment a number every time this method is
>> called. (Chose a language of your choice and write a fully compilable
>> method)
>>
>> At the very least, this is a poorly framed question.  What number
>> should be incremented?  Where is it located, what is its scope and its
>> lifetime?  If I should create no new variables, how is this number to
>> come into existence?  Else, it must already be in existence and the
>> method I create has to be able to access it.  Such a combination of
>> characteristics is a static variable with file or class scope.
>>
>> Is this question for real, or did I really miss someting that will at
>> least make me feel stupid, or worse, reveal to me that I am stupider
>> than I allow for?
>>
>> TIA
>
> The correct answer out in the real world would be: "Please specify
> more exactly what you want to be done, sir."

I would say "void call_me() {}" and keep generating playful
  distractions when asked what I mean by that.

Profiling is the key to the answer. Good enough? Did I pass sir?

Edek

[toc] | [prev] | [next] | [standalone]


#9581

FromKrice <paulkp@mbnet.fi>
Date2011-09-01 00:00 -0700
Message-ID<490a688b-d474-4fe4-9060-01c3e7ad0630@bl1g2000vbb.googlegroups.com>
In reply to#9511
On 30 elo, 23:31, Heck <heckja...@ordertostymieharvestersverizon.net>
wrote:
> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called.

If you think that there must be a variable to increment then
it's a member variable:

void Inc() { m_variable++; }

No new variables were added or arguments passed.

[toc] | [prev] | [next] | [standalone]


#9596

From"hugo_ribeira@hotmail.com" <hugo_ribeira@hotmail.com>
Date2011-09-01 03:27 -0700
Message-ID<8b8591ca-ba78-45bc-a174-0cce84b90b45@m18g2000vbe.googlegroups.com>
In reply to#9581
class C
{
     int my_var_that_does_not_exist;
     public:
       void increment(){++my_var...;}

}

There you go, you didn't add any variable and you can increment it.

[toc] | [prev] | [next] | [standalone]


#9628

FromJames Kanze <james.kanze@gmail.com>
Date2011-09-01 15:56 -0700
Message-ID<58593d90-dfbc-47ce-b6a9-a0726f138ea4@l4g2000vbv.googlegroups.com>
In reply to#9511
On Aug 30, 9:31 pm, Heck
<heckja...@ordertostymieharvestersverizon.net> wrote:
> I was given a programming question on a tech test that made me doubt
> myself.  It seemed too simple.  Did I miss something?  This is the
> text of the question exactly as I got it:

> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called. (Chose a language of your choice and write a fully compilable
> method)

> At the very least, this is a poorly framed question.  What number
> should be incremented?  Where is it located, what is its scope and its
> lifetime?  If I should create no new variables, how is this number to
> come into existence?  Else, it must already be in existence and the
> method I create has to be able to access it.  Such a combination of
> characteristics is a static variable with file or class scope.

> Is this question for real, or did I really miss someting that will at
> least make me feel stupid, or worse, reveal to me that I am stupider
> than I allow for?

The wording of the qustion is atrocious, but perhaps what was
meant was something like:

    void incr( int& var )
    {
        ++ var;
    }

Or perhaps not; it's hard to say from the way the question is
formulated.

--
James Kanze

[toc] | [prev] | [next] | [standalone]


#9638

Fromred floyd <no.spam.here@its.invalid>
Date2011-09-01 17:01 -0700
Message-ID<j3p6de$e5a$1@dont-email.me>
In reply to#9628
On 9/1/2011 3:56 PM, James Kanze wrote:
> On Aug 30, 9:31 pm, Heck
> <heckja...@ordertostymieharvestersverizon.net>  wrote:
>> I was given a programming question on a tech test that made me doubt
>> myself.  It seemed too simple.  Did I miss something?  This is the
>> text of the question exactly as I got it:
>
>> Without defining any new variable or passing an argument to function,
>> I want you to be able to increment a number every time this method is
>> called. (Chose a language of your choice and write a fully compilable
>> method)
>
>> [redacted]
> The wording of the qustion is atrocious, but perhaps what was
> meant was something like:
>
>      void incr( int&  var )
>      {
>          ++ var;
>      }
>

Nope.  Doesn't meet the requirements.  Says no function arguments
allowed.


[toc] | [prev] | [next] | [standalone]


#9668

FromJoe Greer <jgreer@doubletake.com>
Date2011-09-02 15:34 +0000
Message-ID<Xns9F5475C8CDB86jgreerdoubletakecom@88.198.244.100>
In reply to#9638
red floyd <no.spam.here@its.invalid> wrote in news:j3p6de$e5a$1@dont-
email.me:

> On 9/1/2011 3:56 PM, James Kanze wrote:
>> On Aug 30, 9:31 pm, Heck
>> <heckja...@ordertostymieharvestersverizon.net>  wrote:
>>> I was given a programming question on a tech test that made me doubt
>>> myself.  It seemed too simple.  Did I miss something?  This is the
>>> text of the question exactly as I got it:
>>
>>> Without defining any new variable or passing an argument to function,
>>> I want you to be able to increment a number every time this method is
>>> called. (Chose a language of your choice and write a fully compilable
>>> method)
>>
>>> [redacted]
>> The wording of the qustion is atrocious, but perhaps what was
>> meant was something like:
>>
>>      void incr( int&  var )
>>      {
>>          ++ var;
>>      }
>>
> 
> Nope.  Doesn't meet the requirements.  Says no function arguments
> allowed.
> 
> 
> 

as the question is written,

void incr()
{
    ++1;
}

would work.  No, parameters, no new variables, increments a number every 
time, just doesn't persist it in any way.  :)

joe

[toc] | [prev] | [next] | [standalone]


#9671

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-09-02 10:47 -0500
Message-ID<Xns9F54BF3679FC7myfirstnameosapriee@216.196.109.131>
In reply to#9668
Joe Greer <jgreer@doubletake.com> wrote in 
news:Xns9F5475C8CDB86jgreerdoubletakecom@88.198.244.100:
> 
> as the question is written,
> 
> void incr()
> {
>     ++1;
> }
> 
> would work.  No, parameters, no new variables, increments a number every 
> time, just doesn't persist it in any way.  :)

There is just a small problem with this code: it doesn't compile... :)

[toc] | [prev] | [next] | [standalone]


#9904

FromDaniel Bradley <daniel@bradley.mx>
Date2011-09-07 14:58 +0000
Message-ID<296523083337100370.379066daniel-bradley.mx@news.optusnet.com.au>
In reply to#9511
Heck <heckja_in@ordertostymieharvestersverizon.net> wrote:
> I was given a programming question on a tech test that made me doubt
> myself.  It seemed too simple.  Did I miss something?  This is the
> text of the question exactly as I got it:
> 
> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called. (Chose a language of your choice and write a fully compilable
> method)
> 
> At the very least, this is a poorly framed question.  What number
> should be incremented?  Where is it located, what is its scope and its
> lifetime?  If I should create no new variables, how is this number to
> come into existence?  Else, it must already be in existence and the
> method I create has to be able to access it.  Such a combination of
> characteristics is a static variable with file or class scope.  
> 
> Is this question for real, or did I really miss someting that will at
> least make me feel stupid, or worse, reveal to me that I am stupider
> than I allow for?                                         
> 
> TIA

It's a stupid question.

The answer is probably something like incrementing the program counter in
assembler. Pedantically though any statement of any kind will also
increment the program counter... solving the problem... so again, stupid
question.

[toc] | [prev] | [next] | [standalone]


#10053

From"Thomas J. Gritzan" <phygon_antispam@gmx.de>
Date2011-09-12 03:31 +0200
Message-ID<j4jne9$j2h$1@newsreader4.netcologne.de>
In reply to#9511
Am 30.08.2011 22:31, schrieb Heck:
> I was given a programming question on a tech test that made me doubt
> myself.  It seemed too simple.  Did I miss something?  This is the
> text of the question exactly as I got it:
>
> Without defining any new variable or passing an argument to function,
> I want you to be able to increment a number every time this method is
> called. (Chose a language of your choice and write a fully compilable
> method)
>
> At the very least, this is a poorly framed question.

Quite poorly.

I guess the "without defining any new variable" is meant per call (or 
whatever), so a static variable would be ok:

int inc() {
    static int i = 0;
    return ++i;
}

But since they want a "fully compilable method", make a closure in a 
/compilable/ OOP language with closures.

-- 
Thomas

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web