Question

In: Computer Science

In C++, I have 3 files (Main.cpp, Point.cpp, Point.h). When Compiled and run, it produces 2...

In C++, I have 3 files (Main.cpp, Point.cpp, Point.h). When Compiled and run, it produces 2 errors, in Main.cpp "cannot convert from double to point" and in Point.cpp "name followed by :: must be a class or namespace name". How do you go about fixing these errors without editing Main.cpp? Thanks in advance.

//main.cpp

#include <iostream>
#include <cmath>
#include "Point.h"
using namespace std;

const double PI = 3.14159265359;
const double TOL = .0000001; //allows us to do a comparison for double value equality
int main()
{

   int toTest = 0;
   //TEST AS YOU DEVELOP COMMENT OUT EVERYTHING BUT WHAT YOU HAVE IMPLEMENTED
   //AND UNCOMMENT AS YOU CREATE.
   //(you can look below to see what I make this variable to test given things)
   cout << "MUST IMPLEMENT GETTERS BEFORE TESTING \n";
   cout << "What would you like to test? \n";
   cout << "1-value constructor \n";
   cout << "2-copy constructor \n";
   cout << "3-setters test \n";
   cout << "4-translation test \n";
   cout << "5-scaling test \n";
   cout << "6-reflect over x-axis test \n";
   cout << "7-reflect over y-axis test \n";
   cout << "8-rotation \n";
   cout << "9-assignment operator \n";
   cout << "10-operator equals equals \n";
   cout << "11-cin overload \n";
   cout << "12-cout overload \n";
   cin >> toTest;

   Point a; // a should be at (0,0)
   Point b(5.0); //b should be at (5.0,0)
   /* incremental test line
   Point c(-15.3, -32.22); //c should be at (-15.3, -32.33)


   if(toTest==1)
   {
       cout<<"**Value Constructor Test: \n";
       if(abs(a.get_x())<TOL && abs(a.get_y())<TOL &&
           abs(b.get_x()-5)<TOL && abs(b.get_y())<TOL &&
           abs(-15.3-c.get_x())<TOL && abs(-32.22-c.get_y())<TOL)
       {
           cout<<" Value Constructor Works\n" <<endl;
       }
       else
       {
           cout<<" Value Constructor Failed\n"<<endl;
       }
   }
/*   Point d(c);
   if(toTest==2)
   {
       cout<<"\n**Copy Constructor Test: \n";
       if(abs(d.get_x()-c.get_x())<TOL && abs(d.get_y()-c.get_y())<TOL)
       {
           cout<<" Copy Constructor Works\n"<<endl;
       }
       else
       {
           cout<<" Copy Constructor Failed\n"<<endl;
       }
   }

   if(toTest==3)
   {
       cout<<"\n**Setters Test: \n";
       a.set_x(5.3); a.set_y(-3.2);
       if(abs(a.get_x()-5.3)<TOL && abs(a.get_y()+3.2)<TOL)
       {
           cout<<" Setters Work\n"<<endl;
       }
       else
       {
           cout<<" Setters Failed\n"<<endl;
       }
   }

       if(toTest==4)
   {
       cout<<"\n**Translation Test: \n";
       a.translate(5.3,-3.2);
       if(abs(a.get_x()-5.3)<TOL && abs(a.get_y()+3.2)<TOL)
       {
           cout<<" Translate Works\n"<<endl;
       }
       else
       {
           cout<<" Translate Failed\n"<<endl;
       }
   }

   if(toTest==5)
   {
       cout<<"\n**Scale Test: \n";
       c.scale(-3);
       if(abs(c.get_x()-45.9)<TOL && (abs(c.get_y()-96.66)<TOL))
       {
           cout<<" Scale Works\n"<<endl;
       }
       else
       {
           cout<<" Scale Failed\n"<<endl;
       }

   }

   if(toTest==6)
   {
       cout<<"\n**Reflect Over X-Axis Test: ";
       c.reflect_x();
       if(abs(c.get_y()-32.22)<TOL)
       {
           cout<<" Reflect Over X-axis Works\n"<<endl;
       }
       else
       {
           cout<<" Reflect Over X-Axis Failed\n"<<endl;
       }

   }

   if(toTest==7)
   {
       cout<<"\n**Reflect Over Y-Axis Test: ";
       c.reflect_y();
       if(abs(c.get_x()-15.3)<TOL)
       {
           cout<<" Reflect Over Y-Axis Works\n"<<endl;
       }
       else
       {
           cout<<" Reflect Over Y-Axis Failed\n"<<endl;
       }

   }

   if(toTest==8)
   {
       Point e(-1,0); //e shoule be at (-1, 0)
       cout<<"\n**Rotation of Point Test: ";
       e.rotate(PI/2);
       if(abs(e.get_x())<TOL && abs(e.get_y()+1)<TOL)
       {
           cout<<" Rotation Of PI/2 (90 deg CCW) Worked\n"<<endl;
       }
       else
       {
           cout<<" Rotation Of PI/2 (90 deg CCW) Failed\n"<<endl;
       }
   }

   if(toTest==9)
   {
       cout<<"\n**Operator equals Test: ";
       d=b;
       if((abs(d.get_x()-b.get_x())<TOL) && (abs(d.get_y()-b.get_y())<TOL))
       {
           cout<<" Operator Equals Test Passed\n"<<endl;
       }
       else
       {
           cout<<" Operator Equals Test Failed\n"<<endl;
       }

   }

   if(toTest==10)
   {
       cout<<"\n**Operator equals equals Test: ";
       Point e(-15.3, -32.22);
       if(e==c)
       {
           cout<<" Operator equals equals Test Passed \n"<<endl;
       }
       else
       {
           cout<<" Operator equals equals Test Failed \n"<<endl;
       }
   }

   if(toTest==11)
   {
       cout<<"\n**CIN Test: \ncin the values 10 and 20 to test this with (10,20): ";
       cin>>d;
       if(abs(d.get_x()-10)<TOL && abs(d.get_y()-20)<TOL)
       {
           cout<<"CIN Test Passed\n"<<endl;
       }
       else
       {
           cout<<"CIN Test Failed\n"<<endl;
       }
   }

   if(toTest==12)
   {
       cout<<"**COUT Test: coutting Points a,b,c: \n";
       cout<<a;
       cout<<b;
       cout<<c;

   }*/
}

//Point.cpp

#include "Point.h"
#include <iostream>
#include <cstdlib>

using namespace std;

double x = 0;
double y = 0;

void Point::point()
{
   x = 0;
   y = 0;
}

void Point::point(double inX)
{
   x = inX;
   y = 0;
}

void Point::point(double inX, double inY)
{
   x = inX;
   y = inY;
}

double getX()
{
   return x;
}

double getY()
{
   return y;
}

void setPoint(double a, double b)
{
  
}

//Point.h

#include <iostream>
#ifndef Point_H;

using namespace std;

class Point
{
public:
static double x;
static double y;


void point();
void point(double x);
void point(double x, double y);

double getX();
double getY();

void setPoint(double a, double b);
};

#endif

Solutions

Expert Solution

/*** Point.h ***/

#include <iostream>
#ifndef POINT_H
#define POINT_H

using namespace std;

class Point
{
private:
double x;
double y;
public:
Point();
Point(double x);
Point(double x, double y);
Point(const Point&p);

double get_x();
double get_y();

void set_x(double inX);
void set_y(double inY);

void setPoint(double a, double b);
};

#endif

/*** Point.cpp ***/

#include "Point.h"
#include <iostream>
#include <cstdlib>

using namespace std;

Point::Point()
{
x = 0;
y = 0;
}

Point::Point(double inX)
{
x = inX;
y = 0;
}

Point::Point(double inX, double inY)
{
x = inX;
y = inY;
}

Point::Point(const Point&p)
{
x = p.x;
y = p.y;
}
double Point::get_x()
{
return x;
}

double Point::get_y()
{
return y;
}

void Point::set_x(double inX)
{
x = inX;
}
void Point::set_y(double inY)
{
y = inY;
}
void Point::setPoint(double a, double b)
{
x = a;
y = b;
}


/*** main.cpp ***/

#include <iostream>
#include <cmath>
#include "Point.h"
using namespace std;

const double PI = 3.14159265359;
const double TOL = .0000001; //allows us to do a comparison for double value equality
int main()
{

int toTest = 0;
//TEST AS YOU DEVELOP COMMENT OUT EVERYTHING BUT WHAT YOU HAVE IMPLEMENTED
//AND UNCOMMENT AS YOU CREATE.
//(you can look below to see what I make this variable to test given things)
cout << "MUST IMPLEMENT GETTERS BEFORE TESTING \n";
cout << "What would you like to test? \n";
cout << "1-value constructor \n";
cout << "2-copy constructor \n";
cout << "3-setters test \n";
cout << "4-translation test \n";
cout << "5-scaling test \n";
cout << "6-reflect over x-axis test \n";
cout << "7-reflect over y-axis test \n";
cout << "8-rotation \n";
cout << "9-assignment operator \n";
cout << "10-operator equals equals \n";
cout << "11-cin overload \n";
cout << "12-cout overload \n";
cin >> toTest;

Point a; // a should be at (0,0)
Point b(5.0); //b should be at (5.0,0)
/* incremental test line
Point c(-15.3, -32.22); //c should be at (-15.3, -32.33)


if(toTest==1)
{
cout<<"**Value Constructor Test: \n";
if(abs(a.get_x())<TOL && abs(a.get_y())<TOL &&
abs(b.get_x()-5)<TOL && abs(b.get_y())<TOL &&
abs(-15.3-c.get_x())<TOL && abs(-32.22-c.get_y())<TOL)
{
cout<<" Value Constructor Works\n" <<endl;
}
else
{
cout<<" Value Constructor Failed\n"<<endl;
}
}
Point d(c);
if(toTest==2)
{
cout<<"\n**Copy Constructor Test: \n";
if(abs(d.get_x()-c.get_x())<TOL && abs(d.get_y()-c.get_y())<TOL)
{
cout<<" Copy Constructor Works\n"<<endl;
}
else
{
cout<<" Copy Constructor Failed\n"<<endl;
}
}

if(toTest==3)
{
cout<<"\n**Setters Test: \n";
a.set_x(5.3); a.set_y(-3.2);
if(abs(a.get_x()-5.3)<TOL && abs(a.get_y()+3.2)<TOL)
{
cout<<" Setters Work\n"<<endl;
}
else
{
cout<<" Setters Failed\n"<<endl;
}
}

if(toTest==4)
{
cout<<"\n**Translation Test: \n";
a.translate(5.3,-3.2);
if(abs(a.get_x()-5.3)<TOL && abs(a.get_y()+3.2)<TOL)
{
cout<<" Translate Works\n"<<endl;
}
else
{
cout<<" Translate Failed\n"<<endl;
}
}

if(toTest==5)
{
cout<<"\n**Scale Test: \n";
c.scale(-3);
if(abs(c.get_x()-45.9)<TOL && (abs(c.get_y()-96.66)<TOL))
{
cout<<" Scale Works\n"<<endl;
}
else
{
cout<<" Scale Failed\n"<<endl;
}

}

if(toTest==6)
{
cout<<"\n**Reflect Over X-Axis Test: ";
c.reflect_x();
if(abs(c.get_y()-32.22)<TOL)
{
cout<<" Reflect Over X-axis Works\n"<<endl;
}
else
{
cout<<" Reflect Over X-Axis Failed\n"<<endl;
}

}

if(toTest==7)
{
cout<<"\n**Reflect Over Y-Axis Test: ";
c.reflect_y();
if(abs(c.get_x()-15.3)<TOL)
{
cout<<" Reflect Over Y-Axis Works\n"<<endl;
}
else
{
cout<<" Reflect Over Y-Axis Failed\n"<<endl;
}

}

if(toTest==8)
{
Point e(-1,0); //e shoule be at (-1, 0)
cout<<"\n**Rotation of Point Test: ";
e.rotate(PI/2);
if(abs(e.get_x())<TOL && abs(e.get_y()+1)<TOL)
{
cout<<" Rotation Of PI/2 (90 deg CCW) Worked\n"<<endl;
}
else
{
cout<<" Rotation Of PI/2 (90 deg CCW) Failed\n"<<endl;
}
}

if(toTest==9)
{
cout<<"\n**Operator equals Test: ";
d=b;
if((abs(d.get_x()-b.get_x())<TOL) && (abs(d.get_y()-b.get_y())<TOL))
{
cout<<" Operator Equals Test Passed\n"<<endl;
}
else
{
cout<<" Operator Equals Test Failed\n"<<endl;
}

}

if(toTest==10)
{
cout<<"\n**Operator equals equals Test: ";
Point e(-15.3, -32.22);
if(e==c)
{
cout<<" Operator equals equals Test Passed \n"<<endl;
}
else
{
cout<<" Operator equals equals Test Failed \n"<<endl;
}
}

if(toTest==11)
{
cout<<"\n**CIN Test: \ncin the values 10 and 20 to test this with (10,20): ";
cin>>d;
if(abs(d.get_x()-10)<TOL && abs(d.get_y()-20)<TOL)
{
cout<<"CIN Test Passed\n"<<endl;
}
else
{
cout<<"CIN Test Failed\n"<<endl;
}
}

if(toTest==12)
{
cout<<"**COUT Test: coutting Points a,b,c: \n";
cout<<a;
cout<<b;
cout<<c;

}*/
}

I  have fixed those errors without editing Main.cpp. Whether you face any problem or need any modification then share with me in the comment section, I'll happy to help you.

Thank You.


Related Solutions

how do i run 3 files on c++?
how do i run 3 files on c++?
I need to access the values in the pizzaLocations array when main.cpp is run. The values...
I need to access the values in the pizzaLocations array when main.cpp is run. The values include name, address, city, postalCode, province, latitude, longitude, priceRangeMax, priceRangeMin. I tried declaring getter functions, but that does not work. How do I access the values? Do I need to declare a function to return the values? operator[](size_t) - This should return the location with the matching index. For example if given an index of 3, you should return the location at index 3...
3 files cvehicle.h -- a partially filled-out class declaration for the CVehicle class main.cpp -- the...
3 files cvehicle.h -- a partially filled-out class declaration for the CVehicle class main.cpp -- the main module that creates and manipulates CVehicle objects cars.dat -- a text file that contains name data for the main module 4th file is cvehicle.cpp and it needs to be created from scratch, and cvehicle.h needs to be filled in This was the test drive: carOne = Hyundai Sonata carTwo = Hyundai Sonata carThree = Enter the make and model of a vehicle: toyota...
C++ Please create 4 different files with this respective names main.cpp , Pokemon.h , Pokemon.cpp Move.h...
C++ Please create 4 different files with this respective names main.cpp , Pokemon.h , Pokemon.cpp Move.h 16.5 Homework 5 Introduction Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP). Scenario You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and...
find all the errors c++ should be able to be compiled and run to perform the...
find all the errors c++ should be able to be compiled and run to perform the task #include iostream #include <string> Using namespace std; class Customer { // Constructor void Customer(string name, string address) : cust_name(name), cust_address(address) { acct_number = this.getNextAcctNumber(); } // Accessor to get the account number const int getAcctNumber() { return acct_number; } // Accessor to get the customer name string getCustName(} const { return cust_name; } // Accessor to get the customer address string getCustAddress() const...
hi! I have this code. when I run it, it works but in the print(the number...
hi! I have this code. when I run it, it works but in the print(the number we are searching for is ) it prints the number twice. ex. for 5 it prints 55 etc. apart from this, it works #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){ int n,i; printf("Give me the size of the table : \n"); scanf("%d", &n); int A[n],x,y; for (i=0;i<n;i++) A[i]=rand() % n; for (i=0;i<n;i++) printf("%d\n", A[i]); srand(time(NULL)); y=rand()% n ; printf("The number we are searching...
When I run this C++ program that asks the user to enter the population of 4...
When I run this C++ program that asks the user to enter the population of 4 cities and produce the bar graph - it runs but ends with a Debug Error - run time check failure 2 stack around variable population was corrupted - any help would be appreciated #include <iostream> using namespace std; int main() { int population[4],k;    int i=1,n=5;       do    {        cout<<"Enter the population of city "<<i<<":"<<endl;             cin>>population[i];        if(population[i]<0)       ...
The question I have to solve is that when two people A and B run in...
The question I have to solve is that when two people A and B run in the opposite direction at the same speed 0.6c, do they agree with the referee that says the result is draw. I want to approach this question in a different way so I set that A looks back to B when he runs to the goal and feels like B is running at 0.88c. Then does A think B is slower than A because the...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
4. Translate the following C code to MIPS assembly (in two separate files). Run the program...
4. Translate the following C code to MIPS assembly (in two separate files). Run the program step by step and observe the order of instructions being executed and the value of $sp. int main() { int x=2; z=Subfunc(x); printf(“Value of z is: %d”, z); } int Subfunc(int x) { return x+1;} Submission file: Lab4_4a.asm and Lab4_4b.asm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT