Download PROGRAMMING FUNDAMENTALS IN C++

Transcript
29
b) The column on which these disks are initially threaded.
c) The column to which this stack of disks is to be moved
d) The column to be used as a temporary holding area.
Your program should print the precise instructions it will take to move the disks from a starting column
to the destination column. For example, to move a stack of three disks from column A to column C, your
program should print the following series of moves:
Figure 1.11:
9) a.
Hanoi-Tower puzzle
Create a class named Fractions having two integer data members named for a fraction's numerator
and denominator.
The class's default constructor should provide both data members with default values
of 1 if no explicit user initialization is provided.
an object's data values.
Additionally, provide member functions for displaying
Also provide the class with the member functions that are capable of adding,
subtracting, multiplying, and dividing two Fraction objects according to the following formulas:
Sum of two fractions: a/b + c/d = (ad +cb)/bd
Dierence of two fractions: a/b c/d = (ad cb)/bd
Product of two fractions: (a/b)X (c/d) = ac/bd
Division of two fractions: (a/b)/(c/d) = ad/cb
b.
Include the class written for a) in a working C++ program that tests each of the class's member
functions.
10) A stack is an ordered collection of data items in which access is possible only at one end, called the
top of the stack with the following basic operations:
1. Push: add an element to the top of the stack.
2. Pop: remove and return the top element of the stack.
3. Check if the stack is empty
4. Check if the stack is full.
It would be nice to have a stack class, because we could then use it to easily develop some applications
which need stack data structure.
a. For the moment, assume that we need to dene an integer stack class. Since a stack must stores a
collection of integers, we can use an integer array to model the stack and a pointer named Top to indicate
the location of the top of the stack. The array should have a xed size. So we can begin the declaration of
the class by selection two data members:
•
Provide an integer array data member to hold the stack elements (the size of the array is a constant).