Question
This project will help you show your mastery of arrays , classes ,and libraries . Program Information Write a program to allow the user to
This project will help you show your mastery ofarrays,classes,andlibraries.
Program Information
Write a program to allow the user to calculate the distance between cities on a map.
Sounds pretty complicated, eh? Don't worry, we'll make a few simplifications here:
- The distances are calculated in map units on the 2D map.
- Each city is given a set of coordinates relative to some point on the map. We'll call this origin(0,0).
- There can only be a finite number of cities in the system at a given time (you decide this maximum).
But in order to make the system useful, we'll have to add a few other features:
- Each city has a name in addition to its coordinates (you can assume a maximum length for these names; but they must be able to hold spaces: Los Angeles, New York, etc.).
- The user selects what action to take from a menu:
1) Enter city Information 2) calculate Distance between two cities 3) Print All cities 4) Quit
- Make sure you allow them to choose their options by both the number and the capitalized letter(s) of the choice.
- They cannot calculate a distance until at least two cities have been entered.
- When they have exactly two cities, assume they are the ends and print their distance.
- When they have more than two cities, show them the list of cities and have them pick the two cities to calculate the distance between. Don't let them choose the same city for both ends of the 'trip'.
- If your list is full and they choose to enter another city, have them choose to eitherNOTenter the new city or to overwrite one of the earlier cities (they choose which one). Print the list of cities for them to choose from. (Remember, you still can't exceed your maximum list size!)
For those last two when you list the cities for them to choose, I'm assuming you'll do a numbered list and have them enter the position number of the city they are interested in. If you want to make it nicer, see theoption below.
Hint: You should have at least 2classes possibly 3 (see theoptionsbelow). One will bePointfrom the examples. (And, yes, you must use it as is!) Another should be aCityclassalmost exactly like:
const size_t MAX_CITY_NAME = ???; class City { Point location; char name[MAX_CITY_NAME]; public: double distance(const City & other) const { return location.distance(other.location); } Point get_location(void) const { return location; } // other methods and constructors here };
but with additions as noted. (But otherwise identical!)
Don't forget to separate all the details of city handling from the details of list management.
Hint: Eachclassshould be in its own library. Other libraries may also be used for collections of useful functions.
IMPORTANT NOTE: Also, detect whether the user entered a number or a name at prompts involving a list of the cities (including overwrite and distance). If they've entered a number, proceed as normal. If they've entered a name, use a search to decide which city it was. (If the name 'matches' multiple cities, you should print a new hopefully smaller list of the matches for them to choose from.)
Point.h:
#ifndef POINT_CLASS_HEADER_INCLUDED #define POINT_CLASS_HEADER_INCLUDED // A 2D point class class Point { double x, // x coordinate of point y; // y coordinate of point public: Point(void); Point(double new_x, double new_y); Point(const Point & p); void Output(void) const; // output this point void Input(void); // input this point // distance between this point and other double distance(const Point & other) const; // point in middle of this point and other Point midpoint(const Point & other) const; double get_x(void) const { return x; } // accessors double get_y(void) const { return y; } void set_x(double new_x); // mutators void set_y(double new_y); Point flip_x(void) const; // new point is this one flipped Point flip_y(void) const; // about specified axis Point shift_x(double move_by) const; // new point is this one Point shift_y(double move_by) const; // shifted move_by in the // specified direction }; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started