?

This is a discussion on ? within the C++ Programming forums, part of the General Programming Boards category; Dear C++ Programmers, I need your help. i would like to ask how I could get my program to read ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    ?

    Dear C++ Programmers,

    I need your help.
    i would like to ask how I could get my program to read coordinates i.e (21.5 W) this is a longitude!

    Thanks,
    Mubanga

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    47
    I'm not an expert, but I'm sure the experts will want to know how your program will get the coordinates (cout, ifstream, etc) and what they will be used for so they can put in a proper type for the rest of the program

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    4
    Dear C++ Programers,

    I want to know if there is a code I could write in C++ or import from Java or C and incorporate in my C++ program to accept input in the form of Coordinates namely; longitude and latitude e.g 21.5W {note all values in degrees} and use them in a calculation involving the Azimuthal angle of a satellite earth station.

    Thanks alot,
    Mubanga

  4. #4
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    Azimuthal angle of a satellite earth station!?

    are you trying to launch nuclear weapons?

    j/k

    are you looking for something like this?

    Code:
    #include<iostream.h>
    #include<ctype.h>
    
    int intcoordinate;
    char chardirection[1];
    
    main()
    {
    int toupper(int c);
    cout << "Enter the coordinates" << endl;
    cin >> intcoordinate;
    cout << "Enter the direction(E, W, S, N)" << endl;
    cin >> chardirection[0];
    chardirection[0] = toupper(int(chardirection[0]))
    if(int(chardirection[0]) == 87)
    {
    //code goes here for West direction
    }
    }
    //then all you need to do make 3 more if then statements
    //one for each direction and enter your math equation thing
    hope that helps

  5. #5
    Unregistered
    Guest
    21.5 W is either a string, if it is all one variable, or a combination of a double and a character. If you view it as the latter, then having the coordinates be a class or a struct has some merit. Here's a skeletal version of a possible class:

    class Longitude
    {
    private:
    double value;
    char direction;

    public:
    //using default methods
    void setValue(double);
    void setDirection(char );
    double getValue() const;
    char getDirection() const;
    void display() const;
    };

    //example of function definition:
    void Longitude::display()
    {
    cout << value << ' ' << direction;
    }

    int main()
    {
    //declare instance of Longitude using default default constructor
    Longitude coord1;

    //supply instance of Longitude with hard coded data, not very flexible
    coord1.setValue(54.2);
    coord1.setDirection('W');

    //do something with the object
    coord1.display();

    //and away you go.


    It is easier to code, but produces a less stable environment, if you use all public members. Using private data members with public accessor and mutator functions is the prefered approach in the long run.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21