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
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
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
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…
Chapter 11 Solutions
C++ for Engineers and Scientists
Knowledge Booster
Similar questions
- (Polymorphic Banking Program Using Account Hierarchy) Develop a polymorphic banking program using the Account hierarchy created in Exercise 19.10. Create a vector of Accountpointers to SavingsAccount and CheckingAccount objects. For each Account in the vector, allowthe user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As youprocess each Account, determine its type. If an Account is a SavingsAccount, calculate the amountof interest owed to the Account using member function calculateInterest, then add the interestto the account balance using member function credit. After processing an Account, print the updated account balance obtained by invoking base-class member function getBalance.arrow_forward(phyton) create a vehicle claas with max_speed and mileage. define a function that changes the max speed with the setMax_speed(new speed) function. Create an object of this class change the max_speed value of this object to 200 with the help of the function you definedarrow_forward(Rectangle Class) Create a class Rectangle with attributes length and width, each of whichdefaults to 1. Provide member functions that calculate the perimeter and the area of the rectangle.Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.arrow_forward
- (CP6) Write a function that is passed an array of structs and performs calculations. The function should locate the highest gpa from a group of students. The function is passed the array of structs, the first element to be searched, and the last element to be searched. The return value of the function is the highest gpa in the search range. struct data{ string name; double gpa;}; double highestGpa( data [ ], int, int ); data [ ] - array of structs to search int - first element to be searched int - last element to be searched return - highest gpa from grouparrow_forward(Polymorphic Application) You’ve been asked to develop a flight simulator that will haveelaborate graphical outputs. Explain why polymorphic programming could be especially effectivefor a problem of this nature.arrow_forward(Package Inheritance Hierarchy) Use the Package inheritance hierarchy created inExercise 19.9 to create a program that displays the address information and calculates the shippingcosts for several Packages. The program should contain a vector of Package pointers to objects ofclasses TwoDayPackage and OvernightPackage. Loop through the vector to process the Packagespolymorphically. For each Package, invoke get functions to obtain the address information of thesender and the recipient, then print the two addresses as they would appear on mailing labels. Also,call each Package’s calculateCost member function and print the result. Keep track of the totalshipping cost for all Packages in the vector, and display this total when the loop terminates.arrow_forward
- (Date Class Modification) Modify class Date in Fig. 17.17 to have the following capabilities: a) Output the date in multiple formats such as DDD YYYY MM/DD/YY June 14, 1992 b) Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). c) Create a Date constructor that reads the system date using the standard library functions of the header and sets the Date members. See your compiler’s reference documentation or en.cppreference.com/w/cpp/chrono/c for information on the functions in header . You might also want to check out C++11’s new chrono library at en.cppreference.com/w/cpp/chronoarrow_forwardQ3. (Python programming) Develop a user defined iterator for prime numbers using class. The prime numbers should be less than 100 and greater than 40arrow_forward(java programing) a) Code a definition for a class named ChessPiece. Its (public) attributes are:The name of the pieceIts position on the chess boardb) Code a definition for a class named ChessBoard that represents a chess board. Its attributes are:the height of the board in number of tiles (m tiles) – private attributethe width of the board in number of tiles (n tiles) – private attributea 2D array of type ChessPiece[][] of m rows by n columns – private attributepublic attributes of type ChessPiece, one for each type of piece on the chess board: the pawn, the king,the queen, the bishop, the knight, the rook. The value of each piece is the name of the piece.c) For the ChessBoard class, code a constructor that takes values to initialize these attributes.d) For the ChessBoard class, code 3 getters, one for each attribute that is not a chess piece.e) For the ChessBoard class, code 3 setters, one for each attribute that is not a chess piece.f) How could encapsulation be improved in this…arrow_forward
- (Card Shuffling and Dealing) Create a program to shuffle and deal a deck of cards. Theprogram should consist of class Card, class DeckOfCards and a driver program. Class Card shouldprovide:a) Data members face and suit of type int.b) A constructor that receives two ints representing the face and suit and uses them to initialize the data members.c) Two static arrays of strings representing the faces and suits.d) A toString function that returns the Card as a string in the form “face of suit.” Youcan use the + operator to concatenate strings.Class DeckOfCards should contain:a) An array of Cards named deck to store the Cards.b) An integer currentCard representing the next card to deal.c) A default constructor that initializes the Cards in the deck.d) A shuffle function that shuffles the Cards in the deck. The shuffle algorithm shoulditerate through the array of Cards. For each Card, randomly select another Card in thedeck and swap the two Cards.e) A dealCard function that returns the next…arrow_forward(Python) (The Stock class) Design a class named Stock to represent a company’s stock that contains: A private string data field named symbol for the stock’s symbol. A private string data field named name for the stock’s name. A private float data field named previousClosingPrice that stores the stock price for the previous day. A private float data field named currentPrice that stores the stock price for the current time. A constructor that creates a stock with the specified symbol, name, previous price, and current price. A get method for returning the stock name. A get method for returning the stock symbol. Getandsetmethodsforgetting/settingthestock’spreviousprice. Getandsetmethodsforgetting/settingthestock’scurrentprice. A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice. Draw the UML diagram for the class, and then implement the class. Write a test program that creates a Stock object with the stock…arrow_forward(C++) A class of points to be implemented for a two dimensional planeyou must write. This class should contain the following content: a. Subfields: x and y coordinate information.b. Default constructor: zero values to x and y valuesshould assign.c. The configurator that assigns a value: It must initialize by taking external parameters to x and y values.D. Duplicate constructor: Must create a copy by reference to another point type object.to. Getter and setter methods: Must be written for x and y subfields.f. differenceDone (Point other) method: This method should return the Euclidean distance between the point object and the "other" point object.g. The toString () method: It should return the point structured as a string.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education