C++面向对象实验报告 联系客服

发布时间 : 星期四 文章C++面向对象实验报告更新完毕开始阅读

少了#include 六、实验结果

七、总结 附录:

(1)①//sy7_1.cpp #include using namespace std; template

T max(T a,T b) {

return a>b?a:b; }

int main() {

cout<<\ }

②#include using namespace std; template T max(T a,T b) {

return a>b?a:b; }

int max(int a,int b){return a>b?a:b;}

float max(float a,float b){return a>b?a:b;} int main()

{

cout<<\ return 0; }

(2)//sy7_2.cpp #include #include #include using namespace std; bool inorder(int,int); int main()

{ vector nums; for(int i=0;i<10;i++)

cout<<\return 0;

nums.push_back(rand());

cout<<\向量的初始顺序为:\vector::iterator out,p;

for(out=nums.begin();out!=nums.end();++out)

cout<<* out<<\cout<

cout<<\输入想查找的数:\cin>>value;

p=find(nums.begin(),nums.end(),value); if(p!=nums.end()) cout<<\最先等于:\的是第\ <

else cout<<\没有找到所查找的数.\sort(nums.begin(),nums.end()); cout<<\向量的升序为:\for(i=0;i<10;i++) cout<

sort(nums.begin(),nums.end(),inorder); cout<<\向量的降序为:\

for(out=nums.begin();out!=nums.end();++ out) cout<<* out<<\ cout<

bool inorder(int a,int b){return a>b;};

实验8 I/O流

一、实验目的和要求

(1)掌握格式化的输入输出方法。

(2)熟悉系统提供的输入操作和输出操作函数。 (3)掌握磁盘文件的输入输出方法。

二、实验内容和原理

(1)实验指导书P117 2。 (2)实验指导书P118 3。

三、实验环境

PC机,Windows XP操作系统,Visual C++ 6.0

四、算法描述及实验步骤

(1)编写源程序。

(2)检查程序有无错误(包括语法错误和逻辑错误),有则改之。 (3)编译和连接,仔细分析编译信息,如有错误应找出原因并改正之。 (4)运行程序,分析结果。

(5)将调试好的程序保存在自己的用户目录中,文件名自定。

五、调试过程

六、实验结果