TAILIEUCHUNG - A Complete Guide to Programming in C++ part 37

A Complete Guide to Programming in C++ part 37. 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. | SOLUTIONS 339 Outputs the numbers cout The sorted numbers n endl for i 0 i cnt i cout setw 10 number i cout endl return 0 Exercise 2 ----------------------------------------------------- The class DayTime represents the time in hours minutes and seconds. ----------------------------------------------------- ifndef _DAYTIME_ define _DAYTIME_ include iostream include iomanip using namespace std class DayTime private short hour minute second bool overflow public DayTime int h 0 int m 0 int s 0 overflow false if setTime h m s this- setTime . hour minute second 0 bool setTime int hour int minute int second 0 if hour 0 hour 24 minute 0 minute 60 second 0 second 60 this- hour short hour this- minute short minute this- second short second return true else return false 340 CHAPTER 16 ARRAYS int getHour const return hour int getMinute const return minute int getSecond const return second int asSeconds const Daytime in seconds return 60 60 hour 60 minute second bool isLess DayTime t const Compares this and t. return asSeconds this- sSeconds void print const cout cout setfill 0 setw 2 setw 2 setw 2 setfill hour minute second Uhr endl void swap DayTime t Just one parameter DayTime temp t t this Swaps this and t this temp endif _DAYTIME ------------------------------------------------------- An array containing objects of class DayTime. ------------------------------------------------------- include Definition of class DayTime include iostream using namespace std char header n n Table with Daytimes n n int main DayTime timeTab 4 18 DayTime 10 25 DayTime 14 55 30 int i timeTab 3 .setTime 8 40 50 Last element. cout header endl SOLUTIONS 341 Output for i 0 i 4 i timeTab i .print cout endl To compute shortest and longest time int i_min 0 i_max 0 Indices for shortest and longest elements. for i 1 i 4 i if timeTab i .isLess timeTab i_min i_min i if timeTab i_max .isLess timeTab i i_max i cout nShortest time timeTab i_min .print .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.