Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,764 members, 7,809,939 topics. Date: Friday, 26 April 2024 at 05:32 PM

Programmer Should Please Help Me To Solve This C++ Questions - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programmer Should Please Help Me To Solve This C++ Questions (1644 Views)

29 Things That Every Beginner Programmer Should Know. / Help! Im Stuck With This C# Program / Check In: Submit Your C++ Questions Lets Solve (2) (3) (4)

(1) (Reply) (Go Down)

Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 5:47pm On Apr 01, 2015
please help me to solve this c++ questions .

1 Share

Re: Programmer Should Please Help Me To Solve This C++ Questions by codemarshal08(m): 7:40pm On Apr 01, 2015
Bros, what have u tried na ??
Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 12:33pm On Apr 02, 2015
please help in above questions
Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 12:33pm On Apr 02, 2015
please help in above questions
Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 12:54pm On Apr 02, 2015
They are asking you to implement the sine function using a series (I'm guessing it is Taylor series), you need to think of a formula that represents each term in the series using x as the focal point. For example think about this:

Step 1: User will input x
Step 2: Initialize a variable "i" for each term. "i" should increase by 2 as the number of terms increases by 1.
Step 3: Write a factorial function that will be called with "i" as an argument in it.
Step 4: Multiply each next term by (-1) so that you can alter the sign in each case.

I do not want to do it for you because I want you to understand it, that is why I am providing hints on how you can go about it.

(pow (x, (i+2))/factorial(i+2)) should be the basic logic for doing the magic. Remember to multiply by -1 to change the sign and include the "cmath" header file so that you can use the power function.

I do not like helping people that are lazy, if you want me to do it for you, you will need to show me something you have done so that I can help further.

Note: You made a mistake in the divisor of the third term. It should be "5" and not "7".
Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 8:06am On Apr 03, 2015
my area network is bad sir , this is what have tried

1 Like

Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 4:57pm On Apr 03, 2015
@ DangotePikin, please help me in the havove questions, have posted what have tried but doesn't run.
Re: Programmer Should Please Help Me To Solve This C++ Questions by obamartins(m): 8:24pm On Apr 03, 2015
You didn't include 'cmath'
Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 11:05pm On Apr 04, 2015
My internet modem is faulty. I am using my phone (old java nokia c3) to send this message now. There is no way I can compile codes on this phone, I will fix my computer this week, I will be able to do it for you before wednesday. I hope it wont be too late then...its not my fault, its d internet.
Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 11:08pm On Apr 04, 2015
Have you written any program that uses a formula before, like d quadractic formula? If you can write those then this shud not be difficult for you. My phone is so bad that i can not even view the image you uploaded, but i can promise you that i will fix my system and its internet before wednesday.
Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 5:14pm On Apr 05, 2015
@Oladg2 This is the solution to the number 2 i.e exponential function:

#include <iostream>
using namespace std;
//Returns approximate value of e^x using sum of first n terms of Taylor Series
float exponential(int n, float x)
{
float sum = 1.0f; // initialize sum of series

for (int i = n - 1; i > 0; --i )
sum = 1 + x * sum / i;

return sum;
}

// Driver program to test above function
int main()
{
int n;
float x=0.0;
cout<<"Enter a valuse for your n"<<endl;
cin>>n;
cout<<"Enter a valuse for your x"<<endl;
cin>>x;
//int n = 10;
//float x = 1.0f;
cout<<"e^x = ";
cout<<exponential(n, x)<<endl;
system("pause"wink;
return 0;
}

Let me know if it is showing you any errors.
Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 5:29pm On Apr 05, 2015
Solution to Question 1:

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

long factorial(int num) {
long result = 1;
for(int j = num; j > 1; j--)
result *= j;
return result;
}

double sin(double x, int terms) {
if(terms == 1)
return x;
double result = 0;
for(int j = 1; j <= terms; j++) {
if (j % 2 == 1)
result += pow(x, j * 2 - 1) / factorial(j * 2 - 1);
else
result -= pow(x, j * 2 - 1) / factorial(j * 2 - 1);
}
return result;
}



int main ()
{
//note: x is in radians and not degrees
double y=sin(1.05,10); // This is the line for your input, the first argument is for your radian (note: 1 radian = 180 degrees) while the second
//is d numba of terms
cout<<y;
system("pause"wink;
}



Let me know if you have any errors or questions.
Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 10:37pm On Apr 06, 2015
DangotePikin:
Solution to Question 1:

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

long factorial(int num) {
long result = 1;
for(int j = num; j > 1; j--)
result *= j;
return result;
}

double sin(double x, int terms) {
if(terms == 1)
return x;
double result = 0;
for(int j = 1; j <= terms; j++) {
if (j % 2 == 1)
result += pow(x, j * 2 - 1) / factorial(j * 2 - 1);
else
result -= pow(x, j * 2 - 1) / factorial(j * 2 - 1);
}
return result;
}



int main ()
{
//note: x is in radians and not degrees
double y=sin(1.05,10); // This is the line for your input, the first argument is for your radian (note: 1 radian = 180 degrees) while the second
//is d numba of terms
cout<<y;
system("pause"wink;
}



Let me know if you have any errors or questions.



tanks bro , I really appreciate , I pray that almighty God will continue to be blessing u sir . thanks.

4 Likes 1 Share

Re: Programmer Should Please Help Me To Solve This C++ Questions by DangotePikin: 11:03pm On Apr 06, 2015
Oladg2:




tanks bro , I really appreciate , I pray that almighty God will continue to be blessing u sir . thanks.
We thank God, but have you tried to run them?
Re: Programmer Should Please Help Me To Solve This C++ Questions by Oladg2: 10:08pm On Apr 07, 2015
DangotePikin:
We thank God, but have you tried to run them?
heap, have done DAT.
Re: Programmer Should Please Help Me To Solve This C++ Questions by Nairaface: 6:34am On Apr 11, 2015
Oladg2:
my area network is bad sir , this is what have tried
one cannot but to respect the Nigerian spirit. In spite of network and power issues, we forge ahead. Resilience! May God reward your efforts. Should make the people in places with better infrastructures have better appreciation for what they have.

(1) (Reply)

Live Question And Answer Section For Android, Java And Php From 7-10 Pm Everyday / Please Criticize It, Condemn It / Google And Udacity Launches Android Nanodegree To Teach Coding

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.