Question

2) Write a C++ program that uses a class called “Degree” to obtain the trigonometric values...

2) Write a C++ program that uses a class called “Degree” to obtain the trigonometric
values for angles given in degrees. This is because the trigonometric functions
defined in the library file <cmath> are applied to radian angles only. Use the constant
DEG2RAD = 0.017453 for conversion from degrees to radians. This class must
include a constructor, destructor, and the following functions:
a. void set_value(double)
b. double get_value()
c. double get_sine()
d. double get_cosine()
e. double get_tangent()
f. void read_value()
Your main function should simply demonstrate the use of this class, i.e., prompt a
user for an angle in degrees and display the sine, cosine and tangent of that angle.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<cmath>
using namespace std;

double DEG2RAD = 0.017453;

class TrigonometryCalculator

{

public:

double value;

double radValue;

//constructor

TrigonometryCalculator(double x)

{

radValue = x*DEG2RAD;
value = x;

}

void set_value(double x)

{

radValue = x*DEG2RAD;

value = x;

}

void read_value(double x)

{

cout<<"Value: "<<value<<endl;

}

double get_value()
{

return value;

}

//get Sine of the angle

double get_sine()

{

return sin(radValue);

}

//get Cosine of the angle

double get_cosine()

{

return cos(radValue);

}

//get tangent of the angle

double get_tangent()

{

return tan(radValue);

}

//Destructor

~TrigonometryCalculator()

{

cout<<"Destructor Called."<<endl;

}

};

//Driver Function

int main()

{

// An object of TrigonometricCalculator is made
TrigonometryCalculator A(30); //angle of 30 degrees is passed
cout<<"Sine of 30 degree is : "<<A.get_sine()<<endl;
cout<<"Cosine of 30 degree is : "<<A.get_cosine()<<endl;
cout<<"Tangent of 30 degree is : "<<A.get_tangent()<<endl;

}

Output:

Add a comment
Know the answer?
Add Answer to:
2) Write a C++ program that uses a class called “Degree” to obtain the trigonometric values...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • **This is for the C Language. Trigonometric Calculator Specification You are required to write a program...

    **This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...

  • NEED THE MATLAB CODE Sometimes it is convenient to have a table of sine, cosine, and...

    NEED THE MATLAB CODE Sometimes it is convenient to have a table of sine, cosine, and tangent values instead of using a calculator. Create a table of all three of these trigonometric functions for angles from 0 to 4pi. Prompt the user for the increment in radians. Use disp and fprintf to create a table with a title, column headings, and appropriate spacing. Your table should contain a column for the angle, followed by the three trigonometric function values.  

  • C++: vectors. Euclidean vectors are sets of values which represent values in a dimensional field. A...

    C++: vectors. Euclidean vectors are sets of values which represent values in a dimensional field. A 2d vector would represent values in x,y space (an ordered pair of coordinates) and a 3d vector would represent values in x,y,z space (an ordered triplet of coordinates). We define the basic definition of the 2d vector as follows: class Vector2D { public: Vector2D (); Vector2D (double ,double ); double dotProduct(Vector2D& ); friend Vector2D& operator +(Vector2D&, Vector2D&); friend std::ostream& operator <<(std::ostream& o, Vector2D& a);...

  • I need a simple program in C language that calculates the values of Sine, Cosine, and...

    I need a simple program in C language that calculates the values of Sine, Cosine, and Tangent of values given in degrees. It has to be a range of values between 0 and 360(integer values). The output should be a table of values showing Sin, Cos and Tan values. The complete computation and printing of the table must be done inside a function. The function also returns to the main program with 3 output arguments: It also needs to show...

  • Write a program to compute the area of a triangle using side-angle-side method and reports the...

    Write a program to compute the area of a triangle using side-angle-side method and reports the area of that triangle (rounded to 2 decimal places). Side-angle-side formula: ???? = 1/ 2 ?? sin(?), where a and b are two sides of the triangle, and C is the included angle. Your program must meet the following criteria to receive full marks: • Randomly generate two values between 5 and 10 (inclusive) for two sides a and b of the triangle, respectively....

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • C++ program Create a class Time having data members HH, MM, SS of type integer. Write...

    C++ program Create a class Time having data members HH, MM, SS of type integer. Write a C++ program to do the following: 1. Use a Constructor to initialize HH, MM, SS to 0. 2. Create two Objects of this class and read the values of HH, MM, SS from the user for both objects (Using proper member functions). 3. Use a binary + operator to add these two objects created (Store & display result using separate object). 4. Use...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT