没有合适的资源?快使用搜索试试~ 我知道了~
c++面对对象程序设计课后答案(谭浩强).pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 190 浏览量
2021-11-14
17:28:05
上传
评论
收藏 48KB PDF 举报
温馨提示
试读
50页
c++面对对象程序设计课后答案(谭浩强).pdf
资源推荐
资源详情
资源评论
第一章
5:
#include <iostream>
using namespace std;
int main()
{
cout<<"This"<<"is";
cout<<"a"<<"C++";
cout<<"program."<<endl;
return 0;
}
6:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
a=10;
b=23;
c=a+b;
cout<<"a+b=";
cout<<c;
cout<<endl;
return 0;
}
7:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if (x<y) m=x;
else m=y;
if (z<m) m=z;
return(m);
}
8: #include <iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
c=a+b;
cout<<"a+b="<<a+b<<endl;
return 0;
}
9:
#include <iostream>
using namespace std;
int main()
{int add(int x,int y);
int a,b,c;
cin>>a>>b;
c=add(a,b);
cout<<"a+b="<<c<<endl;
return 0;
}
int add(int x,int y)
{int c;
c=x+y;
return(c);
}
10:
#include <iostream>
using namespace std;
int main()
{void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x, int y, int z)
{
int temp;
if (x>y) {temp=x;x=y;y=temp;} //{ } 内 3 个语句的作用是将 x 和 y 的值互换 )
if (z<x) cout<<z<<','<<x<<','<<y<<endl;
else if (z<y) cout<<x<<','<<z<<','<<y<<endl;
else cout<<x<<','<<y<<','<<z<<endl;
}
11:
#include <iostream>
using namespace std;
int main()
{int max(int a,int b,int c=0);
int a,b,c;
cin>>a>>b>>c;
cout<<"max(a,b,c)="<<max(a,b,c)<<endl;
cout<<"max(a,b)="<<max(a,b)<<endl;
return 0;
}
int max(int a,int b,int c)
{if(b>a) a=b;
if(c>a) a=c;
return a;
}
12:
#include <iostream>
using namespace std;
int main()
{
void change(int ,int );
int a,b;
cin>>a>>b;
if(a<b) change(a,b);
cout<<"max="<<a<<" min="<<b<<endl;
return 0;
}
void change(int ,int )
{
int r1,r2,temp;
temp=r1;
r1=r2;
r2=temp;
}
13:
#include <iostream>
using namespace std;
int main()
{void sort(int &,int &,int &);
int a,b,c,a1,b1,c1;
cout<<"Please enter 3 integers:";
cin>>a>>b>>c;
a1=a;b1=b;c1=c;
sort(a1,b1,c1);
cout<<a<<" "<<b<<" "<<c<<" in sorted order is ";
cout<<a1<<" "<<b1<<" "<<c1<<endl;
return 0;
}
void sort(int &i,int &j,int &k)
{ void change(int &,int &);
if (i>j) change(i,j);
if (i>k) change(i,k);
if (j>k) change(j,k);
}
void change(int &x,int &y)
{ int temp;
temp=x;
x=y;
y=temp;
}
14:
#include <iostream>
#include <string>
using namespace std;
int main()
{ string s1="week",s2="end";
cout<<"s1="<<s1<<endl;
cout<<"s2="<<s2<<endl;
s1=s1+s2;
cout<<"The new string is:"<<s1<<endl;
return 0;
}
15:
#include <iostream>
#include <string>
using namespace std;
int main()
{ string str;
int i,n;
char temp;
cout<<"please input a string:";
cin>>str;
n=str.size();
for(i=0;i<n/ 2;i++)
{temp=str[i];str[i]=str[n-i-1];str[n-i-1]=temp;}
cout<<str<<endl;
return 0;
}
16:
#include <iostream>
#include <string>
using namespace std;
int main()
{ int i;
string str[5]={"BASIC","C","FORTRAN","C++","PASCAL"};
void sort(string []);
sort(str);
cout<<"the sorted strings :"<<endl;
for(i=0;i<5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{int i,j;
string t;
for (j=0;j<5;j++)
for(i=0;i<5-j;i++)
if (s[i]>s[i+1])
剩余49页未读,继续阅读
资源评论
moneygaojia
- 粉丝: 0
- 资源: 4万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- tensorflow-gpu-2.6.0-cp38-cp38-manylinux2010-x86-64.whl
- mmexport1715960553858.png
- tensorflow-gpu-2.6.0-cp37-cp37m-manylinux2010-x86-64.whl
- 通过 .NET 应用程序中的源代码查找 SQL 注入
- 电子设计竞赛2007年B题 无线识别装置.doc
- Wox全局搜索工具,一款win下的全局搜索软件
- 使用高级集群管理 (ACM) 模板来管理用户、组和命名空间
- 电子设计竞赛2007年A题 音频信号分析仪.doc
- burpsuite安装详细教程
- Bk1_Ch2_01.ipynb
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功