Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ GIVEN CODE: Location.h #ifndef _LOCATION_H_ #define _LOCATION_H_ #include using namespace std; class Location { public : // Default constructor Location(); // Default constructor

In c++

GIVEN 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;

Question:

The UserRequest class is used to initiate a download request from the server.

The class contains the location of the user requesting to download, and details

of the file to be downloaded. Each UserRequest has a unique ID assigned to it,

with the first object assuming a value of 1. The ID should be incremented by

1 for each subsequent request. Create the definition and implementation files

for the UserRequest class. Define the member variables of the class as you see

fit (Hint: the functions should give you an idea of the required variables for the

class).

Member Variables:

UserRequest(Location* loc, int fileIndex): This constructs the UserRequest

object with the given location and index of a file that the user wishes to

download

Location* getLocation(): returns the user request location

int getMovieIndex(): returns the index of the movie file as initialized in

the constructor

int getRequestId(): returns the unique ID of the user request object

bool isComplete(): returns the status of the user request (i.e. if it has been

fulfilled or not)

void setComplete(bool): sets the status of the user request (i.e. if it has

been fulfilled or not)

void download(MovieFile* video, int bytes): initiates the download of a

movie and specifies the bytes (file size) transferred in the initial download.

It is only called once to start the download process. A deep copy of the

input video should be made and stored in the UserRequest object.

void download(int data): this function is used for subsequent download

activity, and simulates the continued receipt of data as the movie is being

downloaded. The input signifies additional chunk of data (in MB) to be

added to the overall file size.

int getAmountDownloaded(): returns the current file size

MovieFile* getDownloadedFile(): returns the downloaded file if it exists

(and null if it does not).

Remember to properly discard allocated memory when the class ceases to exist.

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

How to reverse a Armstrong number by using double linked list ?

Answered: 1 week ago