Dear fellows: This is my first post in this forum. Although I am relatively new to C++, I've been programming in perl for some years in data extraction. Now, I find myself in a very different situation: I'm writing an astronomical ephemeris software and, one of the things that catched me when I was thinking about the language to implement it, was the fact that, unlike C, C++ allows one to hide the implementation of the associated functions within a class, which I denote as a "struct on steroids".
The point of my question is that I want to create a class that will hold geographical and/or astronomical coordinates in both basic forms: as a double integer (decimal degrees) and a struct with field for sign, degree, minute and second. Whenever I fill one, the other should be automatically calculated and stored within the same class, so it can be transparent for the rest of the program to extract both forms. Problem is, I still can't seem to catch the logic of C++ because, although I have the conversion functions into place, they seem useless with these errors:
1 2 3
|
coord.cpp:49: error: ‘cout’ was not declared in this scope
coord.cpp:49: error: ‘endl’ was not declared in this scope
coord.cpp: In member function ‘void coord::printdec()’:
|
...
Could any of you share some light over this issues. the coord class should work in a way that, whenever and use coord.dec_to_bab the input (if there is one), or the value stored in dec in decimal degrees get converted into babilonian or sexagesimal degrees. Also, if I store any bab or dec degree into it, the prototype for the constructor should evaluate its conformity in order to avoid erronoeous data.... I just can't find a way to do any sanity checks for the user input with cin... :-( I hope Im making sense with this post. Thanks for your patience.
So here is the code:
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
|
class coord
{
short sign; /* carry sign explicitly since -0 not neg. */
double hh;
double mm;
double ss;
double dec; // Hold the full coords in decimal.
public:
coord(double initc); // Constructor
~coord(); // Destructor
void printdec();
double bab_to_dec(bab);
void dec_to_bab (deci,bab);
};
coord::coord(double initc) {
dec = initc;
}
coord::~coord() {
cout << "\ninside coord destructor" << endl;
printsize();
}
void coord::printdec() {
cout << "\nThe DEC coord is:" << dec << endl;
}
double coord::bab_to_dec(coord bab){
/* converts a "babylonian" (sexigesimal) structure into
double-precision floating point ("decimal") number. */
coord bab;
double x=dec;
x = bab.sign * (bab.hh + bab.mm / 60. + bab.ss / 3600.);
return(x);
}
void dec_to_bab (deci,bab)
{
double deci;
struct coord *bab;
dec = deci;
/* function for converting decimal to babylonian hh mm ss.ss */
int hr_int, min_int;
if (deci >= 0.) bab.sign = 1;
else {
bab.sign = -1;
deci = -1. * deci;
}
hr_int = deci; /* use conversion conventions to truncate */
bab.hh = hr_int;
min_int = 60. * (deci - bab.hh);
bab.mm = min_int;
bab.ss = 3600. * (deci - bab.hh - bab.mm / 60.);
}
|