944,084 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1974
  • C++ RSS
Dec 14th, 2004
0

need help for programming

Expand Post »
hello, i need the help for computer programming in the class.

the question is below. i try to write the program, but it comes out a lot of error. please, help me to do this problem.

Write a C++ program for the function

f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3

Create an array with elements:

-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3

Compute the value of f1(x) for each element of the array.
Display results in a table:


element value f1(x)
--- --------------------------------------
0 -4.3


therefore, i start the program like

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

void msort(float y[],int);

int main()
{
const int size=8;
float arry[size]={-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3},i;
cout<<"element: "<<size<<"value: "<<value<<"fl(x): "<<msort<<endl;
cout<<"----------------------------------------\n";
for (int i=0;i<10;i++)
cout<<setw(3)<<i ;
array(ary,size);
for(int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
msort(arry,num);
for (int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
cout<<endl;
return 0;
}

void msort(float list[],int x)
{
int i;
float x;
for (int i=0;i<size;i++)
{
f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3
}
return
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sweetbaby is offline Offline
2 posts
since Nov 2004
Dec 15th, 2004
0

Re: need help for programming

Please use code tags.
^ in C++ is not number to the whatever power it is the bitwise OR. What you could do is write your own pow function eg.
C++ Syntax (Toggle Plain Text)
  1. float myPow(float value,int power)
  2. {
  3. int i = 0;
  4. float tempValue = value;
  5. for(i = 1; i < power; i++)
  6. {
  7.  
  8. value = value * tempValue;
  9.  
  10. }
  11.  
  12. return value;
  13. }
As for your code if you want size to be global declare it outside of main, or you could pass it to msort as a const parameter. The rest I not going to bother reading cause its a pain without code tags
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Printing a Hash Table
Next Thread in C++ Forum Timeline: Help with simple problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC