Hello I'm doing C++, had some really hard problems with the following questions. I'm using code blocks and wondered if somebody can give me the answers to these problems, my book doesn't answer them
1.Write a program to swap positions of digits of a user entered three-digit integer N,
where N is equal or between 101 and 999. (i.e. if user enters 389 your program
should print 983. If user enters 300 program should print 003). Repeatedly ask user
for correct N, if he/she enters an integer N which is not in the range.
2. Given that y= 4*( 1- 1/3 + 1/5- 1/7+ 1/9-...plus or minus 1/N)
Write a program using a for-loop or a
while-loop to compute and print the sum of first 50 terms of y.
3. a) Write a user-defined function funGx to compute G(x), where
5 if x<-10
x^2 +(5/x) if -10 <=x<-5
x^2 - (5/x-5) if -5<=x<5
x^2 -(5/x) if 5<=x<10
-5 if x>=10
b) Call the user-defined function funGx in main function to compute and print
G(x)values for x= -15.5 , x=5, and x= 0.5 in an informative sentence.
For the first one you obviously have to use a string to read the numbers because in c++, there is no such thing as 003, only a string can hold this form. But you do have to still check if the string is an integer and if it is in the range 101 - 999
For the second one, set your for loop to loop 50 times, have a value n = 1.0 and a value total = 0, and use a boolean to dictate if you will be adding or subtracting. For each loop, depending on the value of the boolean you either add 1/n to total or your subtract 1/n from the total, then add 2 to n and set the boolean to the opposite value.
In the end you multiply total by 4 and return that value
For third one use if statements to determine what action to do depending on the value of x your function receives. I will advice separating each operation into functions to make the program easier to debug. Also do the operations in the order they were stated in the problem. i.e.
if you get x = 20, first check if 20 < -10
If not, check if it is equal to -10 or less than -5
if not check if it is equal to -5 or < 5
....