Académique Documents
Professionnel Documents
Culture Documents
Task # 1
In this task, you are required to use separate functions to calculate the sum of the first few terms
(as specified by the user) of the following series:
x x 2 x3
f ( x) = 1 − + − + ...
1! 2! 3!
Your program will take two integers from the user:
Number of terms (n) of the above series for which the sum is required. Your program
should make sure that n > 0.
The value of x. Your program should make sure that x > 1.
The main function of your program MUST look exactly as follows. You can not even slightly
change this main function.
int main()
{
int n = getNumberOfTerms();
int x = getX ();
double sum = calculateSumOfSeries (x,n);
cout << "Sum of series is: " << setprecision(3) << sum << endl;
return 0;
}
Apart from the three functions which have been highlighted (in blue color) in the above main
function, you are also required to implement a function for finding the factorial of a given
integer, and a function to calculate the power. (Note: You cannot use any function from cmath
library)
Page 1 of 2
Thursday, March 17, 2011.
Task # 2
• A positive integer is called perfect if its factors including 1 (but not the number itself) sum up
to the number itself. For example, 6 is a perfect number because 1+2+3 = 6. Write a function:
bool isPerfect (int n)
which determines whether the number n is a perfect number or not. This function should
return true if n is a perfect number, otherwise it should return false.
• Now, use the above function to write a program which prints all perfect numbers between 1
and 1000. (Note: Your program will not take any input from the user)
• Now, modify your program so that it also displays the factors for each perfect number
displayed.
Task # 3
Solve Prog. Ex. # 5 on Page 341 of your text book
Task # 4
Solve Prog. Ex. # 6 on Page 341-342 of your text book
Task # 5
Solve Prog. Ex. # 7 on Page 342 of your text book
Note:
• Indent your code properly.
• Use meaningful variable names.
Page 2 of 2