Absolute C++ (4th Edition) part 18

Absolute C++ (4th Edition) part 18. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Arrays array It is a capital mistake to theorize before one has data. Sir Arthur Conan Doyle Scandal in Bohemia Sherlock Holmes Introduction An array is used to process a collection of data all of which is of the same type such as a list of temperatures or a list of names. This chapter introduces the basics of defining and using arrays in C and presents many of the basic techniques used when designing algorithms and programs that use arrays. You may skip this chapter and read Chapter 6 and most of Chapter 7 which cover classes before reading this chapter. The only material in those chapters that uses material from this chapter is Section which introduces vectors. Introduction to Arrays Suppose we wish to write a program that reads in five test scores and performs some manipulations on these scores. For instance the program might compute the highest test score and then output the amount by which each score falls short of the highest. The highest score is not known until all five scores are read in. Hence all five scores must be retained in storage so that after the highest score is computed each score can be compared with it. To retain the five scores we will need something equivalent to five variables of type int. We could use five individual variables of type int but five variables are hard to keep track of and we may later want to change our program to handle 100 scores certainly 100 variables are impractical. An array is the perfect solution. An array behaves like a list of variables with a uniform naming mechanism that can be declared in a single line of simple code. For example the names for the five individual variables we need might be score 0 score 1 score 2 score 3 and score 4 . The part that does not change in this case score is the name of the array. The part that can change is the integer in the square brackets . declaring and referencing arrays In C an array consisting of five variables of type int can be declared as follows int score 5 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
111    329    1    15-05-2024
Đã 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.