hello_world_代码的幽默_第1页
hello_world_代码的幽默_第2页
hello_world_代码的幽默_第3页
hello_world_代码的幽默_第4页
hello_world_代码的幽默_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、代码的幽默:“Hello World”的若干编写方式作者简介:赵永华,男,威海职业学院信息工程系 高级工程师你是一名编程教师,学生上你的课特痛苦,他们抱怨说Coding枯燥乏味,此时你不妨让他们试用一下如下编写“Hello WORLD”程序的不同方式。你就等着瞧好吧!中学生:10 PRINT "HELLO WORLD"20 END大一:program Hello(input, output)beginwriteln('Hello World')end.大学高年级:(defun hello(print(cons 'Hello (list 'Wo

2、rld)见习程序员:#include <stdio.h>void main(void) char *message = "Hello ", "World" int i; for(i = 0; i < 2; +i) printf("%s", messagei); printf("n");资深程序员:#include <iostream.h>#include <string.h>class string private: int size; char *ptr; string(

3、) : size(0), ptr(new char1) ptr0 = 0; string(const string &s) : size(s.size)   ptr = new charsize + 1;  strcpy(ptr, s.ptr); string()   delete ptr; friend ostream &operator <<(ostream &, const string &); string &operator=(const char *);ostream &operator<

4、;<(ostream &stream, const string &s) return(stream << s.ptr);string &string:operator=(const char *chrs) if (this != &chrs)   delete ptr;  size = strlen(chrs);  ptr = new charsize + 1;  strcpy(ptr, chrs); return(*this);int main() string str; str = "He

5、llo World" cout << str << endl; return(0);程序员头目:uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)library LHello / bring in the master library importlib("actimp.tlb"); importlib("actexp.tlb"); / bring in my interfaces #include "pshlo.idl" uuid(2573F8F5-CFEE-101

6、A-9A9F-00AA00342820) cotype THello   interface IHello;  interface IPersistFile; ;exe,uuid(2573F890-CFEE-101A-9A9F-00AA00342820)module CHelloLib / some code related header files importheader(<windows.h>); importheader(<ole2.h>); importheader(<except.hxx>); importheader(&qu

7、ot;pshlo.h"); importheader("shlo.hxx"); importheader("mycls.hxx"); / needed typelibs importlib("actimp.tlb"); importlib("actexp.tlb"); importlib("thlo.tlb"); uuid(2573F891-CFEE-101A-9A9F-00AA00342820), aggregatable coclass CHello   cotype T

8、Hello; ;#include "ipfix.hxx"extern HANDLE hEvent;class CHello : public CHelloBase public: IPFIX(CLSID_CHello); CHello(IUnknown *pUnk); CHello(); HRESULT  _stdcall PrintSz(LPWSTR pwszString); private: static int cObjRef;#include <windows.h>#include <ole2.h>#include <stdi

9、o.h>#include <stdlib.h>#include "thlo.h"#include "pshlo.h"#include "shlo.hxx"#include "mycls.hxx"int CHello:cObjRef = 0;CHello:CHello(IUnknown *pUnk) : CHelloBase(pUnk) cObjRef+; return;HRESULT  _stdcall  CHello:PrintSz(LPWSTR pwszString) pr

10、intf("%ws ", pwszString); return(ResultFromScode(S_OK);CHello:CHello(void) / when the object count goes to zero, stop the server cObjRef-; if( cObjRef = 0 ) PulseEvent(hEvent); return;#include <windows.h>#include <ole2.h>#include "pshlo.h"#include "shlo.hxx"

11、#include "mycls.hxx"HANDLE hEvent;int _cdecl main(int argc,char * argv) ULONG ulRef; DWORD dwRegistration; CHelloCF *pCF = new CHelloCF(); hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); / Initialize the OLE libraries CoInitializeEx(NULL, COINIT_MULTITHREADED); CoRegisterClassObject(CLSID_

12、CHello, pCF, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwRegistration); / wait on an event to stop WaitForSingleObject(hEvent, INFINITE); / revoke and release the class object CoRevokeClassObject(dwRegistration); ulRef = pCF->Release(); / Tell OLE we are going away. CoUninitialize(); return(0

13、); extern CLSID CLSID_CHello;extern UUID LIBID_CHelloLib;CLSID CLSID_CHello = /* 2573F891-CFEE-101A-9A9F-00AA00342820 */ 0x2573F891, 0xCFEE, 0x101A, 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 ;UUID LIBID_CHelloLib = /* 2573F890-CFEE-101A-9A9F-00AA00342820 */ 0x2573F890, 0xCFEE, 0x101A, 0x9A, 0x9

14、F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 ;#include <windows.h>#include <ole2.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include "pshlo.h"#include "shlo.hxx"#include "clsid.h"int _cdecl main(int argc,char * argv) HRESULT  h

15、Rslt; IHello        *pHello; ULONG  ulCnt; IMoniker * pmk; WCHAR  wcsT_MAX_PATH; WCHAR  wcsPath2 * _MAX_PATH; / get object path wcsPath0 = '0' wcsT0 = '0' if( argc > 1)   mbstowcs(wcsPath, argv1, strlen(argv1) + 1);  wcsu

16、pr(wcsPath); else   fprintf(stderr, "Object path must be specifiedn");  return(1); / get print string if(argc > 2) mbstowcs(wcsT, argv2, strlen(argv2) + 1); else wcscpy(wcsT, L"Hello World"); printf("Linking to object %wsn", wcsPath); printf("Text Stri

17、ng %wsn", wcsT); / Initialize the OLE libraries hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(SUCCEEDED(hRslt)   hRslt = CreateFileMoniker(wcsPath, &pmk);  if(SUCCEEDED(hRslt)  hRslt = BindMoniker(pmk, 0, IID_IHello, (void *)&pHello);  if(SUCCEEDED(hRslt) &#

18、160;  / print a string out   pHello->PrintSz(wcsT);   Sleep(2000);   ulCnt = pHello->Release();    else  printf("Failure to connect, status: %lx", hRslt);  / Tell OLE we are going away.  CoUninitialize(); return(0);新黑客:#!/usr/local/bin/perl$msg="Hello, world.n"if ($#ARGV >= 0) while(defined($arg=shift(ARGV)   $outfilename = $arg;  open(FILE, ">" . $outfilename) | die "Can't write $arg: $!n"  print (FILE $msg);  close(FILE) | die "Can

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论