Comments

Wednesday, November 21, 2012

OOP Take input in two object of class

Posted by at 9:30 PM Read our previous post

Object
In ocean navigation, locations are measured in degrees and minutes of latitude and longitude.
Thus if you’re lying off the mouth of Papeete Harbor in Tahiti, your location is 149
degrees 34.8 minutes west longitude, and 17 degrees 31.5 minutes south latitude. This is
written as 149°34.8’ W, 17°31.5’ S. There are 60 minutes in a degree. (An older system
also divided a minute into 60 seconds, but the modern approach is to use decimal minutes
instead.) Longitude is measured from 0 to 180 degrees, east or west from Greenwich,
England, to the international dateline in the Pacific. Latitude is measured from 0 to 90
degrees, north or south from the equator to the poles.
Create a class angle that includes three member variables: an int for degrees, a float
for minutes, and a char for the direction letter (N, S, E, or W). This class can hold either
a latitude variable or a longitude variable. Write one member function to obtain an angle
value (in degrees and minutes) and a direction from the user, and a second to display the
angle value in 179°59.9’ E format. Also write a three-argument constructor. Write a
main() program that displays an angle initialized with the constructor, and then, within a
loop, allows the user to input any angle value, and then displays the value. You can use
the hex character constant ‘\xF8’, which usually prints a degree (°) symbol.  

Source Code


#include <iostream>

using namespace std;



class direction

{
      
public:
       int degree;
       float minute;
       char direc,press;
       int degree1;
       float minute1;
       char dir1;

       direction ()
       {}

              int longitude(int d,float m,char dir)
              {
              degree=d;
              minute=m;
              direc=dir;

              if ((0<degree)&&(degree<=180))
              {     
                    
                           /*cout<<degree<<"\xF8"<<minute<<"\'"<<dir<<endl;*/
                     d=degree;
                     return(degree);
                    
              }
              else
              {
              cout<<"Enter correct information"<<endl;
              }


              }//////////////////////////////longtude/////////////////////

              int latitude(int d,float m,char dir)
              {
              degree1=d;
              minute1=m;
              dir1=dir;

              if ((0<degree1)&&(degree1<90))
              {     
                    
                     d=degree1;
                     return(degree1);
             
              }
              else
              {
              cout<<"Enter correct information"<<endl;
              }
              ////////////////////////// latitude ////////////////////////////////////

              }
};

class counter
{
public:
      
       void showdata(int a,int b,float c,float d,char e,char f)
       {
              for(int u=0;u<2;u++)
              {cout<<a<<"\xF8"<<c<<"\'"<<e<<endl;
              cout<<b<<"\xF8"<<d<<"\'"<<f<<endl;}


       }
      
      
};
void main()
{
       direction dirc;
       counter counterx;

       int inputdeg,inputdeg2,ship;
       float min,min2;
       char dir,dir2;
       int clas1,clas2;

       cout<<"Enter Degree for longitute"<<endl;
       cin>>inputdeg;
       cout<<"Enter minutes for longitute"<<endl;
       cin>>min;
       cout<<"Enter Direction for longitute Press E for east and W for west"<<endl;
       cin>>dir;
      
       cout<<"Enter Degree for latitude"<<endl;
       cin>>inputdeg2;
       cout<<"Enter minutes for latitude"<<endl;
       cin>>min2;
       cout<<"Enter Direction for latitude Press N for east and S for west"<<endl;
       cin>>dir2;

       clas1=dirc.longitude(inputdeg,min,dir);
       clas2=dirc.latitude(inputdeg2,min2,dir2);
       counterx.showdata(clas1,clas2,min,min2,dir,dir2);

}

 Output

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template