有谁会做C++语言编程,我这有个考题帮我做下。速求~~~

1.使用Visual C++6.0打开源文件test1.cpp,按要求完成程序,编译并运行成功后将文件test1.cpp保存至 D: \C++Test\xxxxxxxxx\test1.cpp
2.使用Visual C++6.0打开源文件test2.cpp,按要求完成程序,编译并运行成功后将文件test2.cpp保存至 D: \C++Test\xxxxxxxxx\test2.cpp
3. 按下列要求编写程序:
1)定义一个矩形类rect,要求有计算矩形周长和面积的成员函数的定义。
2)在主函数中定义一个矩形对象,长和宽的值分别为15和10,分别输出该矩形对象的周长和面积。
3)分离该程序的类定义和主函数,改成多文件结构。
注意:①分离后主函数所在的源程序文件名称为test3_main.cpp
②分离后类头文件名为test3_rect.h
③分离后类定义文件名为test3_rect.cpp
4)按上述要求完成后,编译运行程序并将运行结果写入test3_main.cpp文件中。
5)最后,将上述三个文件保存至D: \C++Test\xxxxxxxxx\。(切记)

完成上述考试要求后,确保上述红色标记的6个文件保存至D: \C++Test\xxxxxxxxx\,并删除其它临时文件,
test1.cpp
//请完成下面程序中swap()函数的定义
void swap(int& x,int& y)
{

}
#include <iostream.h>
test2.cpp
//根据程序输出结果完成下面程序中min()函数和max()函数的定义
#include<iostream.h>
int min(int x,int y,int z)
{

}
int max(int x,int y,int z)
{

}
void main()
{
int a=35,b=20,c=25;
cout<<"最小值:"<<min(a,b,c)<<endl;

cout<<"最大值:"<<max(a,b,c)<<endl;
}

//输出结果为:

//最小值:20
//最大值:35
void main()
{
int a=3,b=5;
cout<<a<<'\t'<<b<<endl;
swap(a,b);
cout<<a<<'\t'<<b<<endl;
}

//输出为:

//3 5
//5 3

第1,2题
//test1.cpp

void swap(int& x,int& y) //变量的引用
{

int t;
t=x;
x=y;
y=t;

}

//test2.cpp
#include <iostream.h>
int min(int x,int y,int z)
{
int min;
min=x;
if(min>y) min=y; //此时min已经是x和y中的较小的那个数了
if(min>z) min=z;
return min;
}
int max(int x,int y,int z)
{
int max;
max=x;
if(max<y) max=y; //此时min已经是x和y中的较小的那个数了
if(max<z) max=z;
return max;
}
void main()
{
int a=35,b=20,c=25;
cout<<"最小值:"<<min(a,b,c)<<endl;

cout<<"最大值:"<<max(a,b,c)<<endl;
}

//输出结果为:

//最小值:20
//最大值:35
void main()
{
int a=3,b=5;
cout<<a<<'\t'<<b<<endl;
swap(a,b);
cout<<a<<'\t'<<b<<endl;
}

//输出为:

//3 5
//5 3

第3题:

//test3_rect.h (这是头文件,在此文件中进行类的声明)
#include <iostream>
using namespace std;
class Rect
{
public:
Rect(int,int);
float perimeter();
float area();
private:
int length;
int width;
};

//test3_rect.cpp
#include <iostream>
#include "test3_rect.h"
using namespace std;
Rect::Rect(int l,int w)
{
length=l;
width=w;
}
float Rect::perimeter()
{
return 2*(length+width);
}
float Rect::area()
{
return length*width;
}
//test3_main.cpp

#include <iostream>
#include "test3_rect.h"
using anmespace std;
int main()
{
Rect rect(15,10);
cout<<rect. perimeter()<<endl;
cout<<rect.area()<<endl;
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-13
静待高手
第2个回答  2011-07-13
text1
void swap(int &x,int &y)
{
y=x-y;
x=x-y;
y=x+y;
}
text2
int min(int x,int y,int z)
{
return (x>y?y:x)>z?z:(x>y?x:y);
}
int max(int x,int y,int z)
{
return (x>y?x:y)>z?(x>y?x:y):z;
}
第3个回答  2011-07-13
去买一本江苏省二级考试试卷汇编,书店里应该都有,上面笔试题,上机题都有,答案也很全。
第4个回答  2011-07-14
text1
void swap(int &x,int &y)
{
y=x-y;
x=x-y;
y=x+y;
}
text2
int min(int x,int y,int z)
{
return (x>y?y:x)>z?z:(x>y?x:y);
}
int max(int x,int y,int z)
{
return (x>y?x:y)>z?(x>y?x:y):z;
} 推荐你买本《数据结构》。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网