c++上机实验码5个.docVIP

  • 77
  • 0
  • 约1.6万字
  • 约 13页
  • 2016-10-06 发布于贵州
  • 举报
c上机实验码5个

C++面向对象程序设计实验一:C++基础练习 编写一个将3个整数从小到大排序输出的程序。要求编写两个函数main和sort,输入输出在main中完成,数的排序在sort中完成(要用引用实现)。(注意加上适当的注释) #include iostream using namespace std; void sort(int a,int b,int c)//排序子函数 {int temp=0; if(ba) {temp=b;b=a;a=temp;} if(ca) {temp=c;c=a;a=temp;} if(cb) {temp=b;b=c;c=temp;} } int main() {int a,b,c; coutpls input the 3 nums u want to sort:endl; cinabc; sort(a,b,c); coutthe result is abcendl; return 0;} 用函数重载的方法实现2个整数或三个整数相加。 #include iostream using namespace std; int add(int a,int b) {return a+b; } int add(int a,int b,int c)//重载函数 {return a+b+c; } int main() {int a=3,b=6,c=9; couta+b=a

文档评论(0)

1亿VIP精品文档

相关文档