2012年2月22日 星期三
Exercise #13
This assignment will give you practice in producing formatted output using C++ input/output classes. Create a class consisting of an int, an unsigned, a long, a short, and a double. Generate random numbers to assign to the members. Print 20 lines of output using the class. Each line should be printed exactly as illustrated below. Of course, the numbers will not match since they are random. The output specifications are:
The first column contains the int member left justified displayed in octal.
The second column contains the unsigned member left justified displayed in hex.
The third column contains the long member left justified displayed in decimal.
The fourth column contains the short member left justified displayed in hex.
The fifth column contains the double member right justified.
The sixth column contains the double member right justified.
The seventh column contains the double member right justified.
The integer types should be printed in a field of width 9, the doubles using a width of 12. Make sure you match the base indicators and the precision of the doubles.
Note: for the scientific output shown in the last two columns, your compiler will print the exponent as either a 2-digit or 3-digit number, but not both. You cannot control this. You will have to figure out a way to massage the double value to produce one of the scientific outputs.
62436 0X22E8 2888 1889 426.0986 4.261e+002 4.26e+02
72062 0X29AF 7884 106c 5.1463 5.146e+000 5.15e+00
47262 0X68E8 19107 5a62 0.9017 9.017e-001 9.02e-01
31237 0X1A6C 29243 2cce 39.5479 3.955e+001 3.95e+01
13020 0X33FD 17339 459d 0.0789 7.890e-002 7.89e-02
74524 0X7E67 8056 5b9e 0.6746 6.746e-001 6.75e-01
45040 0X1842 21039 596 1.3779 1.378e+000 1.38e+00
14051 0X1995 1452 408c 1.8856 1.886e+000 1.89e+00
12706 0X24CE 17308 6bfe 0.0308 3.078e-002 3.08e-02
37534 0X66C5 21689 6e05 0.9871 9.871e-001 9.87e-01
15311 0X2AC5 15003 a87 3.0408 3.041e+000 3.04e+00
56020 0X8D1 3278 200b 0.0388 3.877e-002 3.88e-02
67351 0X23A1 12797 41d1 1.9757 1.976e+000 1.98e+00
76410 0X3908 21582 5a36 0.4780 4.780e-001 4.78e-01
13472 0X42C1 7242 7193 4.8966 4.897e+000 4.90e+00
35644 0X5EDA 16355 350a 2.4271 2.427e+000 2.43e+00
16706 0X7E32 23414 360d 1.0195 1.019e+000 1.02e+00
62433 0X3CC4 26845 667b 1.1618 1.162e+000 1.16e+00
16543 0X1ABC 3301 5eac 0.6685 6.685e-001 6.69e-01
57772 0X5E7E 28111 51be 9.0853 9.085e+000 9.09e+00
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言