




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高校实验室安全基础
- 护肤品新品课件
- 2024年CFA考试新变化试题及答案
- 山东省诸城第一中学春考部2024-2025学年高三上学期10月月考数学试题(原卷版)
- 英语 第四册(五年制高职)5课件 Unit5 Quality Assurance
- 武威一中2024-2025学年下学期高一年级开学检测地理试卷
- 太阳花绘画课件
- 江西省抚州市2024-2025学年高一上学期期末地理试题
- 2024年特许金融分析师考试重难点及答案
- 反复练习的重要性:CFA试题及答案
- DB37T 3651-2019 汽车加油站安全生产风险管控和隐患排查治理体系建设实施指南
- DB32-T 4340-2022 沥青红外光谱法相似度识别与SBS含量试验检测规程
- 《安全生产治本攻坚三年行动方案(2024-2026年)》子方案合集
- 职业道德试题及答案
- 《大模型原理与技术》全套教学课件
- 湖北省十一校2025届高三第一次联考 英语试卷(含答案)
- 生产异常处理流程
- 工程测量课件:GNSS测量原理与方法
- 微型消防站演练教学
- 老旧小区天然气管道改造施工方案
- 高压天然气管道氮气置换方案
评论
0/150
提交评论