1、m) m=z; return(m); 8: #include b;a+byz; sort(x,y,z);void sort(int x, int y, int z) int temp; if (xy) temp=x;x=y;y=temp; / 内3个语句的作用是将x和y的值互换)x) coutz,xy else if (zy) cout else cout11:int max(int a,int b,int c=0);max(a,b,c)=max(a,b,c)max(a,b)=max(a,b)a) a=b; if(ca) a=c; return a;12: void change(int ,i
2、nt ); int a,b; if(ab) change(a,b);max=a min=bvoid change(int ,int ) int r1,r2,temp; temp=r1; r1=r2; r2=temp;13:void sort(int &,int &); int a,b,c,a1,b1,c1;Please enter 3 integers: a1=a;b1=b;c1=c; sort(a1,b1,c1); in sorted order is a1b1c1j) change(i,j); if (ik) change(i,k); if (jk) change(j,k);void ch
3、ange(int &x,int &y) int temp; temp=x; x=y; y=temp;14:string string s1=week,s2=ends1=s1s2=s2 s1=s1+s2;The new string is: 15: string str; int i,n; char temp;please input a string:str; n=str.size(); for(i=0;in/2;i+) temp=stri;stri=strn-i-1;strn-i-1=temp;strreturn 0; 16: int i; string str5=BASIC,CFORTRA
4、NPASCAL; void sort(string ); sort(str);the sorted strings :5;strivoid sort(string s)int i,j; string t; for (j=0;jsi+1) t=si;si=si+1;si+1=t; 17: long c5=10100,-123567, 1198783,-165654, 3456; int a5=1,9,0,23,-45; float b5=2.4, 7.6, 5.5, 6.6, -2.3 ; void sort(int );void sort(float ); void sort(long );
5、sort(a); sort(b); sort(c);void sort(int a)int i,j,t; if (aiai+1) t=ai;ai=ai+1;ai+1=t;the sorted numbers :aiendl void sort(long a) long t;void sort(float a) float t;18:template void sort(T a) int i,j,min; T t; min=i; for (j=i+1;j+) if(aminaj) min=j; t=ai; ai=amin; amin=t; int a5=1,9,0,23,-45;第二章1clas
6、s Time public: void set_time(); void show_time();private: /成员改为公用的 int hour; int minute; int sec; ;void Time:set_time() /在main函数之前定义hour;minute;sec;show_time() /在main函数之前定义hourminutesec void show_time(void) cout private:Time t; t.set_time(); t.show_time(); 3: void set_time(void); void show_time(void
7、);set_time(void)show_time(void)cout t.set_time();4:/xt2-4-1.cpp(main.cpp)#include xt2-4.hStudent stud; stud.set_value(); stud.display();/xt2-4-2.cpp(即student.cpp) /在此文件中进行函数的定义 /不要漏写此行void Student:display( ) coutnum:numname:namesex:sexnum;cinname;sex;5:/xt2-5-1.cpp(file1.cpp)xt2-5.h Array_max arrmax
8、; arrmax.set_value(); arrmax.max_value(); arrmax.show_value();/xt2-5-2.cpp(arraymax.cpp)void Array_max: int i; for (i=0;10;arrayi;max_value() int i; max=array0; for (i=1; if(arrayimax) max=arrayi;show_value()max6:解法一class Boxpublic: void get_value(); float volume(); void display(); public: float len
9、gh; float width; float height;void Box:get_value()please input lengh, width,height:lengh;width;height;float Box:volume() return(lengh*width*height);display()volume()Box box1,box2,box3; box1.get_value();volmue of bax1 is box1.display(); box2.get_value();volmue of bax2 is box2.display(); box3.get_valu
10、e();volmue of bax3 is box3.display();解法二: void volume(); float vol; vol=lengh*width*height;vol box1.volume(); box2.volume(); box3.volume();cout第三章2:class Date Date(int,int,int); Date(int,int); Date(int); Date(); int month; int day; int year;Date:Date(int m,int d,int y):month(m),day(d),year(y) Date(i
11、nt m,int d):month(m),day(d) year=2005;Date(int m):month(m) day=1; year=2005;Date() month=1; day=1;void Date:month/dayyear Date d1(10,13,2005); Date d2(12,30); Date d3(10); Date d4; d1.display(); d2.display(); d3.display(); d4.display();3: Date(int=1,int=1,int=2005);4:class Student Student(int n,float s):num(n),score(s) int num; float score;scoredisplay();using namespace
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1