Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my code: shape.h: #ifndef SHAPE_H #define SHAPE_H #include <iostream> #i

ID: 3741450 • Letter: T

Question

This is my code: shape.h:

#ifndef SHAPE_H

#define SHAPE_H

#include <iostream>

#include <vector>

using namespace std;

class Shape{

private:

struct Point{

double x, y;

};

vector<Point> points;

public:

void addPoint(Point p);

Point getPoint(int);

int getNumPoints(void);

};

#endif

shape.cpp:

#include "shape.h"

using namespace std;

Shape::Shape(){}

void addPoint(Point p){

points.push_back(Point p);

}

Point getPoint(int i){

return points[i];

}

int getNumPoints(void){

return points.size();

}

Main.cpp:

#include <iostream>

#include "Shape.h"

#include <fstream>

#include <vector>

using namespace std;

struct Point{

double x,y;

};

int main(int argc, char* argv[]){

Shape shape1;

ifstream shapeOne;

shapeOne.open(argv[1]); // Test to see if file opened correctly.

if(!shapeOne){

cout << "File not found, enter correct file name." << endl;

return 1;

}

Point p1, p2, p3, p4; //Adding Point struct objects.

shapeOne >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> p4.x >> p4.y; //Storing file points into struct Point variables.

shapeOne.close();

//Adding points to <vector>

shape1.addPoint(p1);

shape1.addPoint(p2);

shape1.addPoint(p3);

shape1.addPoint(p4);

return 0;

}

In my code, I am getting an error "[Error] no matching function for call to 'Shape::addPoint(Point&)' and I've got no idea why.

This is c++

Explanation / Answer

#ifndef SHAPE_H
#define SHAPE_H
#include <iostream>
#include <vector>

using namespace std;
    struct Point{
       double x, y;
   };

class Shape{
    private:
    vector<Point> points;
    public:
    void addPoint(Point p);
    Point getPoint(int);
    int getNumPoints(void);
};
#endif

#include "shape.h"

using namespace std;
void Shape::addPoint(Point p)
{
    points.push_back(p);
}

Point Shape::getPoint(int i)
{
    return points[i];
}

int Shape::getNumPoints(void)
{
    return points.size();
}

#include <iostream>
#include "Shape.h"
#include <fstream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    Shape shape1;
    ifstream shapeOne;
    shapeOne.open(argv[1]); // Test to see if file opened correctly.
    if (!shapeOne) {
        cout << "File not found, enter correct file name." << endl;
        return 1;
    }
    Point p1, p2, p3, p4; //Adding Point struct objects.
    shapeOne >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> p4.x >> p4.y; //Storing file points into struct Point variables.
    shapeOne.close();
    //Adding points to <vector>
    shape1.addPoint(p1);
    shape1.addPoint(p2);
    shape1.addPoint(p3);
    shape1.addPoint(p4);
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote