0% found this document useful (0 votes)
109 views2 pages

Programming Fundamentals Lab Tasks

This document outlines 5 programming tasks for a fundamentals lab. Task 1 involves writing functions to calculate the sum of terms in a series given inputs for the number of terms and value of x. Task 2 involves writing a function to check if a number is perfect, then a program to print all perfect numbers between 1 and 1000 along with their factors. Task 3-5 instruct students to solve programming exercises from their textbook. Proper code formatting and naming is emphasized.

Uploaded by

NavEed RaZa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views2 pages

Programming Fundamentals Lab Tasks

This document outlines 5 programming tasks for a fundamentals lab. Task 1 involves writing functions to calculate the sum of terms in a series given inputs for the number of terms and value of x. Task 2 involves writing a function to check if a number is perfect, then a program to print all perfect numbers between 1 and 1000 along with their factors. Task 3-5 instruct students to solve programming exercises from their textbook. Proper code formatting and naming is emphasized.

Uploaded by

NavEed RaZa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Thursday, March 17, 2011.

Programming Fundamentals – Spring 2011


(BS-SE-F10 Morning & Afternoon)
Lab # 3

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

You might also like