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). Write member functions to get input from user, to display the output in 120.36°N format and use a constructor to initialise the object. Write a main() program for demonstrating the above
#include <iostream>
#include <Windows.h>
#include <wchar.h>
using namespace std;
//Define and implement class Angle
class Angle
{
private:
int degrees;//Degrees
float minut;//minutes
char direction;//Direction letter
public:
Angle()
{
this->degrees = 0;
this->direction = 'N';
this->minut = 0;
}
Angle(int _d, int min, char dl = 'N')//Paramitrazed contructor
{
this->degrees = _d;
this->direction = dl;
this->minut = min;
}
//input user
void Input()
{
cout << "Please enter date:\n";
cout << "Degrees: ";
cin >> this->degrees;
cout << "Minutes: ";
cin >> this->minut;
cout << "Direction: ";
cin >> this->direction;
}
void FormatOut()
{
cout << degrees << "." << minut << (char)248 << " " << direction << endl;
}
};
int main()
{
Angle ang;//Create object
ang.Input();//Input date
ang.FormatOut();//Out
return 0;
}
Comments
Leave a comment