Answer to Question #216058 in C++ for Hemambar

Question #216058

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


1
Expert's answer
2021-07-17T04:53:14-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS