Chapter 1 Getting started

Chapter 1 Getting started


Section 1.1 Writing a simple c++ program.

This chapter introduces most of the basic
elements of C++: built-in, library, and class types; variables; expressions; statements;
and functions. Along the way, we’ll briefly explain how to compile and execute
a program.



Having read this chapter and walked through
the exercises, the reader should be able to write, compile, and execute simple



Learning a new programming language
requires writing programs. In this chapter, we will write a simple program to
solve a simple problem that represents a common data-processing task: A
bookstore keeps a file of transactions, each of which records the sale of a
given book. Each transaction contains a
n ISBN (International standard Book Number, a unique identifier
assigned to most books published through out the world.), the number of copies
sold, and the price at which each copy was sold. Each transaction looks like:

学习一门新的编程语言需要编写程序。在这一章,我们将编写一个简单的程序去解决一个具有代表性的常见的数据处理任务的简单问题, 一家书店保留销售记录的文件,每一个记录了特定书籍的销售。每一笔交易包含一个isbn,销售数量和销售价格。每一笔交易的数据看起来像这样


4 24.99

Where the first element is the ISBN, the
second is the number of books sold, and the last is the sales prices. Periodically,
the bookstore owner reads this file and computes the number of copies of each
title sold, the total revenue from that book, and the average sales price. We
want to supply a program to do these computations.



Before we can write this program, we need
to known some basic features of C++. At a minimum, we will need to know how to
write, compile, and execute a simple C++ program. What must this program do? Although
we have not yet designed our solution, we know that program must,



Define variables

Do input and output

Define a data structure to hold the data we
are managing.

Test whether two records have the same ISBN.

Write a loop that will process every record
in the transaction file.







We will start by reviewing these parts of
C++ and then write a solution to our bookstore problem.


This entry was posted in C++ primer(Fourth Edition). Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s