tailieunhanh - A Complete Guide to Programming in C++ part 32
A Complete Guide to Programming in C++ part 32. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | EXERCISES 289 Exercise 2 In the exercises for chapter 13 an initial version of the Date class containing members for day month and year was defined. Now extend this class to add additional methods are shown on the opposite page. The constructors and the method setDate replace the init method used in the former default constructor uses default values for example to initialize the objects in setDate method without any parameters writes the current date to the object. The constructor and the setDate method with three parameters do not need to perform range functionality will be added in the next exercise. The methods isEqual and isLess enable comparisons with a date passed to them. The method asString returns a reference to a string containing the date in the format mm-dd-year . will therefore need to convert any numerical values into their corresponding decimal strings. This operation is performed automatically when you use the operator to output a number to the standard output cout. In addition to the cin and cout streams with which you are already familiar so-called string streams with the same functionality also exist. However a string stream does not read keyboard input or output data on screen. Instead the target or source is a buffer in main allows you to perform formatting and conversion in main memory. Use an application program that calls all the methods defined in the class to test the Date class. Exercise 3 The Date class does not ensure that an object represents a valid avoid this issue add range checking functionality to the class. Range checking is performed by the constructor and the setDate method with three parameters. First write a function called isLeapYear that belongs to the bool type and checks whether the year passed to it is a leap year. Define the function as a global inline function and store it in the header file . Modify the setDate .
đang nạp các trang xem trước