C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Question
Book Icon
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
Check Mark

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

Program Plan:

  • 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
Check Mark

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:

C++ for Engineers and Scientists, Chapter 11, Problem 1PP

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
USE PYTHON PROGRAMMING LANGUAGE(OOP) 1. (Geometry: n-sided regular polygon) An n-sided regular polygon’s sides all have the same length and all of its angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: ■ A private int data field named n that defines the number of sides in the polygon. ■ A private float data field named the side that stores the length of the side. ■ A private float data field named x that defines the x-coordinate of the center of the polygon with a default value 0. ■ A private float data field named y that defines the y-coordinate of the center of the polygon with a default value 0. ■ A constructor that creates a regular polygon with the specified n (default 3), side (default 1), x (default 0), and y (default 0). ■ The accessor and mutator methods for all data fields. ■ The method getPerimeter() returns the perimeter of the polygon. ■ The method getArea() returns the area of the…
(C++) Create a class Cylinder with attributes base-radius and height, each of which defaults to 1 .Provide member functions that calculate the surface area ( = 2πrh) and the volume (= πr2h) of the cylinder. Also, provide set and get functions for the base radius and height attributes. The set functions should verify that base radius and height are each floating- point numbers larger than 0.0 and less than 20.0. Use M PI from < cmath > header for π.
(Hospital Class) Write a c++ class called 'Hospital' with Data Members: hospital name -string type- //store the name of the hospital Number of beds - integer type- //store number of beds in the hospital number of patient - integer type- // number of patients, consider each patient need one bed, if the hospital has 15 beds then no more than 15 patients Member Functions: Hospital(name, beds, patients) // Constructor to initilize data members addPatient() //to add one patient to number of patients currently in the hospital, just increment number of patient by 1 removePatient() //to remove one patient from number of patients currently in the hospital, just subtract one from number of patients displayInfo() // which just show information about the hospital: hospital name, number of beds, number of patients. Create a program that creates at least three Hospital objects or array of Hospital objects and tests the member functions of…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education