cpp_lab2_x07 - Name Username CGS 2425 Introduction(Tour LAB...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Name Username ____________ CGS 2425 LAB EXAM 2 SUMMER 2007 Introduction (Tour) In this test, we will define two classes—City and Tour. A Tour object contains a dynamic array of cities. Suppose that all the necessary header files (<iostream>, <fstream>, <cmath>, <string> are included). In the class City , the name of the city is represented by a string. The class statement and all of the methods are given below. class City { private: string name; // name of city double x; // x coordinate double y; // y coordinate public: City(void){}; //void constructor City(string nn, double xi, double yi); //non-void constructor double dist(const City & cc)const; //distance to City cc, //you need implement double get_x(void){return x;} double get_y(void){return y;} string getName(void){return name;} }; City::City(string nn, double xi, double yi){ name = nn; x = xi; y = yi; } double City::dist(const City & cc) const{ return sqrt( pow((x cc.x),2) + pow((y cc.y),2) ); } The definition of class Tour is given by: class Tour // a class that contains a dynamic array of Cities { private: City * cities; //pointer to dynamical array of objects from class City int num; //the number of City objects in a Tour public: Tour(void) { cities = NULL; num = 0;} ; //void Tour constructor Tour(char *filename); //Tour constructor( to be implemented by you in 1) ~Tour(void); //Tour destructor (to be implemented by you in 2a) int getNum(void){return num;}; //gives total number of Cities in Tour double totalDist(); //finds total distance of Tour (implement in 2b) bool contains( string c_name); //checks if Tour has City (implement in 3) bool operator > ( Tour t){ return( totalDist() > t.totalDist());}; friend Tour operator + ( const Tour & t1, const Tour & s2);//implement in 4 };
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 You need to implement the Tour constructor Tour:Tour (char *filename) which constructs Tour object from the input file filename (see question 1). A Tour object contains a dynamically allocated array of City objects. The Tour object is constructed from the information stored in a file. The file has the following format: Miami 4.7 -2.6 Gainesville 12.3 4.8 Orlando 2.6 3.1 Ocala -5.1 1.9 The first column is the name of city, the second column is the x-coordinate, and the third column is the y-
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 04/17/2008 for the course CGS 2425 taught by Professor Kammerdiner during the Spring '08 term at University of Florida.

Page1 / 7

cpp_lab2_x07 - Name Username CGS 2425 Introduction(Tour LAB...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online