C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
expand_more
expand_more
format_list_bulleted
Question
Chapter 11, Problem 1PP
a)
Program Plan Intro
To construct the class Pol_coord along with the member functions convToPolar() and showdata().
a)
Expert Solution
Explanation of Solution
//class definition classPol_coord { //two floating point data members dist and mathematical private: floatdist; float theta; //constructor and function prototypes public: Pol_coord(); voidshowdata(); voidconvToPolar(float,float); }; //constructor function Pol_coord::Pol_coord() { //setting the values to 0 dist=0; theta=0; } //function for finding the polar coordinates voidPol_coord::convToPolar(float x,float y) { dist=sqrt(pow(x,2)+pow(y,2)); theta=(atan(y/x)*(180/3.1416)); } //function for showing the data voidPol_coord::showdata() { cout<<"The polar coordinates are "; cout<<dist<<", "<<theta<<endl; return; }
Explanation:
Create the class Pol_coordwith two floating data members for distance and angle. The constructor is used for assigning these two values.The function convToPolar() is used for converting them into polar coordinates using the following formula:
dist=sqrt(pow(x,2)+pow(y,2)); theta=(atan(y/x)*(180/3.1416));
b)
Program Plan Intro
- Include the class declaration and implementation in the program.
- Create the objects of the class Pol_coordin the main function.
- Calculate the polar coordinates using the method convToPolar.
- Display the data member values using the function showValues.
Program Description: The purpose of the program is to find the polar coordinate values.
b)
Expert Solution
Explanation of Solution
Program:
#include<iostream> //including the header file for mathematical functions #include<cmath> usingnamespacestd; //class definition classPol_coord { //two floating point data members dist and mathematical private: floatdist; float theta; //constructor and function prototypes public: Pol_coord(); voidshowdata(); voidconvToPolar(float,float); }; //constructor function Pol_coord::Pol_coord() { //setting the values to 0 dist=0; theta=0; } //function for finding the polar coordinates voidPol_coord::convToPolar(float x,float y) { dist=sqrt(pow(x,2)+pow(y,2)); theta=(atan(y/x)*(180/3.1416)); } //function for showing the data voidPol_coord::showdata() { cout<<"The polar coordinates are "; cout<<dist<<", "<<theta<<endl; return; } intmain() { Pol_coord a; a.convToPolar(9.09326,5.25001); a.showdata(); return0; }
Explanation:
The object of the class Pol_coord is created and the function convToPolar ( float, float ) is called with float values and then function showdata() is called for displaying the polar coordinates in the output screen.
Output Screenshot:
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
State whether each of the following is true or false. If false, explain why g) Definitions can appear anywhere in the body of a function.
How should I answer the following regarding the first main function?
7. using c++, Write a void function that accepts an integer array a and a integer SizeA, and an integer n, and adds n to every element in that array. Be sure to develop an appropriate name for your function.
Chapter 11 Solutions
C++ for Engineers and Scientists
Knowledge Booster
Similar questions
- Use DeMorgan’s Law to find and simplify the negation ?′ of the following function: ?(?, ?, ?) = ?? + ?′? + ?′?′arrow_forward-Convert SES variable to a factor and assign the value labels “low”, ”middle” and “high” to the 3 levels of thevariable. Then -Define the variables complic, comorb, depressi, diabetes as factors. For all these factors, a zero means “no” and a 1 means “yes”. Assign these value labels through the function factor() and check the change using str()arrow_forwardDescribe the statements of the function main.arrow_forward
- State whether each of the following is true or false. If false, explain why e) All variables must be given a type when they’re defined.arrow_forward- Give an example of short circuit evaluation (in any language) and explain why it is short circuited - Give an example of an overloaded operator (in any language – but not overloaded by a function). Explain why it is overloaded.arrow_forwardUse C language and implement the following functions:arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr