Question

Question: Define a class to find the third root of your B[15]. Please write this in...

Question: Define a class to find the third root of your B[15].

Please write this in programming C or C++ language and please explain what we are doing in each step.

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

Please find the code below:

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


class ThirdRoot{
public:

   // Returns the absolute value of n-mid*mid*mid
   double diff(double n,double mid)
   {
       if (n > (mid*mid*mid))
           return (n-(mid*mid*mid));
       else
           return ((mid*mid*mid) - n);
   }

   // Returns cube root of a no n
   double findThirdRoot(double n)
   {
       // Set start and end for binary search
       double start = 0, end = n;

       // Set precision
       double e = 0.0000001;

       while (true)
       {
           double mid = (start + end)/2;
           double error = diff(n, mid);

           // If error is less than e then mid is
           // our answer so return mid
           if (error <= e)
               return mid;

           // If mid*mid*mid is greater than n set
           // end = mid
           if ((mid*mid*mid) > n)
               end = mid;

           // If mid*mid*mid is less than n set
           // start = mid
           else
               start = mid;
       }
   }
};

int main(){
   cout<<"Enter the number : ";
   double num;
   cin>>num;
   ThirdRoot rootFinder;
   cout<<"Third root of number "<<num<<" is : "<<rootFinder.findThirdRoot(num);
   return 0;
}

output:

Add a comment
Know the answer?
Add Answer to:
Question: Define a class to find the third root of your B[15]. Please write this in...
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
  • Question (1) Write for statements that print the following sequences of values a) 30, 20, 10,...

    Question (1) Write for statements that print the following sequences of values a) 30, 20, 10, 0, –10, –20, –30 b) 15, 23, 31, 39, 47, 55 Question (2) Write a function call it cube to find the cube of each number. Please write this in programming C language and please explain what we are doing in each step.

  • Write a C++ program to check the upper and lower limits of different data types: int,...

    Write a C++ program to check the upper and lower limits of different data types: int, unsigned int, long long data type, unsigned long long data type, Bits in char data type, char data type signed char data type, unsigned char data type. Please write this in programming C++ language and please explain what we are doing in each step.

  • Please program in the Java language. a) Write driver class that instantiates 5 objects of class...

    Please program in the Java language. a) Write driver class that instantiates 5 objects of class Circle with radius is an even number from 2 to 10 b) Write/define the class Circle

  • A) Please implement a Python script to define a student class with the following attributes (instance...

    A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...

  • Programming Language in Healthcare - Please write at least 250 words. 1a. In your own words,...

    Programming Language in Healthcare - Please write at least 250 words. 1a. In your own words, discuss what is meant by programming language? 1b. Use the Internet to find an example of a voice recognition program (natural language) used in the healthcare industry. Please cite your source(s).

  • Write a function int levelSearch(Node* root, int key) that takes as input the root node of...

    Write a function int levelSearch(Node* root, int key) that takes as input the root node of a Binary Search tree and a key. The function searches the key in the BST and returns the level of the found node. If the key is not found in the tree, return -1. The level starts at 0 for the root node and increases from top to bottom. We have defined the following node C++ Node class for you: class Node { public:         ...

  • This is a data mining course question. We are using Data Mining: Concepts and Techniques third...

    This is a data mining course question. We are using Data Mining: Concepts and Techniques third edition. Please help with the following assignment. Thank you: Propose an algorithm, in pseudocode or in your favorite programming language, for the following: Please help me with this in pseudocode. Thank you. (a) The automatic generation of a concept hierarchy for nominal data based on the number of distinct values of attributes in the given schema.

  • Write a C++ program that does the following : Define a class myInt that has as...

    Write a C++ program that does the following : Define a class myInt that has as its single attribute an integer variable and that contains member functions for determining the following information for an object of type myInt: A. Is it multiple of 7 , 11 , or 13. B. Is the sum of its digits odd or even. C. What is the square root value. D.Is it a prime number. E. Is it a perfect number ( The sum...

  • Programming language question ( please help if you can ) write a function f1() with the...

    Programming language question ( please help if you can ) write a function f1() with the following requirements (in C language): - It must define a local array of char values. The size must be adjustable via define macro. The default size could be, say, 1000. - It must also define a static int n that increments the number of activation records. - It must also define a static long int addr that stores the starting address of the array....

  • 1.Define a class to hold information about a single point (Point class). 2.Write a method of...

    1.Define a class to hold information about a single point (Point class). 2.Write a method of the Point class to determine the distance to another Point. 3.Use composition to define a Circle. 4.Write a method of the Circle classes to determine if a Point is inside the Circle. 5.Write a method of the Circle classes to determine if a Circle is wholly inside another Circle. 6.Write a method of the Circle classes to determine if a circle surrounds another circle....

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