C++ :: Compute The Value Of A Polynomial

Mar 27, 2014

This program is supposed to find the value of a polynomial

with x being the number of terms

a[x] being the coefficients

b[x] being the exponents in each term

j being the variable

for example if

x=4

a[x]=1,2,1,5

b[x]=3,2,1,0

j=2

then the polynomial is (j*j*j)+2(j*j)+j+5

the value will be 23

however the value computed is wrong in the code below

#include <stdio.h>
#include <math.h>
int main()

[Code].....

View 4 Replies


ADVERTISEMENT

C :: Program Doesn't Properly Compute Simple Polynomial

Feb 7, 2014

The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.

Code:

#include <stdio.h>
int main(void)
{
int x, polynomial;
}

[code]...

View 5 Replies View Related

C :: Value Of A Polynomial In A Point

Jan 3, 2015

I don't know why this doesn't work. It doesn't return any errors, but it does the polynomial equation wrong. I tried using "^" instead of "pow" and it still does it wrong. I'm getting results like "-897123897" instead of "3". This is the code:

Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
[code]....

View 4 Replies View Related

C :: How To Get Derivative Of Polynomial

Nov 12, 2014

How to get the derivative of a polynomial.

Code:
#include "p.h"#include <stdio.h>
#include <stdlib.h>

/*----------------------------------------------*/
/* Sets all coefficients to 0 */
/*--------------------------------------------- */
void initialize(Polynomial p)

[Code] .....

View 2 Replies View Related

C++ :: Identify Polynomial With Two Arrays Of Same Length

Oct 15, 2014

I wanna write a class for polynomials, but there are some bugs in my code. I want to identify a polynomial with two arrays of the same length, one that contains the exponents of the nonzero monomials, and the other that contains the coefficients itself.

for example: (shematically)
3x^2 +5x^100 shoud be identified by array1=(2,100) and array2=(3,5)

the size of that polynomial should be Dim=2.

it should be possible to change the size dynamically.

Code:

#ifndef poly
#define poly
#include<cassert>
class poly {

[Code] ....

PROBLEM1 the destructor isnt working:
virtual ~poly() {delete [] start;delete [] koef;} //destruktor
Error: This declaration has no Storage class or typ specifier.
Error: Expected an identifier.

PROBLEM2 the constructor isnt working:
poly::poly(int x=0)
Error: Expected an identifier
Error: Expected a )
Error: Expected a ;.

I dont know what the computer want to tell me??

View 6 Replies View Related

C++ :: Program That Will Calculate Minimal Polynomial?

Apr 20, 2013

I need to make a program that will calculate minimal polynomial of the nxn matrix.

View 1 Replies View Related

C++ :: Extracting Polynomial Coefficient From String

Nov 30, 2013

I want to extract polynomial coefficient out of a string recieved by input, for example if i enter 4x^3+2x^4+3 , the resulting out put be : 2 , 4 , 0 , 0 , 3

View 10 Replies View Related

C/C++ :: Simple Polynomial Derivative Calculator

Feb 27, 2014

So I'm trying to make a derivative calculator that can do simple polynomial calculations in a very specific way. If you read the cout line you'll understand rather quickly.

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;
struct variable {
char Variable,degree,constant;

[Code] ....

I get an error at line 33 and 37 saying error: request for member '_cstr' in 'constant', which is of non-class type 'char'
and the same line with 'degree' instead of constant.

View 2 Replies View Related

C/C++ :: Define Polynomial Using Linked List

Mar 18, 2014

I'm try to write a program which define a polynomial using a linked list.

1) I fill every node of the list which list is as long as the value of the max power of the polynomial.
2) I print it out the resulting polynomial.
3) I want to re-scan the poly in search for the polynomials with the same index and sum them each other for having only one element with the same index, for instance, if I enter P(x) = 1 + x + x^2 + 3*x^2 + x^3, I want to obtain:
P(x) = 1 + x + (1 + 3)*x^2 + x^3.

I called this function SeekForSameIndex().

But with this example I have 4x^2 + 4x^2 + x^3, losing the firsts members of the expression, I'm behind this problem for days and I do not understand where's the mistake.

Here my code:

#include <stdio.h>
#include <stdlib.h>
struct SPoly {
int coeff;
unsigned int index;

[Code] ....

View 1 Replies View Related

C :: Implementing And Manipulating Polynomial ADT Using Linked List

Sep 23, 2014

Implementing and manipulating a Polynomial ADT using a linked list.

So far I have:

poly_ADT.h
Code: typedef struct nodeT{
int coef;
int powr;
struct nodeT *next;
} node;

[Code]...

I need to create a function that creates the polynomial using input first.

poly *poly_create (num,...) ;return a new polynomial with num terms terms are listed in order of lowest ordered-term to highest. i.e., to initialize poly 15x^6 + -9x^4 + 3x^2 call poly_create(3, 3,2, -9,4, 15,6 );

Once I do that I need to implement various functions that can manipulate the polynomial itself but I'm having trouble just with creating the polynomial itself, how to do that using a linked list and nodes?

View 3 Replies View Related

C++ :: Polynomial Objects - Deep Copy And Operator Overloading

Feb 22, 2015

In main I instantiate two Polynomial objects -- p1 and p2:

int main() {
const int SIZE = 3;
Polynomial *p1 = new Polynomial(SIZE);
Polynomial *p2 = new Polynomial(SIZE);

//Read data into p1
std::cout << "Initialize Polynomial Coefficients (1)" << std::endl;

[Code] .....

The implementation file for Polynomial is as follows:

Polynomial::~Polynomial() {
delete [] this->m_Ptr;
this->m_Ptr = NULL;
} Polynomial::Polynomial(int size) {

[Code] .....

What works: Adding two pointers. The output is correctly produced.

The problem in particular occurs in main when p1 and p2 are attempted to be multiplied. The code attempts to release the memory upon multiplication but I receive a run-time error.

The output for the difference of the two polynomial objects is incorrect. It is displaying addresses.

View 3 Replies View Related

C++ :: Polynomial Coefficients Are Memorialized In Field Of Real Double Precision Numbers

Mar 19, 2013

I am starting to learn C++.Designing class CPolynom to work with polynomials. The polynomial coefficients are memorialized in the field of real double precision numbers. Implement the following functions:

-Constructor, which defines the order of the polynomial CPolynom(int order)
-method to add the appropriate grade Coef(int exp, duble coef)
-method of addition, subtraction, multiplication and division two polynomials
-method to add a field coefficient
-method for nala

View 1 Replies View Related

C++ :: How To Compute Perimeter Of A Triangle

Jun 26, 2013

I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.

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

struct Point{
double x;
double y;

[Code] ......

I expect to get 0 for triangle1, but I get some strange value...

Here is the result

Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843

View 2 Replies View Related

C++ :: Compute And Output Power Set

Oct 30, 2013

I am trying to do a compute and output a power set program. The numbers will be input through a file. How to do a power set. Here is my code :

#include <iostream>
#include <fstream>
#include <string>
#include <ostream>
using namespace std;
int main () {
string array[21]; // creates array to hold names

[Code] .....

View 1 Replies View Related

C++ :: Compute Mean / Median / Mode For Map Construct

May 28, 2013

I am writing code, which reads an input file (280 MB) containing a list of words. I would like to compute

1) total # of words
2) total # of unique/distinct words
3) mean/median/mode of word count (Link)

I managed to get done with 1) and 2), but my program crashes for 3). I am not quite sure whether there are memory issues or some bug in the code.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

[Code] .....

View 2 Replies View Related

C++ :: Unable To Compute Standard Deviation?

Mar 15, 2014

Unable to compute Standard Deviation

View 1 Replies View Related

Visual C++ :: Loop To Compute Both Max And Min Of Vector?

Jul 12, 2014

How would I make a loop that would simultaneously compute both the max and min of a vector?

View 2 Replies View Related

C :: Flowchart - Program To Compute Average Of N Numbers

Feb 20, 2015

How can you draw a flow chart that will be used to write a program to compute Average of n numbers?

View 1 Replies View Related

C :: Compute Total Price Of Books By A Given Author

May 7, 2013

Given a structure book defined as follows and an array lib of books

Code:
struct Book{
char title[100];
char author[100];
int price;
struct Book *nextedition;
};

struct Book lib[1000]; I'm going to write a function to compute total price of books by a given author including all books which are future editions of his book, even if the author of that future edition is NOT the specified author. title author price nextedition Book1 Author1 25 &lib[2] Book2 Author2 20 NULL Book3 Author3 30 &lib[3] Book4 Author1 35 NULL
For the example above, given the author "Author1", the function should return 90 (=25+30+35), and given the author "Author 3", the function should return 65 (=30+35).

So here's my attempt:

Code:
int totalPrice(char author[100]){
int total=0;
for (i=0; i<numbooks; i++)
if(strcmp(author, lib[i].author==0))

[Code] ....

What I'm trying to do is finding the first book in the lib of the specified author using for loop and then let the while loop do the rest. However, it seems the price is over-counted after each iteration of the for loop but I don't know how to fix it.

View 2 Replies View Related

C++ :: Compute Area Of A Triangle Using Cross Product

Jan 8, 2015

I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.

I am beginning like this;

#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)

[Code] .....

View 5 Replies View Related

C++ :: How To Compute Financial Ratio With Using Header File

Aug 19, 2013

How to compute financial ratio in C++ with using header file?

Calculate in c++ program with 3 different file. - 2 file (cpp file) - 1 file (header file)

Information:

formula:-
*1.*Current ratio = (current asset / current liabilities)
*2.*Gross margin = (Revenue – Cost of goods sold) / Revenue
*3.*Operating margin= (Operating Income / Revenue)
*4.*Profit margin = (Net Profit / Revenue)
*5.*ROE= (Net Income/Shareholder's Equity)

I want put 5 formula to run the program. How to put 5 formula in the program but run one formula.

EXAMPLE: In the coding, write all financial ratio. When we compile, just asking 1 formula value only. We need to fixed, which formula to run. Just adjust the coding only.

View 7 Replies View Related

C++ :: Write Program That Uses Function To Compute The Cost?

Nov 1, 2013

Write a program that uses a function to compute the cost of a pizza with given diameter and the number of toppings. Constant will be the cost per toppings and cost per square inch. It will contain a reputable structure as well.

diameter=17
number of toppings=3

//complier directives
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>

[Code].....

View 6 Replies View Related

C++ :: Compute Mean And Standard Deviation From A Set Of 10 Random Scores

Nov 18, 2014

I have to write a program in which it is to compute the mean and standard deviation from a set of 10 random scores between 1 and 20. The C++ program should generate a set of scores randomly and then, compute the mean and standard deviation from such a set of scores.

View 2 Replies View Related

C/C++ :: Compute Sum And Average Of All Positive Integers Using Loop

Oct 8, 2014

I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;

[Code] .....

View 12 Replies View Related

C :: Compute Permutations Of Any String Entered - Function Will Not Return A Value

Jun 11, 2013

This is my program, for now it is intended to compute permutations of any string entered, but the function ox will not return the final x value. ox is the function that actually computes the permutations so the return of the x value is critical.

Code:
#include<stdio.h>
#include<string.h>
int ox(int x);
int main() {
int x;
char input[10];

[Code] .....

View 2 Replies View Related

C++ :: Program To Compute And Print A Billing Statement For Each Patient

Oct 17, 2013

Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:

a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00
b. telephone charge = $1.75
c. television charge = $3.50

Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:

How many days was the room occupied? 5
What type of room? P
Telephone used during the stay? N
Television used during the stay? Y

Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.

A statement (which yours MUST be identical to) for the data given follows:

Community Hospital Patient Billing Statement

Number of days in hospital: 5
Type of room: Private
Room charge:$ 625.00
Telephone charge:$ 0.00
Television charge:$ 17.50

TOTAL DUE = $642.50

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved