奇怪的错误:C++中的非赋值
这是我的程序,它可以找到矩形的面积、周长以及矩形是否为正方形。它通过使用两个坐标和建模结构来实现这一切。我对C++是相当新的,并且我在这行上得到了一个不熟悉的错误:IFABSEY-A2.Y= ABSA2.x-x{错误:这是:赋值中的非Load。奇怪的错误:C++中的非赋值,c++,C++,这是我的程序,它可以找到矩形的面积、周长以及矩形是否为正方形。它通过使用两个坐标和建模结构来实现这一切。我对C++是相当新的,并且我在这行上得到了一个不熟悉的错误:IFABSEY-A2.Y= ABSA2.x-x{错误:这是:赋值中的非Load。 #include <cstdlib> #include <iostream> #include <math.h> /* Name: Rectangle Author: ------ Date: 27/10/14 04
#include <cstdlib>
#include <iostream>
#include <math.h>
/*
Name: Rectangle
Author: ------
Date: 27/10/14 04:31
Description: A program that finds the area, perimeter, and if a rectangle is square
*/
using namespace std;
class Point
{
private:
int x, y;
public:
Point ()
{
x = 0;
y = 0;
}
//A four parameter constructor
Point (int a, int b)
{
x = a ;
y = b ;
}
//Setter function
void setX (int a)
{
x = a ;
}
void setY (int b)
{
y = b ;
}
//Accessor functions
int getX ()
{
return x ;
}
int getY ()
{
return y ;
}
//Function to print points
void printPoint ()
{
cout << endl << "(" << x << ", " << y << ")" << endl ;
}
//Function to enter new points
Point newPoint ()
{
Point aPoint;
int a;
int b;
cout << "Enter first x coordinate: " ;
cin >> a ;
cout << "Enter first y coordinate: " ;
cin >> b ;
aPoint.setX(a);
aPoint.setY(b);
return aPoint;
}
//Function to find area
int areaA (Point a2)
{
int height = y - a2.y ;
int length = a2.x - x ;
int area = abs((length * height)) ;
return area ;
}
//Function to find perimeter
int perimeterA (Point a2)
{
int height1 = y - a2.y ;
int length1 = a2.x - x ;
int perimeter1 = abs(((length1 + height1) * 2)) ;
return perimeter1 ;
}
//Function to determine shape
int isSquare (Point a2)
{
int square;
if ( abs(y - a2.y) = abs(a2.x - x) ) //****ERROR ON THIS LINE****
{
cout << "It is square" ;
}
else
{
cout << "It is not square" ;
}
return square;
}
};
Point newPoint();
int main(int argc, char *argv[])
{
cout << "Enter top left coordinate first and bottom right coordinate second" ;
cout << endl << endl ;
Point firstPoint;
Point secondPoint;
int areaR;
int perimeter;
firstPoint = firstPoint.newPoint();
secondPoint = secondPoint.newPoint();
cout << endl ;
cout << "First point: " ;
firstPoint.printPoint();
cout << "Second point: " ;
secondPoint.printPoint();
cout << endl ;
areaR = firstPoint.areaA(secondPoint);
cout << "Area: " << areaR << endl ;
perimeter = firstPoint.perimeterA(secondPoint);
cout << "Perimeter: " << perimeter << endl;
cout << endl ;
system("PAUSE");
return EXIT_SUCCESS;
}
我在这个错误中没有看到任何奇怪的东西。这条线确实试图把一些东西分配给非LValk,就像错误消息一样。在C++中,等式比较操作符被拼写为A==。 还不清楚为什么在包含C库标题时混合了两种不同的样式:和。如果决定包含,则包含更有意义。请记住,通过标题可用的标准库函数应视为std命名空间的成员。中不推荐使用include.h版本的heqaders现代C++
if(abs(y-a2.y) = abs(a2.x - x) )
尝试将absa2.x-x分配给absy-a2.y,这没有意义。使用==比较值
顺便说一句,isSquare返回一个未初始化的值,这是一个错误。要么返回一些有意义的值,要么使函数无效。相等性由a==not=检查。我在这一行遇到一个不熟悉的错误:ifabsy-a2.y=absa2.x-x{错误是这样的:赋值中的非左值。我不知道这意味着什么,也不知道如何修复它。你可能在互联网上搜索过这个词的意思吗?这个问题可能是c的重复,但在这种情况下规则是相同的,所以下一个问你自己的逻辑问题是赋值?它应该是?@HostileFor吗k:非常弯曲的op=: