c++中未初始化对象问题,希望帮助.

在平面直角坐标系中,两点可以确定一条直线
如果有多点在一条直线上,那么这些点中任意两点确定的直线是同一条
给定平面上2x3个整点((x,y)l0即横坐标是0到1(包含0和1)之间的整数、纵坐标是0到2(包含0和2)之间的整数的点这些点一共确定了11条不同的直线。
给定平面上20x21个整点{(x,y)l0x<20,0y<21,XEZyEZ
即横坐标是0到19(包含0和19)之间的整数、纵坐标是0到20(包含0和20)之间的整数的点请问这些点一共确定了多少条不同的直线。


#include
using namespace std;
#include

class Point
{
public:
    Point()
    {

    }
    Point(int x, int y)
    {
        this->m_x = x;
        this->m_y = y;
    }
    int m_x;
    int m_y;
};

class Line
{
public:
    Line()
    {

    }
    Line(int coefficient_x, int coefficient_y, int constant)
    {
        this->m_coefficient_x = coefficient_x;
        this->m_coefficient_y = coefficient_y;
        this->m_constant = constant;
    }
    int m_coefficient_x;
    int m_coefficient_y;
    int m_constant;

    bool operator==(Line& l)
    {
        if (this->m_coefficient_x == l.m_coefficient_x && this->m_coefficient_y == l.m_coefficient_y && this->m_constant == l.m_constant)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    bool operator!=(Line& l)
    {
        if (this->m_coefficient_x == l.m_coefficient_x && this->m_coefficient_y == l.m_coefficient_y && this->m_constant == l.m_constant)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
};



void CreatePoint(vector &v_Point,int x,int y)
{
    for (int i = 1; i < x; ++i)
    {
        for (int j = 1; j < y; ++j)
        {
            Point p(i, j);
            v_Point.push_back(p);
        }
    }
    v_Point.resize(v_Point.size());
}

void CreateLine(vector v_Line,vector v_Point)
{
    for (vector::iterator it = v_Point.begin(); it != v_Point.end(); ++it)
    {
        for (vector::iterator it_2 = v_Point.begin(); it_2 != v_Point.end(); ++it_2)
        {
            int temp_coefficient_x = (*it).m_y - (*it_2).m_y;
            int temp_coefficient_y = (*it_2).m_x - (*it).m_x;
            int temp_constant = (*it).m_x * (*it_2).m_y - (*it_2).m_x * (*it).m_y;
            Line l(temp_coefficient_x, temp_coefficient_y, temp_constant);
            v_Line.push_back(l);
        }
    }
}

void Erase_repetition(vector& v_Line)
{
    for (vector::iterator it = v_Line.begin(); it != v_Line.end()-1; ++it)
    {
        for (vector::iterator it_2 = it+1; it_2 != v_Line.end(); ++it_2)
        {
            if ((*it) == (*it_2))
            {
                v_Line.erase(it_2);
            }
        }
    }
    v_Line.resize(v_Line.size());
}

void Output_result_Line_vector(vector &v_Line)
{
    cout << "The number of line:_____\b\b\b\b\b" << v_Line.size() << endl;
}

int main()
{
    vector v_Point;
    vector v_Line;
    int x, y;
    cout << "Enter the value of X axis:_____\b\b\b\b\b";
    cin >> x;
    --x;
    cout << "Enter the value of Y axis:_____\b\b\b\b\b";
    cin >> y;
    --y;

    CreatePoint(v_Point,x, y);
    CreateLine(v_Line, v_Point);
    Erase_repetition(v_Line);
    Output_result_Line_vector(v_Line);

    
    return 0;
}

出现以下错误:

img

不是很理解这个错误。

将9-12行改成:

Point()
    {
       m_x=0;
       m_y=0;
    }

25~28行:

Line()
    {
 m_coefficient_x=0;
   m_coefficient_y=0;
   m_constant=0;
    }

#include<bits/stdc++.h>
using namespace std;
int main()
{
    set< pair<double,double> > les;
    for(double x1=0;x1<20;++x1){
        for(double y1=0;y1<21;++y1){
            for(double x2=0;x2<20;++x2){
                for(double y2=0;y2<21;++y2){
                    if(x1!=x2&&y1!=y2){
                        double k = (y2-y1)*1.0/(x2-x1);
                        //b=y-k*x;
                        double b = (y2*(x2-x1)-(y2-y1)*x2)*1.0/(x2-x1);    
                        les.insert(pair<double,double>(k,b));
                    }
                }
            }
        }
    }
    cout << les.size()+20+21;
    return 0;
}