Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Implement functions to meet the following specificaions. In each case, you should make an appropriate choice for the kind of parameter to use (a value parameter, a reference parameter, or a const reference parameter). These functions are neither member functions nor friends. A. A void function with one parameter (a polynomial p). The function prints the value of p evaluated at x=1, x=2, x=3,..., up to x=10. B. A void function with one parameter (a polynomial p). The function deletes the largest term in p, and this change should affect the actual argument.

OpenStudy (nick67):

Hi mugwump101, please check this solution; I used C++ on Eclipse Indigo for Linux 64 bits and it seems working. Let me know if I was right in the interpretation of your requirements. #include <iostream> using namespace std; struct p // polynomial single term { int val; // term value p* next_item; // next term address }; void a( p polynomial) { int x, power, poly_val; p* pointer; for(x=1; x<=10; x++) { pointer = &polynomial; power=1; poly_val=0; do { poly_val += power * pointer->val; pointer = pointer->next_item; power *= x; } while(pointer != NULL); cout << poly_val << endl; } return; } void b(p* polynomial) { p* pointer = polynomial; p* prv_pointer = pointer; do { pointer = pointer->next_item; if(pointer->next_item!=NULL) prv_pointer = pointer; } while(pointer->next_item!=NULL); prv_pointer->next_item=NULL; return; } int main() { p my_polynomial[3]; // test polynomial p(x) = x^2*a2 + x*a1 + a0 my_polynomial[0].val = 3; // a0 coefficient my_polynomial[0].next_item = &my_polynomial[1]; // next term address my_polynomial[1].val = 2; // a1 coefficient my_polynomial[1].next_item = &my_polynomial[2]; // next term address my_polynomial[2].val = 5; // a2 coefficient my_polynomial[2].next_item = NULL; // last term, next term address = NULL a(my_polynomial[0]); // first run on a 2nd order polynomial b(my_polynomial); // delete largest term so that polynomial is 1st order now a(my_polynomial[0]); // evaluates again on the new polynomial return 0; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!