80 Introduction to C++ Programming and Graphics
3.7.2.Pascal’s triangle appears as
1
11
121
1331
14641
1 5 10 10 5 1
··················
Each entry is the sum of the two entries immediately above it, and the
outermost entries are equal to unity. The entries of thepth row provide
us with the coefficients of the binomial expansion (a+b)p−^1 , whereaand
bare two variables andpis an integer.
For example, whenp= 3, the third row provides us with the coefficients
of the quadratic expansion,
(a+b)^2 = 1 a^2 + 2 ab+ 1 b^2.
Whenp=4,
(a+b)^3 = 1 a^3 + 3 a^2 b+ 3 ab^2 + 1 b^3.
Write a program that computes and prints the Pascal triangle.
3.7.3.Modify the student code so that the number of grades recorded is printed
next to the students’ names before the grades.
3.7.4.Write a code that reads from a file the names of pets in a pet store, and
prints, nicely formatted, their species, age, and usual mood.
3.8 Sample algorithms
We have learned how to enter data from the keyboard, print data to the screen,
read data from a file, and write data to a file. In scientific and other applications,
the data are manipulated according to carefully designed algorithms to achieve
a specific goal.
We have defined an algorithm as a set of instructions that achieves a
goal through sequential or repetitive steps. Certain algorithms provide us with
systematic ways of eliminating events and narrowing down possibilities. Other
algorithms provide us with craftily devised methods of producing a sequence of
approximations to a desired solution.