我的任务是编写 main 函数,它定义了一个名为recs[]的对象数组,大小为 4。 的每个元素都recs
必须用宽度和长度进行初始化,我必须计算它的面积和周长。
#include <iostream>
#include <cmath>
using namespace std;
struct recs
{
double width;
double length;
};
class rect
{
public:
rect();
double area;
double circumference;
void setrect();
void calarea();
void calcircumf();
void print();
friend bool operator==(rect rec1,rect rec2);
private:
double width,length;
};
rect recs[4];
bool operator==(rect rec1,rect rec2)
{
return (rec1.area == rec1.area && rec1.circumference == rec2.circumference);
}
rect::rect()
{
width=0.0;
length=0.0;
}
void rect::setrect()
{
cout << "width = ";
cin >> width;
cout << "length = ";
cin >> length;
print();
}
void rect::calarea()
{
width == length;
cout << "the return value true" << endl;
}
void rect::calcircumf()
{
width == length;
cout << "the return value true" << endl;
}
void rect::print()
{
cout << "width = " << width << endl;
cout << "length = " << length << endl << endl;
}
int main()
{
double area;
double circumference;
double width;
double length;
rect recs[4] = { {10.0, 12.0}, {12.0, 14.0}, {14.0, 16.0}, {16.0, 18.0} };
for (int i = 0; i <= 4; i++)
{
area = width * length;
cout << "the area "<< i << " = " << area << endl ;
circumference = ((width + length) + (width + length));
cout << "the circumference" << i << " = " << circumference << endl;
};
system("pause");
return 0;
}
到目前为止,我已经编辑了这个代码 4 个小时,但我无法编译它。