Macam-macam Pemrogram dalam Menulis "Hello, World!" dalam Bahasa C/C++

Hasil gambar untuk pemrogramAN C++


Ini mengingatkan saya pada lelucon lama ini:

Evolusi Programer

Jenjang SMA / SMP

  1. 10 PRINT "HELLO WORLD"
  2. 20 END

Tahun Pertama di Perguruan Tinggi

  1. program Hello(input, output)
  2. begin
  3. writeln('Hello World')
  4. end.

Tingkat Akhir di Perguruan Tinggi

  1. (defun hello
  2. (print
  3. (cons 'Hello (list 'World))))

Baru Bekerja sebagai profesional

  1. #include
  2. void main(void)
  3. {
  4. char *message[] = {"Hello ", "World"};
  5. int i;
  6. for(i = 0; i < 2; ++i)
  7. printf("%s", message[i]);
  8. printf("\n");
  9. }

Berpengalaman sebagai professional

  1. #include
  2. #include
  3.  
  4. class string {
  5. private:
  6. int size;
  7. char *ptr;
  8. public:
  9. string() : size(0), ptr(new char('\0')) {}
  10. string(const string &s) : size(s.size) {
  11. ptr = new char[size + 1];
  12. strcpy(ptr, s.ptr);
  13. }
  14. ~string() {
  15. delete [] ptr;
  16. }
  17. friend ostream &operator <<(ostream &, const string &);
  18. string &operator=(const char *);
  19. };
  20.  
  21. ostream &operator <<(ostream &stream, const string &s) {
  22. return(stream << s.ptr);
  23.  
  24. }
  25.  
  26. string &string::operator=(const char *chrs) {
  27. if (this != &chrs) {
  28. delete [] ptr;
  29. size = strlen(chrs);
  30. ptr = new char[size + 1];
  31. strcpy(ptr, chrs);
  32. }
  33. return(*this);
  34. }
  35.  
  36.  
  37. int main() {
  38. string str;
  39. str = "Hello World";
  40. cout << str << endl;
  41. return(0);
  42. }

Programmer yang sudah Jago atau Menguasai

  1. [
  2. uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  3. ]
  4. library LHello
  5. {
  6. // bring in the master library
  7. importlib("actimp.tlb");
  8. importlib("actexp.tlb");
  9.  
  10. // bring in my interfaces
  11. #include "pshlo.idl"
  12.  
  13. [
  14. uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
  15. ]
  16. cotype THello
  17. {
  18. interface IHello;
  19. interface IPersistFile;
  20. };
  21. };
  22.  
  23. [
  24. exe,
  25. uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  26. ]
  27. module CHelloLib
  28. {
  29. // some code related header files
  30. importheader(<windows.h>);
  31. importheader(<ole2.h>);
  32. importheader(<except.hxx>);
  33. importheader("pshlo.h");
  34. importheader("shlo.hxx");
  35. importheader("mycls.hxx");
  36.  
  37. // needed typelibs
  38. importlib("actimp.tlb");
  39. importlib("actexp.tlb");
  40. importlib("thlo.tlb");
  41.  
  42. [
  43. uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
  44. aggregatable
  45. ]
  46. coclass CHello
  47. {
  48. cotype THello;
  49. };
  50. };
  51.  
  52.  
  53. #include "ipfix.hxx"
  54.  
  55. extern HANDLE hEvent;
  56.  
  57. class CHello : public CHelloBase
  58. {
  59. public:
  60. IPFIX(CLSID_CHello);
  61.  
  62. CHello(IUnknown *pUnk);
  63. ~CHello();
  64.  
  65. HRESULT __stdcall PrintSz(LPWSTR pwszString);
  66.  
  67. private:
  68. static int cObjRef;
  69. };
  70.  
  71.  
  72. #include
  73. #include
  74. #include
  75. #include
  76. #include "thlo.h"
  77. #include "pshlo.h"
  78. #include "shlo.hxx"
  79. #include "mycls.hxx"
  80.  
  81. int CHello::cObjRef = 0;
  82.  
  83. CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  84. {
  85. cObjRef++;
  86. return;
  87. }
  88.  
  89. HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString)
  90. {
  91. printf("%ws
  92. ", pwszString);
  93. return(ResultFromScode(S_OK));
  94. }
  95.  
  96.  
  97. CHello::~CHello(void)
  98. {
  99. // when the object count goes to zero, stop the server
  100. cObjRef--;
  101. if( cObjRef == 0 )
  102. PulseEvent(hEvent);
  103.  
  104. return;
  105. }
  106.  
  107. #include
  108. #include
  109. #include "pshlo.h"
  110. #include "shlo.hxx"
  111. #include "mycls.hxx"
  112.  
  113. HANDLE hEvent;
  114.  
  115. int _cdecl main(
  116. int argc,
  117. char * argv[]
  118. ) {
  119. ULONG ulRef;
  120. DWORD dwRegistration;
  121. CHelloCF *pCF = new CHelloCF();
  122.  
  123. hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  124.  
  125. // Initialize the OLE libraries
  126. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  127.  
  128. CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
  129. REGCLS_MULTIPLEUSE, &dwRegistration);
  130.  
  131. // wait on an event to stop
  132. WaitForSingleObject(hEvent, INFINITE);
  133.  
  134. // revoke and release the class object
  135. CoRevokeClassObject(dwRegistration);
  136. ulRef = pCF->Release();
  137.  
  138. // Tell OLE we are going away.
  139. CoUninitialize();
  140.  
  141. return(0);
  142. }
  143.  
  144. extern CLSID CLSID_CHello;
  145. extern UUID LIBID_CHelloLib;
  146.  
  147. CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
  148. 0x2573F891,
  149. 0xCFEE,
  150. 0x101A,
  151. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  152. };
  153.  
  154. UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
  155. 0x2573F890,
  156. 0xCFEE,
  157. 0x101A,
  158. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  159. };
  160.  
  161. #include
  162. #include
  163. #include
  164. #include
  165. #include
  166. #include "pshlo.h"
  167. #include "shlo.hxx"
  168. #include "clsid.h"
  169.  
  170. int _cdecl main(
  171. int argc,
  172. char * argv[]
  173. ) {
  174. HRESULT hRslt;
  175. IHello *pHello;
  176. ULONG ulCnt;
  177. IMoniker * pmk;
  178. WCHAR wcsT[_MAX_PATH];
  179. WCHAR wcsPath[2 * _MAX_PATH];
  180.  
  181. // get object path
  182. wcsPath[0] = '\0';
  183. wcsT[0] = '\0';
  184. if( argc > 1) {
  185. mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
  186. wcsupr(wcsPath);
  187. }
  188. else {
  189. fprintf(stderr, "Object path must be specified\n");
  190. return(1);
  191. }
  192.  
  193. // get print string
  194. if(argc > 2)
  195. mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  196. else
  197. wcscpy(wcsT, L"Hello World");
  198.  
  199. printf("Linking to object %ws\n", wcsPath);
  200. printf("Text String %ws\n", wcsT);
  201.  
  202. // Initialize the OLE libraries
  203. hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  204.  
  205. if(SUCCEEDED(hRslt)) {
  206. hRslt = CreateFileMoniker(wcsPath, &pmk);
  207. if(SUCCEEDED(hRslt))
  208. hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
  209. if(SUCCEEDED(hRslt)) {
  210. // print a string out
  211. pHello->PrintSz(wcsT);
  212. Sleep(2000);
  213. ulCnt = pHello->Release();
  214. }
  215. else
  216. printf("Failure to connect, status: %lx", hRslt);
  217.  
  218. // Tell OLE we are going away.
  219. CoUninitialize();
  220. }
  221. return(0);
  222. }

 

Evolusi seorang Hacker

Hacker yang sedang Magang

  1. #!/usr/local/bin/perl
  2. $msg="Hello, world.\n";
  3. if ($#ARGV >= 0) {
  4. while(defined($arg=shift(@ARGV))) {
  5. $outfilename = $arg;
  6. open(FILE, ">" . $outfilename) || die "Can't write $arg: $!\n";
  7. print (FILE $msg);
  8. close(FILE) || die "Can't close $arg: $!\n";
  9. }
  10. } else {
  11. print ($msg);
  12. }
  13. 1;

Hacker yang Sudah berpengalaman

  1. #include
  2. #define S "Hello, World\n"
  3. main(){exit(printf(S) == strlen(S) ? 0 : 1);}

  1. % cc -o a.out ~/src/misc/hw/hw.c
  2. % a.out

Hacker yang Sudah Jago Banget

  1. % cat
  2. Hello, world.
  3. ^D

 

Evolusi seorang Manajer

Manajer Pemula

  1. mail -s "Hello, world." bob@b12
  2. Bob, could you please write me a program that prints "Hello, world."? I need it by tomorrow.
  3. ^D

Manajer Berpengalaman

  1. % zmail bill
  2. I need a "Hello, world." program by this afternoon.

Ketua Pelaksana


  1. C:\\% letter
  2. letter: Command not found.
  3. C:\\% mail
  4. To: ^X ^F ^C
  5. C:\\% help mail
  6. help: Command not found.
  7. C:\\% damn!
  8. !: Event unrecognized
  9. C:\\% jim come over here right now!


Banyak bangetkan macam-macamnya hahahah

Kamu termasuk golongan yang mana ? 




translate : Richard Liu

Teguh Tri Sasongko

Menasihati diri sendiri merupakan salah satu tugas yang tersulit. Karena yang akan melawan nasihat tersebut, adalah diri sendiri.

Lebih baru Lebih lama

Formulir Kontak