版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、会计学1面向对象程序设计与面向对象程序设计与VC 实践习题答案实践习题答案#include #include /#include void main() int i,j,a55=1; /第一行第一列赋值第一行第一列赋值1,其他为,其他为0 for(i=1;i5;i+) ai0=1; /第一列全置为第一列全置为1 for(j=1;j=i;j+) aij=ai-1j-1+ai-1j; /每个数是上面两数之和每个数是上面两数之和 for(i=0;i5;i+) /输出杨辉三角输出杨辉三角 coutsetw(5-i) ;/for(j=0;j5-i;j+) printf( );for(j=0;j=i;j+
2、) /只输出只输出a55的下三角的下三角 coutsetw(2)aij; /printf(%2d, aij);coutendl; 方法一方法一1000011000121001331014641第1页/共84页#include #include /#include void main() int i,j,a55; for(i=0;i5;i+) ai0=1; aii=1; /第一列、对角全置为第一列、对角全置为1 for(j=1;ji;j+) aij=ai-1j-1+ai-1j; /每个数是上面两数之和每个数是上面两数之和 for(i=0;i5;i+) /输出杨辉三角输出杨辉三角 coutsetw
3、(5-i) ;/for(j=0;j5-i;j+) printf( );for(j=0;j=i;j+) /只输出只输出a55的下三角的下三角 coutsetw(2)aij; /printf(%2d, aij);coutendl; 方法一变形方法一变形111121133114641第2页/共84页#include void main() int a59,i,j;for(i=0;i5;i+) for(j=0;j9;j+) aij=0;/所有元素赋值所有元素赋值0for(i=0;i5;i+) /左右两斜边赋值左右两斜边赋值1 ai4-i=1; ai4+i=1; for(i=2;i1;j-)aij=ai
4、-1j-1+ai-1j+1;for(i=0;i5;i+) for(j=0;j9;j+) if(aij=0)cout ; /值为值为0的元素输的元素输出为空格出为空格 elsecoutaij; coutendl; 方法二方法二000010000000101000001020100010303010104060401第3页/共84页#include #define N 5void main() int i,j,aNN; aNN=1,1,1; for(i=2;iN;i+) ai0=1; aii=1; for(j=1;j=i;j+) aij=ai-1j-1+ai-1j; for(i=0;iN;i+)
5、for(j=0;j20-2*i;j+) printf( ); for(int k=0;k=i;k+) printf(%d, aik);/正确为:正确为:printf(%4d, aik); printf(n); 错误答案错误答案第4页/共84页#include void main( )int a6=1,7,3,7,22,9;int i,j,t,flag;int m=6,n;n=m;/n控制输出不同的元素个数控制输出不同的元素个数/删除相同元素删除相同元素for(i=0;im;i+)for(j=i+1;jn;j+)if(ai=aj)for(int k=j;kn;k+)ak=ak+1;/前移前移n-
6、;j-;/冒泡排序冒泡排序 for(i=0;in;i+) flag=0;for(j=0;jn-i-1;j+)if(ajaj+1) t=aj; aj=aj+1; aj+1=t; flag=1;if(flag=0) break;cout排序后的数组为:排序后的数组为:n;for(i=0;in;i+) cout ain;第5页/共84页#include #include void main() char a8=agbbcc;char t; int i,j;for(i=0;i8;i+) for (j=0;ji;j+)if (ai=aj) ai=0;for(i=0;i8;i+) coutsetw(2)a
7、iendl;for(i=0;i8;i+) for (j=i+1;j8;j+) if (aiaj) t=ai;ai=aj;aj=t; for(i=0;i8;i+) coutai, endl; 第6页/共84页#include void main( )int a10=1,2,1,4,1,6,9,6,7,6;int i,j,t,flag,b10;/冒泡排序冒泡排序 for(i=0;i10;i+) flag=0;for(j=0;j10-i-1;j+)if(ajaj+1) t=aj; aj=aj+1; aj+1=t; flag=1;if(flag=0) break;t=0; /删除相同元素删除相同元素f
8、or(i=0;i9-t;i+) if(ai=ai+1) for(j=i+1;j10-t;j+) aj-1=aj; t+; / 当相同元素多于当相同元素多于2个时出错个时出错cout排序后的数组为:排序后的数组为:n;for(i=0;i10-t;i+) cout ain;错误答案错误答案/删除相同元素删除相同元素b0=a0;j=0;for(i=1;i10;i+) if(ai!=bj) bj+1=ai;j+; / / 或或 i f ( a i ! = a i - 1 ) bj+1=ai;j+;/或或if(aj!=ai) aj+1=ai;j+; /相邻元素相等则删除一个相邻元素相等则删除一个第7页/
9、共84页#includeint cmps(char *p,char *q);void main() char s1128,s2128;cins1;cins2;coutcmps(s1,s2)cmps(s1,s2);int cmps(char *p,char *q) for(;*p!=0&q!=0;p+,q+) if(*p!=*q) break; return(*p-*q);int cmps(char *p,char *q)for(;*p=*q&*p!=0&*q!=0;p+,q+); return(*p-*q);int cmps(char *p,char *q)while(*p=*q)p+;q+;
10、return(*p-*q);第8页/共84页第9页/共84页第10页/共84页#include class Son int age; public: Son() age=1; Son(int i) age=i; void print() cout儿子的年龄是:儿子的年龄是:ageendl; ;class Father int age;Son s1,s2;/类的组合类的组合public:F a t h e r ( i n t a 1 , i n t a 2 , i n t f):s2(a2),s1(a1) age=f; void print() c o u t “ 父 亲 的 年 龄 是 :父
11、亲 的 年 龄 是 : ageendl; Son &gets1() cout第一个第一个; return s1; Son &gets2() cout第二个第二个; return s2; ;void main()Father f(10,5,38);f.print();f.gets1().print();f.gets2().print();父亲的年龄是:父亲的年龄是:38第一个儿子的年龄是:第一个儿子的年龄是:10第二个儿子的年龄是:第二个儿子的年龄是:5第11页/共84页(2) 程序代码如下:程序代码如下:第12页/共84页n,姓名:stumax.get_name()endl;nc o u t
12、最 小 年 龄 :stumin.get_age()n,姓名:stumin.get_name()endl;nn程序运行结果为:最大年龄:最大年龄:19,姓名:吴伟,姓名:吴伟最小年龄:最小年龄:17,姓名:李丽,姓名:李丽第13页/共84页nn;(3)下列程序实现的是堆栈的压入和弹出。其中有两个类,一个下列程序实现的是堆栈的压入和弹出。其中有两个类,一个是结点类,它包含结点值和指向上一结点的指针;另一个类是是结点类,它包含结点值和指向上一结点的指针;另一个类是堆栈类,数据成员为堆栈的头指针,它是结点类的友员。试分堆栈类,数据成员为堆栈的头指针,它是结点类的友员。试分析程序,并说明堆栈的压入和弹出
13、过程。析程序,并说明堆栈的压入和弹出过程。第14页/共84页分析:实现了输入的顺序与输出的顺序相反分析:实现了输入的顺序与输出的顺序相反第15页/共84页nvoid decrement();/给原值减1nint getvalue();/取得计数值nvoid display();/显示计算器值n;第16页/共84页#include class counterint value;public:counter(int number);void increment();/给给原值加原值加lvoid decrement();/给给原值减原值减1int getvalue(); /取得计数值取得计数值voi
14、d display(); /显示计算器显示计算器值值;counter:counter(int number) value=number;void counter:increment() value+;void counter:decrement() value-;int counter:getvalue() return value;void counter:display() coutvalue=valueendl;void main()counter counter1(99);counter1.increment();/+counter1.increment(); /+counter1.d
15、ecrement(); /-counter1.display();第17页/共84页#include iostream.h#include string.h#include iomanip.hconst int N=5;class personchar name10;char num10;public:void getdata( )strcpy(name,na);strcpy(num,nu);void outdata(person pnN);void person:outdata(person pnN) int i;for(i=0;iN;i+)cout.width(10); cout.widt
16、h(10); void main() char *na5=li,zh,li,zh,li; char*nu5=01,02,03,04,05;person obj5;/对象数组对象数组for(int i=0;i5;i+)obji.getdata(nai,nui); *pt=obj; ; char* na,char* nu或:或:char na,char nu endl; coutpni.numoutdata(pt) ;或:或:pt-outdata(obj) ;第18页/共84页#include #include class Rectangleint X1,Y1,X2,Y2;
17、 public:Rectangle(int x1,int y1,int x2,int y2)X1=x1; Y1=y1; X2=x2; Y2=y2;int Area();int Rectangle:Area() return fabs(X2-X1)*(Y2-Y1); void main() Rectangle A(10,20,30,50); cout面积为面积为A.Area()endl; 第19页/共84页#include class complex/复数类声明复数类声明double real; double imag;public:complex(double r=0.0,double i=0
18、.0) /构造函数构造函数 real=r;imag=i;complex(complex &c) /拷贝构造函数拷贝构造函数 real=c.real;imag=c.imag;void display()/显示复数的值显示复数的值cout“实部为实部为:”real“虚部为虚部为:imagendl;void main() complex A;A.display(); complex B(2,3);B.display(); complex C(B);C.display();第20页/共84页#include const float PI = 3.14159;/define PI 3.14159clas
19、s circle/类声明类声明double radius;public:circle(double r=0.0) radius=r; /构造函数构造函数double area() return PI*radius*radius;void main() circle A(5); circle B(8);cout圆环面积圆环面积B.area()-A.area()endl; 第21页/共84页#include #include class string/类声明类声明 int length;char *contents; public:string() length=0;contents=0;stri
20、ng(const char *str); /构造函数构造函数void display() const;/显示值显示值void getlength();void append(const char *tail);string:string(const char *str)length=strlen(str); contents=new charlength+1;strcpy(contents,str);第22页/共84页void string:display() const/显示显示 if(contents=0)coutempty.n; elsecout字符串的内容为字符串的内容为content
21、sendl;void string:getlength()/获取长度获取长度length=strlen(contents);cout字符串的长度为字符串的长度为lengthendl;void string:append(const char *tail)/连接连接char *tmp; length+=strlen(tail); tmp=new charlength+1; strcpy(tmp,contents); strcat(tmp,tail); delete contents; contents=tmp;void main()string s0,s1(a string);s0.displa
22、y();s1.display();s1.getlength();string s2(this );s2.append(a string);cout连接的连接的;s2.display();第23页/共84页#include class Catstatic int HowManyCat;/引用性说明引用性说明public: Cat() HowManyCat+; Cat() HowManyCat-; static void Get_HowManyCat() cout总数总数:HowManyCatendl;int Cat:HowManyCat=0; /定义性说明定义性说明void main()Cat
23、f1; Cat:Get_HowManyCat(); Cat f2; f2.Get_HowManyCat(); f1.Cat(); Cat:Get_HowManyCat();第24页/共84页struct Node int data;Node *next; ;class ListNode *head; public:List() head=NULL; void InsertList(int aData,int bData);/链表结点的插入链表结点的插入void DeleteList(int aData);/链表结点的删除链表结点的删除void OutputList();/链表结点的输出链表结点
24、的输出Node *Gethead() return head; Node *reverse(Node *head);void List:OutputList()/链表输出函数链表输出函数Node *current=head;while (current!=NULL) coutdatanext;cout next; / q指向指向2号号 while (q!=NULL) r = q- next; / r指向指向3号号 q- next = p; / 2号的号的next指向指向1号号 p = q; / p指向指向2号号 q = r; / q指向指向3号号 head- next = NULL; / 1号
25、的号的next指向指向NULL, head = p; / 循环结束之后,循环结束之后,p指向原来的末结点,现在是头指向原来的末结点,现在是头结点结点 return head; / 返回头结点返回头结点 第26页/共84页第27页/共84页#include class B int x1,x2; public: void Init(int n1,int n2) x1=n1;x2=n2; int inc1() return +x1; int inc2() return +x2; void disp() coutB,x1=x1,x2=x2endl;第28页/共84页第29页/共84页B,x1=-2,x
26、2=-2D1,x3=3D2,x4=6D2,x4=6D2,x4=6void main()B b;b.Init(-2, -2); b.disp();D1 d1(3);d1.Init(5,5);d1.inc1();d1.disp();D2 d2(6);d2.Init(-4, -4);d2.B:disp();d2.disp();d2.inc1();d2.inc2();d2.B:disp();d2.disp();d2.B:inc1();d2.B:disp();d2.disp();B,x1=-2,x2=-2D1,x3=3B,x1=-4,x2=-4D2,x4=6B,x1=0,x2=-3D2,x4=6B,x1
27、=1,x2=-3D2,x4=6第30页/共84页 #includeclass Level1/声明基类声明基类Level1 public: int n1; Level1(int in_n1) n1=in_n1;coutThis is Level1,n1=n1endl; ;class Level21:virtual public Level1 /Level1为虚基类,派生类为虚基类,派生类Level21 public:intn21;Level21(int a):Level1(a) n21=a;coutThis is Level21,n21=n21endl;第31页/共84页class Level2
28、2:virtual public Level1 /Level1为虚基类,派生类为虚基类,派生类Level22 public:int n22;Level22(int a):Level1(a) n22=a;coutThis is Level22,n22=n22endl;class Level3:public Level21,public Level22 /声明派生类声明派生类Level3 public:int n3;Level3(int a):Level1(a),Level21(a),Level22(a) n3=a;coutThis is Level3,n3=n3endl;void main()
29、Level3 obj(3); /定义定义Level3类对象类对象obj This is Level1,n1=3This is Level21,n21=3This is Level22,n22=3This is Level3,n3=3程序运行结果为:程序运行结果为:第32页/共84页第33页/共84页#include class base private:int n1;protected:int k1;public:base()n1=0;k1=1;void fun1()coutn1k1endl; ;class d1:public baseint n2; protected:int k2; pub
30、lic:d1()n2=10;k2=11;void fun2()coutn1k1endl; coutn2k2endl; ;class d2:public d1int n3; protected:int k3; public:d2()n3=20;k3=21;void fun3() c o u t n 1 k 1 e n d l ; c o u t n 2 k 2 e n d l ; coutn3k3endl; ;第34页/共84页void main()base baseobj;d1 d1obj;d2 d2obj;baseobj.fun1();d1obj.fun2();d2obj.fun3();、n
31、2和k2?能否访问基类base中的成员fun1()、n1和k1?nl 派生类d2的对象能否访问直接基类d1中的成员fun2()、n2和k2?能否访问基类base中的成员fun1()、n1和k1?n 以上程序有错,请改正,并上机验证。privateprotectedpublicbasen1k1base(),fun1()d1n2k2d1(),fun2()d2n3k3d2(),fun3()privateprotectedpublicbasen1k1base(),fun1()d1n2k2k1d1(),fun2()fun1()d2n3k3k2k1d2(),fun3()fun2()fun1()第35页/共
32、84页(1)能访问能访问base中公有的中公有的fun1()和保护的和保护的k1 ,不能访问私有的,不能访问私有的n1(2)能访问能访问base中公有的中公有的fun1(),不能访问,不能访问n1和和k1(3)能访问能访问d1中公有的中公有的fun2() 和和k2 ,不能访问私有的,不能访问私有的n2能访问能访问base中公有的中公有的fun1()和和k1 ,不能访问私有的,不能访问私有的n1(4)能访问能访问d1中公有的中公有的fun2(),不能访问私有的,不能访问私有的n2和和k2能访问能访问base中公有的中公有的fun1(),不能访问私有的,不能访问私有的n1和和k1 fun2函数中:
33、函数中:coutn1k1endl;替换为替换为fun1();fun3函数中:函数中:coutn1k1endl;coutn2k2endl;替换为替换为fun2();第36页/共84页第37页/共84页#include class B1public:int n1;B1(int in_n1)n1=in_n1;coutB1,n1=n1endl; ;class B21:virtual public B1public:int n21;B21(int a):B1(a)n21=a;coutB21,n21=n21endl; ;class B22:virtual public B1public:int n22;B
34、22(int a):B1(a)n22=a;coutB22,n22=n22endl; ;class B3:public B21,public B22public:int n3; B3(int a):B1(a),B21(a),B22(a)n3=a;coutB3,n3=n3endl; ;void main()B3 obj(5);B1,n1=5B21,n21=5B22,n22=5B3,n3=5程序运行结果为:程序运行结果为:第38页/共84页class B3:public B21,public B22改为改为class B3:public B22,public B21 没有变化,初始化的顺序与继承顺序
35、有关,与初始化列表的顺没有变化,初始化的顺序与继承顺序有关,与初始化列表的顺序无关序无关第39页/共84页第40页/共84页#include #include class Point private:float X,Y; public:void InitP(float xx=0, float yy=0) X=xx;Y=yy;void Move(float xOff,float yOff) ;float GetX()return X;float GetY()return Y;class Rectangle: private:float W,H; public:void InitR(float x
36、, float y,float w,float h) ;W=w;H=h; void Move(float xOff, float yOff) Point:Move(xOff,yOff);float GetX() return Point:GetX();float GetY() return Point:GetY();float GetH() return H;float GetW() return W;第41页/共84页endl;nn程序运行结果为:nThe data of rect(X,Y,W,H):n5,5,20,10X+=xOff;Y+=yOff; private Point InitP
37、(x,y);第42页/共84页第43页/共84页#include #includeclass circledouble radius;public:circle(double r) radius=r;double get_area()return ; ;class table double height;public:table(double h) height=h;double get_height()return height;class roundtable: public table,public circle char *color;public:roundtable(double
38、h,double r,char c): color=new charstrlen(c)+1; ; char *get_color()return color; ;第44页/共84页3.14*radius*radius circle(r), table(h) strcpy(color,c)第45页/共84页第46页/共84页cl=(5,4)c2=(2,10)c3=c1-c2=(3,-6)c4=c1+c2=(7,14)real=r;imag=i;complex(c1.real+c2.real,c1.imag+c2.imag) complex(c1.real-c2.real,c1.imag-c2.i
39、mag)#include class complex private:double real; double imag; public:complex(double r=0.0,double i=0.0) ;friend complex operator + (complex c1,complex c2);friend complex operator - (complex c1,complex c2);void display();complex operator + (complex c1,complex c2)return ;complex operator - (complex c1,
40、complex c2) return ;void complex:display()cout(real,imag)endl;void main() complex c1(5,4),c2(2,10),c3,c4;coutcl=;c1.display(); coutc2=;c2.display();c3=c1-c2; coutc3=c1-c2=;c3.display();c4=c1+c2;coutc4=c1+c2=;c4.display();第47页/共84页第48页/共84页#include const double PI=3.14159;class Shapes/基类基类Shapes int
41、x,y; public: Shapes (int xx,int yy=0)x=xx;y=yy;void GetArea() coutThe area of shapes is undefinedendl;class Rectangle:public Shapes/派生类派生类Rectangle int wide,high;public: Rectangle (int xx,int yy,int w, int h): Shapes(xx,yy) wide=w;high=h;void GetArea() coutThe area of rectangle is : wide*high endl;方
42、法一方法一第49页/共84页class Circle:public Shapes /派生类派生类Circle int radius;public: Circle (int xx,int yy,int r) : Shapes(xx,yy) radius=r;void GetArea() coutThe area of circle is :PI*radius*radiusendl;void main()Shapes sh(5,8);sh. GetArea();Rectangle rect(5,8,10,10); rect. GetArea(); Circle cir(5,8,10);cir.Ge
43、tArea(); 方法一方法一第50页/共84页#include const double PI=3.14159;class Shapes/基类基类Shapesprotected: int x,y; public:void setvalue(int xx,int yy=0)x=xx;y=yy;void GetArea() coutThe area of shapes is undefinedendl;class Rectangle:public Shapes/派生类派生类Rectanglepublic: void GetArea() coutThe area of rectangle is :
44、x*yendl;class Circle:public Shapes /派生类派生类Circlepublic: void GetArea() coutThe area of circle is :PI*x*xendl;void main()Shapes sh;Rectangle rect;Circle cir;sh.setvalue(5,8);sh. GetArea();rect.setvalue(5,8);rect. GetArea();cir.setvalue(10);cir.GetArea(); 方法二方法二第51页/共84页第52页/共84页#include #include clas
45、s personprivate:char* name;int no;public:person(char* n1,int n2)name=new charstrlen(n1)+1;strcpy(name,n1);no=n2; char *get_name() return name; int get_no()return no;class student:public personprivate:char depart10;int degree;public: student(char* n1,int n2,char* n3,int n4):person(n1,n2)strcpy(depart
46、,n3);degree=n4; int get_degree()return degree; char *get_depart()return depart;方法一:说明指针与数组的赋值问题方法一:说明指针与数组的赋值问题第53页/共84页class teacher:public personprivate:char prof10;char depart10;public: teacher(char* n1,int n2,char* n3,char* n4):person(n1,n2)strcpy(prof,n3);strcpy(depart,n4); char *get_prof()retu
47、rn prof; char *get_depart() return depart;void main() student s1(李明李明,1001,计算机计算机,10); teacher t1(曾二曾二,899,教授教授,理学理学院院); couts1.get_name() s 1 . g e t _ n o ( ) s 1 . g e t _ d e g r e e ( ) s1.get_depart()endl; couts1.get_name() s 1 . g e t _ n o ( ) t 1 . g e t _ p r o f ( ) t1.get_depart()endl;第5
48、4页/共84页#include #include class person char *name ,*num;public:person(char *str1,char *str2) name=new charstrlen(str1)+1; strcpy(name,str1); num=new charstrlen(str2)+1; strcpy(num,str2); char *get_num() return num; char *get_name() return name;class student:public person char *classnum; int sorce;pub
49、lic:student(char *str1,char *str2,char *classnum1,int sorce1):person(str1,str2) classnum=new charstrlen(classnum1)+1; strcpy(classnum,classnum1); sorce=sorce1;void get_student() coutperson:get_num()endl; coutperson:get_name()endl; coutclassnumendl; coutsorceendl;方法二:说明在主函数中输入值问题方法二:说明在主函数中输入值问题第55页/
50、共84页class teacher:public personchar *dep,*pos; public:teacher(char *str1,char * s t r 2 , c h a r * d e p 1 , c h a r *pos1):person(str1,str2) dep=new charstrlen(dep1)+1; strcpy(dep,dep1); pos=new charstrlen(pos1)+1; strcpy(pos,pos1);void get_teacher() coutperson:get_num()endl; coutperson:get_name()
51、endl; coutdependl; coutposendl;void main() c h a r n u m 1 0 , n a m e 1 0 , classnum10,; char dep10,pos10; int sorce; c o u t E n t e r a s t u d e n t datanumnameclassnumsorce; coutnum,name,classnum,get_student(); c o u t E n t e r a t e a c h e r datanumnamedeppos; teacher b(num,name,dep,pos),*pt
52、r2; ptr2=&b; ptr2-get_teacher();第56页/共84页第57页/共84页#include#includevoid main() char pSource=I am a teacher.; char pDestination=you are a student.; /pDestination字符串长度字符串长度pSource字符串长字符串长度度strcpy(pDestination,pSource); /等价于等价于strncpy(pDestination,pSource,16);coutpSourceendl;coutpDestinationendl;第58页/共8
53、4页#include const double PI=3.14159;class Myclasspublic:int Double(int x) return 2*x;long Double(long x) return 2*x;float Double(float x) return 2*x;double Double(double x) return 2*x;void main() Myclass test; int a=2;couttest. Double(a)endl; long b=2;cout test. Double(b)endl; float c=2.0;cout test.
54、Double(c) endl; double d=2.0;cout test. Double(d) endl;void main()Myclass test;couttest. Double(5)endl; cout test. Double(5l)endl; cout test. Double(5.0f) endl; cout test. Double(5.0) endl;void main() Myclass test;couttest. Double(5)endl; c o u t t e s t . Double(long)5)endl; cout test. Double(float
55、)5.0) endl; cout test.Double(5.0) endl;第59页/共84页#include const double PI=3.14159;class Shapes/抽象基类抽象基类Shapes int x,y; public:Shapes(int xx,int yy)x=xx;y=yy;virtual void GetArea()=0;/纯虚函数成员纯虚函数成员virtual void GetPrim()=0;/纯虚函数成员纯虚函数成员;class Rectangle:public Shapes/派生类派生类Rectangle int wide,high;public:
56、 Rectangle (int xx,int yy,int w, int h): Shapes(xx,yy) wide=w;high=h;第60页/共84页 void GetArea() coutThe area of rectangle is :wide*highendl; void GetPrim() coutThe area of rectangle is :2*(wide+high)endl; ;class Circle:public Shapes/派生类派生类Circle int radius;public: Circle (int xx,int yy,int r) : Shapes
57、(xx,yy) radius=r; void GetArea() coutThe area of circle is :PI*radius*radius endl; void GetPrim() coutThe area of rectangle is :2*PI*radius GetArea(); ptr0- GetPrim();ptr1=○ ptr1-GetArea(); ptr1- GetPrim();第61页/共84页一个事件,以及事件的种类、发生的时间、发生的位置。n(3) Windows提供了许多种类型的句柄,每种对象都有一个相应的句柄类型,例如HDC、HFONT、HWND
58、和HMENU分别是设备环境 、 字体 、 窗口 和 菜单的句柄。第62页/共84页由由Windows以及由其他应用程序向用户的应用程序发送的全部消息以及由其他应用程序向用户的应用程序发送的全部消息都储存在消息队列中,等待调用。都储存在消息队列中,等待调用。SDK程序以消息循环调用程序以消息循环调用Windows消息,如下代码表示此循环一直运行到程序接受终止执行消息,如下代码表示此循环一直运行到程序接受终止执行消息才停止。消息才停止。MSG Msg;while (GetMessage (&Msg,NULL,0,0) TranslateMessage(&Msg);DispatchMessage(&
59、Msg); 在在WhileWhile循环内部,由循环的每次迭代调用循环内部,由循环的每次迭代调用Windows API函数函数GetMessage (&Msg,NULL,0,0)以得到消息队列中的下一个消息以得到消息队列中的下一个消息,并,并把它存在特定的把它存在特定的MSG结构体变量结构体变量Msg中。中。TranslateMessage(&Msg)实现键盘上某个键的翻译。实现键盘上某个键的翻译。DispatchMessage(&Msg)函数向窗口的函数向窗口的消息处理函数发送消息,调用相应的消息处理函数。完成后进入下一消息处理函数发送消息,调用相应的消息处理函数。完成后进入下一个循环个循环
60、 第63页/共84页1.Windows应用程序由应用程序由WinMain函数和函数和WndProc窗口处理函数构窗口处理函数构成基本框架。成基本框架。2.WinMain函数是所有函数是所有Windows程序的入口,其功能包含窗口类程序的入口,其功能包含窗口类的定义和注册,窗口的创建和显示,并产生消息循环。的定义和注册,窗口的创建和显示,并产生消息循环。3.WndProc窗口处理函数定义了应用程序对收到的不同消息的响窗口处理函数定义了应用程序对收到的不同消息的响应,其中包含了应用程序对各种可能接收到的消息的处理过程,应,其中包含了应用程序对各种可能接收到的消息的处理过程,是消息处理分支控制语句的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 奶茶店人员考核制度
- 幼儿园受伤考核制度
- 垃圾池管理考核制度
- 驾驶员作业考核制度
- 锅巴厂转正考核制度
- 酒店消防证考核制度
- 测绘质检员考核制度
- 酒店新员工考核制度
- 护士考核制度范本
- 放疗科出科考核制度
- Intouch培训课件资料
- 2025年全球骨科创新年度白皮书-
- 2026年寒假德育实践作业竹马行新岁飒沓少年游【课件】
- 职业技术学校教师能力标准及评价
- 2026年皖西卫生职业学院单招职业适应性测试题库附答案解析
- 注意缺陷多动障碍(ADHD)远程认知行为干预方案
- Unit 1 A new start 核心素质评价(含答案)2025-2026学年外研版(2024)七年级英语上册
- 《汽车空气动力学》课件(共八章)
- 《常见机械机构原理与应用》课件
- 2025年哈尔滨职业技术学院高职单招(数学)历年真题考点含答案解析
- 《成人有创机械通气气道内吸引技术操作》标准解读
评论
0/150
提交评论