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.

这章将介绍大多数的C++的基本组成部分:内建类型,类库类型,类类型,变量,表达式,执行语句和函数。顺便,我们将简单解释如何编译和执行一个程序。

 

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

已经阅读完本章和做完练习,读者应该能够编写,编译和执行简单的程序。

 

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,销售数量和销售价格。每一笔交易的数据看起来像这样

 

0-201-70353-X
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.

第一个部分是isbn号,第二个是该书籍的销售数量,最后一个是销售价格。定期的,书店拥有者浏览这些文件,并且计算出每一本书的销售数量,那本书的销售额,和平均的销售价格。我们将提供一个程序来完成这些计算。

 

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,

在我们可以编写这个程序之前,我们需要知道C++的一些基本特征。至少,我们需要知道如何编写,编译和执行一个简单的C++程序。这个程序必须做什么?尽管我们还没有设计我们的解决方案,我们知道那个程序必须

 

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.

定义变量

完成输入和输出

定义一个数据结构去储存我们要管理的数据

测试两条记录是否有相同的ISBN

编写一个用于处理交易文件中每一条记录的循环。

 

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

我们将从阅读这些C++的这部分内容开始,然后为我们的书店问题编写一个解决方案。

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:

WordPress.com Logo

You are commenting using your WordPress.com 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