-->
当前位置:首页 > 题库

PROGRAMMING:Data spacing problem (overload + function template)

Luz5年前 (2021-05-10)题库447
Three classes are designed as follows: class CTime has three data members, HH, mm, SS, representing hours, minutes and seconds respectively, and has several constructors and an overloaded - (minus sign) member function. Class point has two data members, X and Y coordinates respectively, and has several constructors and an overloaded - (minus sign) member function. The class date has three data members, year, month and day, representing year, month and day respectively, and has several constructors and an overloaded (minus sign) member function.
It is required to design a function template template < < class T > < double dist (t a, t b) to return spacing for int, float, CTime, point and date or other types of data.
Among them, HH = 3600 * ss, mm = 60 * ss, year = 365 * day, month = 30 * day. For CTime and date types, the data is converted to SS or day for operation.
Input format:
Each line has an operation. The first number of each line is the element type. 1 is an integer element, 2 is a floating-point element, 3 is a point type, 4 is a time type, and 5 is a date type. If it is an integer element, then enter two integer data,
If it is a floating-point element, then input two floating-point data; if it is a point element, input two point data (x1 Y1 x2 Y2); if it is a time element, input two CTime data (hH1 MM1 SS1 HH2 mm2ss2); if it is a date data, input two date data (year1 month1 day1 year2 month2 Day2). Enter 0 to mark the end of input.
Output format:
For each input, output a spacing value per line.
Sample input:
1 2 5
4 18 21 22 18 20 31
3 2 4 5 9
5 2013 5 14 2013 5 15
2 2.2 9.9
0
Sample output:
three
fifty-one
five point eight three zero nine five
one
7.7






answer:If there is no answer, please comment