Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Test your skills (2005)
Index -> General Programming
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bugzpodder




PostPosted: Tue Jan 04, 2005 11:34 pm   Post subject: (No subject)

would you? here goes...
5 bits for each question... due date is whatever wtd has set
C++ questions
PM me the ans
for each question you get wrong, you get -5 bits hehe... if your final award is below 0 then it will count as 0. you can skip it at no penalty

1) What is the minimum/maximum integer value that you can store in a 32-bit signed integer? write in hexadecimal

2) what does ((((1<<5)+3)&(6))>>1)^5 evaluates to?

3) whats is 32ULL

4) when will the following code segment print "Hi".
int x;
cin>>x;
if (x) cout<<"Hello"<<endl; else cout<<"Hi"<<endl;
Sponsor
Sponsor
Sponsor
sponsor
Martin




PostPosted: Wed Jan 05, 2005 12:44 am   Post subject: (No subject)

I'm guessing I'm not allowed to answer, eh?
Andy




PostPosted: Wed Jan 05, 2005 7:56 am   Post subject: (No subject)

lol and me neither.. only question thats somewhat hard is the 32ull one
bugzpodder




PostPosted: Wed Jan 05, 2005 8:40 am   Post subject: (No subject)

mods can answer, you just wont get any bits.
rizzix




PostPosted: Wed Jan 05, 2005 3:13 pm   Post subject: (No subject)

Quote:
32ULL is an unsigned long long literal
he u should have asked whts 13ULL ^^
bugzpodder




PostPosted: Wed Jan 05, 2005 4:55 pm   Post subject: (No subject)

why 13?
rizzix




PostPosted: Wed Jan 05, 2005 5:16 pm   Post subject: (No subject)

or even simply 3, funny u get replays saying BULL
wtd




PostPosted: Wed Jan 05, 2005 10:19 pm   Post subject: (No subject)

For 30 bits, just to shake things up.

I have the following class in Ruby:

code:
class Foo
   def initialize(bar, baz)
      @bar, @baz = bar, baz
   end
end


Now, @bar and @baz are private, as all instance variables are in Ruby, but I can write methods which let me access those variables.

With only two additional lines of code add the ability to read and write to @bar, and read @baz.

If you use more than two lines, there will be no bits. Smile

Next question!

I have a Haskell function for multiplying an integer by two. Its type is:

code:
double :: Int -> Int


Without changing the name "double", write the shortest possible function definition. This is a 20 bit question.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Jan 07, 2005 9:26 pm   Post subject: Answer to the 1/1/2005 - 1/7/2005 question

Hikaru79 won 20 bits for answering correctly, and Cervantes and Tony merit an honorable mention for taking an interest.

Though:

code:
p [1, 2, 3].collect { |x| x * 2 }


And:

code:
p [1, 2, 3].collect do |x| x * 2 end


Are nearly identical, there is a difference in precendence. In the former, the block binds immediately to the "collect" method. In the latter, the block binds to the "p" method. The "p" method disregards the block, and the "collect" method, without a block, just returns the array.

As a result, the first is essentially equal to:

code:
p([1, 2, 3].collect { |x| x * 2 })


And the second:

code:
p([1, 2, 3].collect) do |x| x * 2 end


But as mentioned, p disregards the block, so it's essentially:

code:
p([1, 2, 3].collect)


And collect just returns the same array when it doesn't have a block, so we might as well have written:

code:
p([1, 2, 3])
wtd




PostPosted: Wed Jan 12, 2005 7:16 pm   Post subject: (No subject)

As for the C++ question:

Quote:
I write the following program and compile it with a modern C++ compiler (GCC 3.3):

code:
#include <iostream.h>

main()
{
   cout << "Hello world!" << endl;
}


It compiles and runs, but I've made four mistakes. Name them. 5 bits for each mistake.



  1. code:
    #include <iostream.h>


    Should be:

    code:
    #include <iostream>


    The "iostream.h" header is deprecated, and future compilers are not guaranteed to support it.
  2. "main" must be declared to return "int". This is mandated by the C++ standard. Using "void" does not conform to the standard. Operating systems rely on that integer being returned to determine whether the program ran successfully.
  3. I'm using "cout" and "endl" without either qualifying them as being in the "std" namespace, or including:

    code:
    using namespace std;

  4. In conjunction with number 2, I need to return zero to indicate the program finished successfully.
Andy




PostPosted: Wed Jan 12, 2005 7:18 pm   Post subject: (No subject)

so technically.. there are only two rite? 8)
wtd




PostPosted: Wed Jan 12, 2005 7:22 pm   Post subject: (No subject)

Quote:
Write a program which prompts for the user's name and accepts it on a single line, then greets the user in all caps. A sample run might look like:

code:
You are? Simon
HELLO SIMON!  SORRY FOR YELLING!!!


Reference material:

http://www.haskell.org
http://www.familygeek.com/haskell/tutorial.html


The answer could look like:

code:
module Main where

import IO
import Char

main :: IO ()
main = do
  putStr "You are? "
  hFlush stdout
  name <- getLine
  let greeting = "hello " ++ name ++ "!  sorry for yelling!!!"
  putStrLn $ map toUpper greeting
wtd




PostPosted: Wed Jan 12, 2005 7:23 pm   Post subject: (No subject)

Andy wrote:
so technically.. there are only two rite? 8)


No, there are four. Perhaps you could argue two and three are connected, but that's still at least three. Smile
Andy




PostPosted: Wed Jan 12, 2005 7:27 pm   Post subject: (No subject)

well.. i noe its unconventional, but if u put void infront of main, and add the .h to the iostream, then it would be fine
wtd




PostPosted: Wed Jan 12, 2005 7:41 pm   Post subject: (No subject)

Andy wrote:
well.. i noe its unconventional, but if u put void infront of main, and add the .h to the iostream, then it would be fine


It will compile, but it won't be fine. Neither is acceptable, according to the C++ standard.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 10  [ 147 Posts ]
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Jump to:   


Style:  
Search: