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

A Complete Guide to Programming in C++ part 66. 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 629 float FloatArr operator int i throw Badlndex if i 0 i cnt throw Badlndex i return arrPtr i float FloatArr operator int i const throw Badlndex if i 0 i cnt throw Badlndex i return arrPtr i Append a float value or an array of floats. void FloatArr append float val if cnt 1 max expand cnt 1 arrPtr cnt val void FloatArr append const FloatArr v if cnt max expand cnt int count Necessary if v this. for int i 0 i count i arrPtr cnt i Inserts a float value or an array of floats. void FloatArr insert float val int pos throw Badlndex insert FloatArr 1 val pos void FloatArr insert const FloatArr v int pos throw BadIndex if pos 0 pos cnt Append is also possible. throw Badlndex pos if max cnt expand cnt int i for i cnt-1 i pos --i Shift up from arrPtr i arrPtr i position pos. for i 0 i i Fill the gap. arrPtr i pos i cnt cnt 630 CHAPTER 28 EXCEPTION HANDLING To delete void FloatArr remove int pos throw Badlndex if pos 0 pos cnt for int i pos i cnt-1 i arrPtr i arrPtr i 1 --cnt else throw Badlndex pos ----------------------------------------------------------- Tests exception handling for float arrays. ----------------------------------------------------------- include iostream include iomanip using namespace std include int main const FloatArr v 10 bool ok false while ok try cout Here is the constant array v n cout setw 8 v endl int i cout cout ok Index cin i nThe value read true v i endl catch BadIndex err cerr Error in reading. n nInvalid index endl SOLUTIONS 631 FloatArr w 20 Array w try 0 To write 1 3 Error w 10 Error 7 Error catch BadIndex err cerr nError in writing nInvalid index endl cout nHere is the array n cout setw 5 w endl return 0 Exercise 2 -------------------------------------------------------- A numeric class to represent fractions exception handling is included.

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.