2012年2月20日 星期一

Exercise #5


Exercise #5

This assignment will give you practice writing constructors and working with a multiple file application. Use the Point and Line header and source files from example 4-12 to complete this assignment. You are to create a Circle class consisting of:
  • Two data members, a Point representing the center of the Circle and a double for the radius.
  • A print() member function that displays Circle data as shown in the output on the next page. Your output should have the exact format as shown.
  • The following ten Circle constructor functions:
    • A default constructor the creates a unit Circle at the origin. That is, center (0,0) and radius 1.
    • A constructor with one double argument. The argument should be used for the radius. The center is assumed to be at the origin.
    • A constructor with two double arguments. The arguments should be used for x-y coordinates of the center. The radius is assumed to be 1.
    • A constructor with a Point and a double argument. The Point should be assigned to the center and the double to the radius. Pass the Point by reference to const.
    • A constructor with three double arguments. The first two doubles should be used for the x-y coordinates of the center. The third double represents the radius.
    • A constructor with two Point arguments. The first Point is the center, and the second represents a Point on the circle. Both points should be passed by reference (to const).
    • A constructor with a Point and a Line argument. The Point is the center. The Circle is tangent to the line. Assume that the Point does not lie on the Line. Pass the arguments by reference.
    • A constructor with one Line argument.  The Line represents the diameter of the Circle.
    • A constructor with a Circle argument and a double argument.  The Circle will be concentric to the argument’s Circle with the double radius.
    • A copy constructor.

Additional requirements:
  • Use the main() provided on the next page.
  • Use the files ex4-12p.h, ex4-12p.cpp, ex4-12lh, and ex4-12l.cpp for the Point and Line class definitions and member functions.
  • Create a multi-file application.  Put your Circle class definition in a separate header file and the Circle member function definitions in a separate source file.
  • Turn in only the Circle header file, the Circle member function source file, main() as a separate source file and the program output.
  • Use constructor initializers in every constructor, even though it is not required. This will help you become familiar with the syntax.

Use this main() for the program.

int main(void)
{
    Point P(2.3,1.3), Q(3.4,4.5), R(3.1,4.9);
    Line L(P,Q);
    Circle C1;
    C1.print();
    Circle C2(3.5);
    C2.print();
    Circle C3(2.6,3.5);
    C3.print();
    Circle C4(P,5.5);
    C4.print();
    Circle C5(1.1,2.3,5.8);
    C5.print();
    Circle C6(P,Q);
    C6.print();
    Circle C7(R,L);
    C7.print();
    Circle C8(L);
    C8.print();
    Circle C9(C8,5.0);
    C9.print();
    Circle C10(C9);
    C10.print();

    return 0;
}


Your output should look like this:

center=(0,0) radius=1
center=(0,0) radius=3.5
center=(2.6,3.5) radius=1
center=(?,?) radius=?
center=(?,?) radius=?
center=(?,?) radius=?
center=(?,?) radius=?
center=(?,?) radius=?
center=(?,?) radius=?
center=(?,?) radius=?

沒有留言:

張貼留言