Computer Science Canada

Write a simple source code

Author:  jhooper3581 [ Fri Aug 28, 2009 7:25 am ]
Post subject:  Write a simple source code

Output: "C++ programming is fun!"

Write a C++ source code that will give the correct output given above

Author:  A.J [ Fri Aug 28, 2009 8:47 am ]
Post subject:  RE:Write a simple source code

c++:

#include<iostream>
using namespace std;

int main()
{
    cout << "C++ programming is fun!" << endl;
    return 0;
}

Author:  jhooper3581 [ Fri Aug 28, 2009 8:50 am ]
Post subject: 

Thanks for the reply!

Author:  saltpro15 [ Fri Aug 28, 2009 11:07 am ]
Post subject:  RE:Write a simple source code

an alternative

c++:

#include<cstdio>

main()
{
    printf ("C++ Programming is fun!");
    return 0;
}

Author:  bbi5291 [ Fri Aug 28, 2009 11:18 am ]
Post subject:  Re: Write a simple source code

Shortest code contest!
c++:

#import <cstdio>
main()
{
     return puts("C++ programming is fun!"),0;
}

Author:  wtd [ Fri Aug 28, 2009 11:55 am ]
Post subject:  Re: RE:Write a simple source code

saltpro15 @ Sat Aug 29, 2009 12:07 am wrote:
an alternative

c++:

#include<cstdio>

main()
{
    printf ("C++ Programming is fun!");
    return 0;
}


No return type for "main" is being bad. Also, if memory serves, the C++ standard says that main implicitly returns zero if no explicit return is coded.

Author:  A.J [ Fri Aug 28, 2009 1:22 pm ]
Post subject:  RE:Write a simple source code

How about we open a new thread for an obfuscated code contest?

Author:  bbi5291 [ Fri Aug 28, 2009 1:24 pm ]
Post subject:  Re: RE:Write a simple source code

wtd @ Fri Aug 28, 2009 11:55 am wrote:

No return type for "main" is being bad. Also, if memory serves, the C++ standard says that main implicitly returns zero if no explicit return is coded.


Fine then.
c++:

#import <cstdio>
int main()
{
     puts("C++ programming is fun!");
}

Author:  rdrake [ Fri Aug 28, 2009 2:01 pm ]
Post subject:  RE:Write a simple source code

Didn't the OP ask for C++ code?

Author:  Zren [ Fri Aug 28, 2009 2:06 pm ]
Post subject:  Re: Write a simple source code

Write a C++ source code that will give the correct output given above.

Mwahaha, never said it had to compile. I rename my empty source code file to "C++ programming is fun!.cpp".

None of your sass bout how the filename isn't actually the file itself either. >,<

Author:  saltpro15 [ Fri Aug 28, 2009 2:31 pm ]
Post subject:  Re: RE:Write a simple source code

A.J @ Fri Aug 28, 2009 wrote:
How about we open a new thread for an obfuscated code contest?


I'm on it.

Author:  bbi5291 [ Fri Aug 28, 2009 2:40 pm ]
Post subject:  Re: RE:Write a simple source code

rdrake @ Fri Aug 28, 2009 2:01 pm wrote:
Didn't the OP ask for C++ code?


It is C++. Try compiling it as C.

Author:  rdrake [ Fri Aug 28, 2009 3:48 pm ]
Post subject:  Re: RE:Write a simple source code

bbi5291 @ Fri Aug 28, 2009 2:40 pm wrote:
rdrake @ Fri Aug 28, 2009 2:01 pm wrote:
Didn't the OP ask for C++ code?


It is C++. Try compiling it as C.
You're using C functions and a C header file pretending it's C++ code. Just saying.

Sure you can compile C as C++, but why not use the C++ equivalents when available? After all, C++ is more than just "C with classes."

Author:  md [ Fri Aug 28, 2009 3:59 pm ]
Post subject:  RE:Write a simple source code

Just because you need the C++ compiler, doesn't mean it's C++. If you use C libraries for things like basic IO you're not writing C++.

Author:  bbi5291 [ Fri Aug 28, 2009 5:06 pm ]
Post subject:  Re: Write a simple source code

OP already received a satisfactory answer from posters before me. I was just having a bit of fun. As far as I am concerned, anything that compiles under a C++ compiler is C++. Even if you write it in machine code (this is actually possible, if you were wondering: char main[] = {...}; ). Obviously this goes against the spirit of writing a solution in C++, but oh well...

Author:  S_Grimm [ Fri Aug 28, 2009 9:34 pm ]
Post subject:  RE:Write a simple source code

I agree with bbi5291. If it compiles and runs under a C++ compiler, it can be considered C++ code. Even if it uses outdated header files and code. But hey, im not judgemental.

Author:  [Gandalf] [ Fri Aug 28, 2009 10:52 pm ]
Post subject:  RE:Write a simple source code

Come on now, arguing semantics has never gotten anyone anywhere.

If you're writing 90% inline assembly, I think we can all agree that, even if you consider that C++ code, it's definitely not idiomatic C++ code. Smile

Author:  saltpro15 [ Fri Aug 28, 2009 11:00 pm ]
Post subject:  RE:Write a simple source code

wow, this topic has come a long way from outputting "C++ Programming is fun!" Laughing

Author:  wtd [ Fri Aug 28, 2009 11:51 pm ]
Post subject:  Re: Write a simple source code

Not quite the message the OP wanted, but it is idiomatic.

c++:
#include <iostream>
#include <string>

class Greeter
{
    private:
        std::string name;

    public:
        Greeter(std::string n);

        const std::string get_name();

        friend std::ostream& operator<<(std::ostream& out, const Greeter& g);
};

int main()
{
    std::cout << Greeter("C++") << std::endl;
}

Greeter::Greeter(std::string n) : name(n)
{
}

const std::string Greeter::get_name()
{
    return name;
}

std::ostream& operator(std::ostream& out, const Greeter& g)
{
    return out << "Hello " << g.get_name();
}

Author:  rdrake [ Fri Aug 28, 2009 11:55 pm ]
Post subject:  Re: Write a simple source code

wtd @ Fri Aug 28, 2009 11:51 pm wrote:
Not quite the message the OP wanted, but it is idiomatic.

c++:
#include <iostream>
#include <string>

class Greeter
{
    private:
        std::string name;

    public:
        Greeter(std::string n);

        const std::string get_name();

        friend std::ostream& operator<<(std::ostream& out, const Greeter& g);
};

int main()
{
    std::cout << Greeter("C++") << std::endl;
}

Greeter::Greeter(std::string n) : name(n)
{
}

const std::string Greeter::get_name()
{
    return name;
}

std::ostream& operator(std::ostream& out, const Greeter& g)
{
    return out << "Hello " << g.get_name();
}
Now you're talking. Glad to see somebody knows how to write real C++ Laughing.

Author:  bbi5291 [ Sat Aug 29, 2009 10:21 am ]
Post subject:  Re: Write a simple source code

If that were real C++, then any sane C++ programmer would be using Java instead. But wait, that hasn't happened...

Author:  wtd [ Sat Aug 29, 2009 10:45 am ]
Post subject:  RE:Write a simple source code

It's showing you the power of using the << operator. And yes, that's real C++ code.

Author:  bbi5291 [ Sat Aug 29, 2009 10:52 am ]
Post subject:  Re: Write a simple source code

Of course, I didn't mean to assert that it's fake C++ code. What I meant is that if C++ is expected to look like that for such a simple program, nobody would ever use it to write such a program.

Author:  A.J [ Sat Aug 29, 2009 11:50 am ]
Post subject:  RE:Write a simple source code

Not here, not now.

This thread was merely used to answer jhooper3581's question. If you have anything else to discuss, do it elsewhere.

[No, I have every right to state my opinion. I am not suggesting that any action should be taken, just that I believe that they ought to take the conversation elsewhere.]

Author:  bbi5291 [ Mon Aug 31, 2009 9:24 am ]
Post subject:  Re: Write a simple source code

Just for fun.
c++:

#include <iostream>
using namespace std;
template<char c,class T>
struct lol
{
        lol()
        {
                cout << c;
                T x;
        }
};
int main()
{
        lol<'C',
        lol<'+',
        lol<'+',
        lol<' ',
        lol<'p',
        lol<'r',
        lol<'o',
        lol<'g',
        lol<'r',
        lol<'a',
        lol<'m',
        lol<'m',
        lol<'i',
        lol<'n',
        lol<'g',
        lol<' ',
        lol<'i',
        lol<'s',
        lol<' ',
        lol<'f',
        lol<'u',
        lol<'n',
        lol<'!',
        lol<'\n',
        int> > > > > > > > > > > > > > > > > > > > > > > > LOL;
        return 0;
}


: