I don't get the task

i don't understand the task, it just doesn't make sense, i am new at this please help me understand this.

and here is the task
http://pastebin.com/1fb4z9Hg
What is there not to understand?
There's nothing particularly unclear about these instructions.
yes sir, but i don't know how would i go about writing a class. could you suggest me a good book or a website.
Let me start that for you.

City.h
1
2
3
4
5
6
7
8
class City {
  private:
    string name;
    double latitude;
    double longitude;
  public:
    City();
};

City.cpp
1
2
3
4
5
City::City() {
  name = "";
  latitude = 0.0;
  longitude = 0.0;
}


could you suggest me a good book or a website.

http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/
SO HE IS WHAT I HAVE GOT FOR THE .h FILE COULD SOMEONE JUST LOOK OVER IT AND SEE IF I AM DOING IT RIGHT. AND SUGGEST ANY CHANGES I NEED TO MAKE. YOU GUYS ARE GREAT

the assignment webiste : http://sleepy.cs.surrey.sfu.ca/cmpt/courses/cmpt128/cmpt-128-assignments/assignment-4-hub-city

and the following is just the code for .h file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once
#include <exception>
#include <stdexcept>
using namespace std;

class city
{
public:
        // Constructors and Destructor
        // Default constructor, sets latitude and longitude to 0
        city();
        // Constructor, sets height and width to parameters w and h
        // Throws an invalid_argument exception if log or lat are <= 0
        // The exception's string indicates the error condition
        city(double lat, double log);
        // Destructor
        ~city();

        // Getters and Setters
        double getLatitude(){return latitude;}; //inline method
        double getLongitude(){return longitude;}; //inline method
        // The setter methods throw an invalid_argument exception
        // if log or lat are <= 0, the exception's string indicates the
        // error condition
        // Sets latitude to parameter lat
        void setLatitude(double lat);
        // Sets longitude to parameter log
        void setLongitude(double log);


private:
        double longitude;
        double latitude;
};




WHAT ELSE DO I NEED TO INCLUDE ACCORDING TO THE ASSIGNMENT. I GRATEFUL TO YOU ALL :)
Last edited on

WHAT ELSE DO I NEED TO INCLUDE ACCORDING TO THE ASSIGNMENT

Read the assignment? And turn your capslock off.
i did, i just need assurance that i have done it, because i know the part 5 and 6 from thepart 1 have to go in the .cpp file(hopefully i am right).
so here is the updated code please have a look at it and give me some advice.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*City.h Begins here */

//city.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include<iostream>
#include <exception>
#include <stdexcept>
#include <string>

const double PI= 3.14159265358979;
const double earth_radius= 6371;

class City{
private:
    std::string nm;
    double latitude;
    double longitude;
    
    bool check_latitude(double lati );
    bool check_longitude(double longi);

public:
        // Constructors and Destructor
        // Default constructor, sets latitude and longitude to 0
        City();
        // Constructor, sets height and width to parameters w and h
        // Throws an invalid_argument exception if log or lat are <= 0
        // The exception's string indicates the error condition
        City(std::string nm,double lati, double longi);
        // Destructor
        ~City();

        // Getters and Setters
        std::string getCityname(){return nm;};
        double getLatitude(){return latitude;}; //inline method
        double getLongitude(){return longitude;}; //inline method
        // The setter methods throw an invalid_argument exception
        // if log or lat are <= 0, the exception's string indicates the
        // error condition
        // Sets latitude to parameter lat
        void setLatitude(double lati);
        // Sets longitude to parameter log
        void setLongitude(double longi);
        // set the city nametion
        void setCityname(std::string nm);
        double distance(const City & c) const;
    friend std::ostream& operator<<(std::ostream& os, const City& c));           
};


/*City.h Ends here */

/*City.cpp Begins here */
// city.cpp : Defines the entry point for the console application.
//

#include"city.h"
#include<iostream>
#include<cmath>

// constructors
City::City() : nm(""), latitude(0.0), longitude(0.0) {}

City(std::string nm,double lati, double longi){
   setCityname(nm);
   setLatitude(lati);
   setLongitude(longi);
}

bool City::check_latitude(double lati)
{/* Range of latitude is [0,90]*/
    return lati >= 0 && lati<=90;
}

bool City::check_longitude(double longi)
{ /* Range of longitude is [0,180]*/
    return longi >=0 && longi <= 180;
}

//Setters
void City::setLatitude(double lati);
{
   if(! check_latitude(lati)){
     throw invalid_argument("latitude value out of bounds");
   }
     
   latitude=lati; 
}

void City::setLongitude(double longi);
{
   if(! check_longitude(longi)){
       throw invalid_argument("longitude value out of bounds");
   }
   
   longitude= longi;
}
void City::setCityname(std::string nm);
{
    this->nm = nm;  
}

double City::distance(const City & c) const
{
    double lati1  = this->latitude * (PI / 180);
    double lati2  = c.laltitude * (PI/180);
    double longi1 = this->longitude * (PI/180);
    double longi2 = c.longitude * (PI/180);
    
   double dist =  acos( sin(lati1) * sin(lati2) + cos(lati1) * cos(lati2) * cos(longi2−longi1) ) * earth_radius;
   return dist;
} 

std::ostream& operator<<(std::ostream& os, const City& c){
   os <<c.nm<<" " << c.latitude << " " << c.longitude<<endl; //
   return os;
}

 
/*City.cpp Ends here
 */
A small tip. You should initialize class members in the constructor initializer list, rather than the body where possible.
Topic archived. No new replies allowed.