hello_world_代碼的幽默_第1頁
hello_world_代碼的幽默_第2頁
hello_world_代碼的幽默_第3頁
hello_world_代碼的幽默_第4頁
hello_world_代碼的幽默_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、代碼的幽默:“Hello World”的若干編寫方式作者簡介:趙永華,男,威海職業(yè)學(xué)院信息工程系 高級工程師你是一名編程教師,學(xué)生上你的課特痛苦,他們抱怨說Coding枯燥乏味,此時你不妨讓他們試用一下如下編寫“Hello WORLD”程序的不同方式。你就等著瞧好吧!中學(xué)生:10 PRINT "HELLO WORLD"20 END大一:program Hello(input, output)beginwriteln('Hello World')end.大學(xué)高年級:(defun hello(print(cons 'Hello (list 'Wo

2、rld)見習(xí)程序員:#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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論