Assignment Two: Functions, variables, operators, and pointers
Part One:
In this assignment, you will write a program from scratch. It should
have a main function, just like all C++ programs, and the main
function should call three other functions. One function will return
the sum of the square of each number from one to some value given by
the parameter. The diagram below shows what I mean by this. The
other function will calculate the sum of the multiplicative inverse of
the squares of the same numbers. This is also shown below. The third
function should take a pointer to a variable and square the variable,
NOT return the square of the variable. Don't use the pointer function
in the sum functions. Example of the first two functions:
1*1 + 2*2 + 3*3 + 4*4 + ... + n*n
1 1 1 1 1
--- + --- + --- + --- + ... + ---
1*1 2*2 3*3 4*4 n*n
You should also use input and output. Read in the numbers which you
will sum to, and print out the results in some reasonable form.
Caution!
There are a few things to watch out for.
- Make sure that you use the correct types. The number 1 is an
integer literal, use 1.0 for doubles.
- Don't forget that integer division truncates!
- Make good use of comments!