下载此文档

【工具辅导类】C++ By Example(四).pdf


文档分类:IT计算机 | 页数:约143页 举报非法文档有奖
1/ 143
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/ 143 下载此文档
文档列表 文档介绍
Part IV
Structures and File
Input/Output
C++ By
28EXAMPLE
Structures
Using structures, you have the ability to group data and work with
the grouped data as a whole. Business data processing uses the
concept of structures in almost every program. Being able to ma-
nipulate several variables as a single group makes your programs
easier to manage.
This chapter introduces the following concepts:
♦ Structure definitions
♦ Initializing structures
♦ The dot operator (.)
♦ Structure assignment
♦ Nested structures
This chapter is one of the last in the book to present new
concepts. The remainder of the book builds on the structure con-
cepts you learn in this chapter.
583
Chapter 28 ♦ Structures
Introduction to Structures
Structures can have A structure is a collection of one or more variable types. As you
members of different know, each element in an array must be the same data type, and you
data types.
must refer to the entire array by its name. Each element (called a
member) in a structure can be a different data type.
Suppose you wanted to keep track of your CD music collection.
You might want to track the following pieces of information about
each CD:
Title
Artist
Number of songs
Cost
Date purchased
There would be five members in this CD structure.
TIP: If you have programmed in puter languages, or
if you have ever used a database program, C++ structures are
analogous to file records, and members are analogous to fields
in those records.
After deciding on the members, you must decide what data
type each member is. The title and artist are character arrays, the
number of songs is an integer, the cost is floating-point, and the date
is another character array. This information is represented like this:
Member Name Data Type
Title Character array of 25 characters
Artist Character array of 20 characters
Number of songs Integer
Cost Floating-point
Date purchased Character array of eig

【工具辅导类】C++ By Example(四) 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数 143
  • 收藏数 0 收藏
  • 顶次数 0
  • 上传人 中国课件站
  • 文件大小 0 KB
  • 时间2011-07-19
最近更新