Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I am getting an error when compiling my C++ main.cpp code. Would you mind telling me what could be the problem? Code: Location.h #ifndef

Hi I am getting an error when compiling my C++ main.cpp code.

Would you mind telling me what could be the problem?

Code:

Location.h

#ifndef _LOCATION_H_ #define _LOCATION_H_ #include using namespace std; class Location { public : // Default constructor Location(); // Default constructor Location(int _x,int _y); int getX(); // returns the x coordinate int getY(); // returns the y coordinate // computes the Euclidean distance float computeDistance(const Location& loc); // returns the location coordinates in the following // string format: (x,y) string toString(); private : int x; // variable for x coordinate int y; // variable for y coordinate }; // end of class definition #endif

Location.cpp

#include #include #include"Location.h" using namespace std; // Default constructor Location::Location(){ x = 0; y = 0; } // parameterized constructor Location::Location(int _x,int _y){ x = _x; y = _y; } int Location::getX() // returns the x coordinate { return x; } int Location::getY() // returns the y coordinate { return y; } // computes the Euclidean distance float Location::computeDistance(const Location& loc) { return sqrt(pow(x - loc.x, 2) + pow(y - loc.y, 2)); } // returns the location coordinates in the following // string format: (x,y) string Location::toString(){ string loc = "(" + to_string(x) + "," + to_string(y) + ")"; return loc; }

MovieFile.h

#ifndef _MOVIE_H_ #define _MOVIE_H_ #include using namespace std; class MovieFile { public : // the constructor should receive 3 parameters: // the name of a movie file, its duration in minutes, // and the file size with a default value of 0 MovieFile(string, int, int); // copy constructor that copies all information from the input object MovieFile(const MovieFile& other); // returns the filename string getName(); // returns duration of the movie int getDuration(); // returns file size int getFileSize(); // sets file size void setFileSize(int); // adds the input value to the current file size. void appendFileSize(int); private : string title; // title of movie long duration; // duration of movie int size; // size of a movie file (in MB) }; #endif

MovieFile.cpp

#include #include "MovieFile.h" using namespace std; // the constructor should receive 3 parameters: // the name of a movie file, its duration in minutes, // and the file size with a default value of 0 MovieFile::MovieFile(string _title, int _dur, int _size = 0){ title = _title; duration = _dur; size = _size; } // copy constructor that copies all information from the input object MovieFile::MovieFile(const MovieFile& other){ title = other.title; duration = other.duration; size = other.size; } // returns the filename string MovieFile::getName(){ return title; } // returns duration of the movie int MovieFile::getDuration(){ return duration; } // returns file size int MovieFile::getFileSize(){ return size; } // sets file size void MovieFile::setFileSize(int _size){ size = _size; } // adds the input value to the current file size. void MovieFile::appendFileSize(int _size){ size += _size; }

main.cpp

#include  #include "Location.h" #include "MovieFile.h" using namespace std; int main() { //-------------------------------------------- // Example code: Location class //-------------------------------------------- Location* loc1 = new Location(30,10); Location* loc2 = new Location(20,20); cout << loc1->computeDistance(*loc2) << endl; //output: 14.1421 cout << loc2->toString() << endl; //output: (20,20) delete loc1; delete loc2; loc1 = NULL; loc2 = NULL; //-------------------------------------------- // Example code: MovieFile class //-------------------------------------------- MovieFile* movie1 = new MovieFile("Black Panther", 120, 350); cout << movie1->getFileSize() << endl; //output: 350 movie1->setFileSize(50) ; cout << movie1->getFileSize() << endl; //output: 50 delete movie1; movie1 = nullptr; return 0; }

ERROR OUTPUT

main.cpp:(.text+0x26): undefined reference to 'Location::Location(int, int) '

main.cpp:(.text+0x26): undefined reference to 'Location::Location(int, int)'

main.cpp:(.text+0x26): undefined reference to 'Location::computeDistance(Location const&)'

As well as errors for the Movie file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions

Question

Describe commonly used methods for resolving a negotiation impasse.

Answered: 1 week ago

Question

What is entrepreneurship?

Answered: 1 week ago