C&C++学习笔记1--The seven steps of programming

《C Primer Plus 5th Edition》摘录

The seven steps of programming

1.Define the program objectives.

2.Design the program

3.Write the code.

4.Compile.

5.Run the program.

6.Test and debug the program

7,Maintain and modify the program


Step 1: Define the Program Objectives

You should start with a clear idea of what you want the program to do.Think in terms ofthe information you program needs, the feats of calculation and manipulation the program needs to do, and the information the program should report  back to you. At this level of planning,you should be thinking in general terms, not in terms of some specific computer language.

Step 2: Design the program 

After you have a conceptual picture of what your program ought to do, you should decidehow the program will go about it.What should the user interface be like?How should the program be organized?Who will the target user be?How much time do you have to complete the program?

You also need to decide how to represent the data in the program and,possibly ,in auxiliary files,as well as which methods to use to process the data.When you first learn programming in C,the choices will be simple,but as you deal with more complex situations, you'll find that these decisions require more thought.Choosing a good way to represent the information can often make designing the program and processing the data much easier.

Again, you should be thinking in general terms, not about specific code, but some of your decisions may be based on general characteristics of the language.For example, a C programmer has more options in data representation than ,say ,a Pascal programmer.

Step 3:Write the Code 

Now that you have a clear design for your program, you can begin to implement it by writing the code.That is ,you translate your program design into the C language,Here is where you really have to get your code into the computer.The mechanics of this process depend on your programming environment. We'll present the details for some common environments soon. In general, you use a text editor to create what is called a source code file. This file contains the C rendition of your program design.

Example

#include <stdio.h>
int main()
{
int dogs;
printf("How many dogs you have?\n");
scanf("%d",&dogs);
printf("So you have %d dog(s)!\n",dogs);
return 0;
}
As part of this step, you should document your work.

Step 4:Compile

The next step is to compile the source code.Again,the details depend in your programming environment, and we'll look at some common environments shortly.For now .let start with a more concept view of what happens.

Recall that the compiler is a program whose job is to convert source code into executable code. Executable code is code in the native language, or machine language , of your computer .This language consists of detailed instructions expressed in a numeric code. As you read earlier, different computer have different machine languages, and a C compiler translates C into a particular machine language. C compiler also incorporate code form C libraries into the final program; the libraries contain a fund of standard routines ,such as printf() and scnaf(),for your use.

The compiler also checks that your program is valid C, If the compiler finds errors, it reports them to you and doesn't produce an executable file. Understanding a particular compiler's complains is another skill you will pick up.
Step 5:Run the Program

Traditionally, the executable file is a program you can run. to run the program in many common environments, including MS-DOS, Unix, Linux consoles ,just type the name of the executable file. 

Step 6:Test and Debug the Program

The fact that your program runs is a good sign, but it's possible that it could run incorrectly.Consequently, you should check to see that your program does what it is supposed to do. You'll find that some of your programs have mistakes—bugs, in computer jargon. Debugging is the process of finding and fixing program errors. Making mistakes is a natural part of learning. It seems inherent to programming, so when you combine learning and programming, you had best prepare yourself to be reminded often of your fallibility. As you become a more powerful and subtle programmer, your errors, too, will become more powerful and subtle.

Step 7:Maintain and Modify the Program

When you create a program for yourself or for someone else, that program could see extensive use. If it does, you'll probably find reasons to make changes in it. Perhaps there is a minor bug that shows up only when someone enters a name beginning with Zz, or you might think of a better way to do something in the program. You could add a clever new feature. You might adapt the program so that it runs on a different computer system. All these tasks are greatly simplified if you document the program clearly and if you follow sound design practices.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值