ok so I'm very new at classes and don't quite understand them much so this may seem simple.
What I have to do basically is write a program that takes in an angle (for example 149degree symbol34.8' W) and then prints it out on to the screen. I have to write a main() function that displays an angle initialized with the three argument constructor and an uninitialized angle that uses the default constructor.
Here's what I have so far:
#include <iostream>
using namespace std;
void greeting();
//Diplays the greeting.
class Angle
{
public:
Angle()
{
degrees = 0;
mins = 0;
direction = 0;
}
Angle(int d, double m, char di)
{
d = degrees;
m = mins;
di = direction;
}
~Angle(){}
void getAngle();
void displayAngle();
private:
int degrees;
double mins;
char direction;
};
int main()
{
char runagain;
Angle x;
greeting();
do
{
x.getAngle();
x.displayAngle();
cout << endl << endl << "Do you wish to run again? y/n ";
cin >> runagain;
runagain = tolower (runagain);
cout << endl;
}
while(runagain !='n');
system("pause");
return 0;
}
void greeting()
{
cout << "This program will print out angles that the user enters.\n";
}
void Angle::getAngle()
{
cout << "Please enter the number of degrees, minutes, and the direction: ";
cin >> degrees >> mins >> direction;
}
void Angle::displayAngle()
{
cout << "Angle is: " << degrees << (char)248 << mins << "'" << direction << endl;
}
I can't seem to be able to enter something that doesn't have three arguments and have it print out the default. Please help?