输入:1 2 输出: 39. #include using namespace std; int add(intx,int y) { int z=x+y; return(z); }int main() { inta,b,c; cin>>a>>b; c=add(a,b); cout<<\"a+b=\"<输入:1 2 输出:313. #include using namespace std;void max(int&x,int&y,int&z) { int m; x>y?m=y:m=x; m>z?m=z:m=m; cout<z?cout<z?cout<} if(m==z) {y>x?cout<int main() { inta,b,c; cin>>a>>b>>c; max(a,b,c); system(\"pause\"); return 0; }输入:1 2 3 输出:123 17.
#include using namespace std; constint n=2; void max(int a[n]) { inti,j,b; for(i=1;ivoid max(float a[n]) { inti,j; float b; for(i=1;ia[j]=a[j+1]; a[j+1]=b; } } } }void max(double a[n]) { double b; inti,j; for(i=1;iint main() { int a[n],i; float b[n]; double c[n]; for(i=0;i>a[i]; for(i=0;i>b[i]; for(i=0;i>c[i]; max(a); max(b); max(c); system(\"pause\"); return 0; }输入:2 1 2.5 1.5 1.5 2.5
输出:12
1.52.5 1.52.5 第二章 1.
#include using namespace std; class Time {private: inthour,minute,sec; public: voidset_time(); voidshow_time(); };
Time t; int main() { t.set_time(); t.show_time(); system(\"pause\"); return 0; }
void Time::set_time() { cin>>hour>>minute>>sec; }
void Time::show_time() { cout<输入:1 2 3 输出:123 2.#include using namespace std; class Time {private: inthour,minute,sec; public: voidset_time() { cin>>hour>>minute>>sec; };
voidshow_time() { cout<int main() { Time t1; t1.set_time(); t1.show_time(); system(\"pause\"); return 0; }输入:0 1 2 输出:012 3.
#include using namespace std; class Time {private: inthour,minute,sec; public: voidset_time(); voidshow_time(); };
int main() { Time t1; t1.set_time(); t1.show_time(); system(\"pause\"); return 0; }
void Time::set_time() { cin>>hour>>minute>>sec; }
void Time::show_time() { cout<输入:1 2 3 输出1235。
arraymax.h
#include using namespace std; classArray_max {public: voidmax_value(); voidset_value(); voidshow_value(); private: int array[10]; int max; };
arraymax.cpp
#include \"arraymax.h\"
voidArray_max::set_value() {int i;
for(i=0;i<10;i++) cin>>array[i]; }
voidArray_max::max_value() {int i;
max=array[0]; for(i=1;i<10;i++)
if(array[i]>max)max=array[i]; }
voidArray_max::show_value() { cout<<\"max=\"<file.cpp#include \"arraymax.h\" int main() { Array_maxarrmax; arrmax.set_value(); arrmax.max_value(); arrmax.show_value(); return 0; }
输入:0 1 2 3 4 5 6 7 8 9 10 输出:max=10 第三章
2.
#include using namespace std; class Date {public: Date(int,int,int); Date(int,int); Date(int); Date(); void display(); private: int month; int day; int year; };
Date::Date(intm,intd,int y):month(m),day(d),year(y) {}
Date::Date(intm,int d):month(m),day(d) {year=2005;}
Date::Date(int m):month(m) { day=1; year=2005; }
Date::Date() { month=1; day=1; year=2005; }
void Date::display() { cout<int main() { Date d1(10,13,2005); Date d2(12,30); Date d3(10); Date d4; d1.display(); d2.display(); d3.display();d4.display(); system(\"pause\"); return 0; }
输出:10/13/2005
12/30/2005 10/1/2005 1/1/2005
3.#include using namespace std; class Date {public: Date(int=1,int=1,int=2005); void display(); private: int month; int day; int year; };
Date::Date(intm,intd,int y):month(m),day(d),year(y) {}
void Date::display() { cout<int main() { Date d1(10,13,2005); Date d2(12,30); Date d3(10); Date d4; d1.display(); d2.display(); d3.display(); d4.display(); system(\"pause\"); return 0; }输出:10/13/2005
12/30/2005 10/1/2005 1/1/2005 第四章
4.#include using namespace std; class square {public: int a[2][3]; square() { inti,j; for(i=0;i<2;i++) for(j=0;j<3;j++) a[i][j]=0; }
square operator+(square &c2); };
square square::operator+(square &c2) { square c; inti,j; for(i=0;i<2;i++) for(j=0;j<3;j++) c.a[i][j]=a[i][j]+c2.a[i][j]; return c; }
int main() { inti,j; square c1,c2,c3; for(i=0;i<2;i++) for(j=0;j<3;j++) cin>>c1.a[i][j]; for(i=0;i<2;i++) for(j=0;j<3;j++) cin>>c2.a[i][j]; c3=c1+c2; for(i=0;i<2;i++) {for(j=0;j<3;j++) {cout<输入:1 2 3 4 5 66 5 4 3 2 1 输出:7 7 7 7 7 7
学习总结:C++涉及概念很多,语法比较复杂,内容十分广泛,开始感觉比较难,但是,通过一段时间的学习,终于感到能掌握了,我想熟能生巧,坚持不懈就是学习的金钥。其实要教好这门课,绝不是一个纯技术问题,需要综合多方面因素进行考虑,做出合理的决策和安排。实践是检验真理的唯一标准,实践能积累我们的经验,找到我们的不足,更好的掌握我们所要学习的东西。这次的教学实践活动,使我学到了很多知识,弥补了我的很多漏洞,让我变得更爱思考,精益求精。通过这个很小但对我来说却不小的程序,我多少有点体会到C++相对于C的优越性,方便多了。本来C++语法复杂,内容又多,如果对它缺乏系统的了解,将难以真正应用,编出来的程序将会错误百出,编译出错,事倍功半。而这次实践活动使我认识到了细节其实很重要,正是认识到了细节的重要性,使得我更加仔细,减少了编译出错几率,真的是事倍功半啊!同时使我对C++有了些许系统的了解,真正运用到实处,对C++的认识上升了一个层次。