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 WORLD20 END大一:program Hello(input, output)beginwriteln(Hello World)end.大学高年级:(defun hello(print(cons Hello (list World)见习程序员:#include void main(voi

2、d) char *message = Hello , World; int i; for(i = 0; i 2; +i) printf(%s, messagei); printf(n);资深程序员:#include #include class string private: int size; char *ptr; string() : size(0), ptr(new char1) ptr0 = 0; string(const string &s) : size(s.size) ptr = new charsize + 1; strcpy(ptr, s.ptr); string() del

3、ete ptr; friend ostream &operator (ostream &, const string &); string &operator=(const char *);ostream &operator(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, c

4、hrs); return(*this);int main() string str; str = Hello 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-101A-9A9F-0

5、0AA00342820) cotype THello interface IHello; interface IPersistFile; ;exe,uuid(2573F890-CFEE-101A-9A9F-00AA00342820)module CHelloLib / some code related header files importheader(); importheader(); importheader(); importheader(pshlo.h); importheader(shlo.hxx); importheader(mycls.hxx); / needed typel

6、ibs importlib(actimp.tlb); importlib(actexp.tlb); importlib(thlo.tlb); uuid(2573F891-CFEE-101A-9A9F-00AA00342820), aggregatable coclass CHello cotype THello; ;#include ipfix.hxxextern HANDLE hEvent;class CHello : public CHelloBase public: IPFIX(CLSID_CHello); CHello(IUnknown *pUnk); CHello(); HRESUL

7、T _stdcall PrintSz(LPWSTR pwszString); private: static int cObjRef;#include #include #include #include #include thlo.h#include pshlo.h#include shlo.hxx#include mycls.hxxint CHello:cObjRef = 0;CHello:CHello(IUnknown *pUnk) : CHelloBase(pUnk) cObjRef+; return;HRESULT _stdcall CHello:PrintSz(LPWSTR pws

8、zString) printf(%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 #include #include pshlo.h#include shlo.hxx#include mycls.hxxHANDLE hEvent;int _cdecl main(int argc

9、,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_CHello, pCF, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwRegistratio

10、n); / 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); extern CLSID CLSID_CHello;extern UUID LIBID_CHelloLib;CLSID CLSID_CHello

11、= /* 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, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 ;#include #include #include #include #

12、include #include pshlo.h#include shlo.hxx#include clsid.hint _cdecl main(int argc,char * argv) HRESULT hRslt; 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) +

13、1); wcsupr(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, LHello World); printf(Linking to object %wsn, wcsPath); printf(Text String %wsn, wcsT); / Initialize the OLE libraries hRslt

14、 = 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) / print a string out pHello-PrintSz(wcsT); Sleep(2000); ulCnt = pHello-Release(); else printf

15、(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 Cant write $arg: $!n; print (FILE $msg); close(FILE) | die Cant close $arg: $!n; else print ($msg);1;老黑客:#include #define S Hello, Worldnmain()exit(printf(S) = strlen(S) ? 0 : 1);职业黑客:% cc -o a.out /src/misc/hw/hw.c% a.out大师级黑客:% echo Hello, world.行政小组长:10 PRINT HELLO WORLD20 END中层行政管理:mail -s Hello, world. bobb12Bob, could you please write

温馨提示

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

评论

0/150

提交评论