PREFACE



WHAT IS WRONG? PUT YOUR FEAR ASIDE!

How many people drive a car without knowing how the engine functions? How many people use the telephone without knowing the conversion process of voice to digit or vice versa? We use many machines daily without understanding how they work. However, people have different expectations when it comes to learning about computers; they want to understand it all. People have heard and seen so much about computers that they expect superior intelligence from them in every situation. They are curious to explore this unknown machine while at the same time are frightened to cause a malfunction. If the computer is not working properly or it is not “friendly” enough, the user assumes that they are not good or intelligent enough to learn about computers or programming. 

You don't have to know it all at once. If you start learning little by little you will overcome the fear. The learning process is just like watching a movie: you don't have to read, listen to, or see everything on the screen to understand or appreciate a movie. You just have to focus on the important things. The problem beginners have is that they can’t distinguish what is important from what is not; they mistakenly think everything is important. You don't have to be mathematically or scientifically gifted to understand computer programming. Whether you are a child or an elderly person, you can program. All you need is to combine awareness with effort, and you can make your way through programming.

It may be silly to ask these questions, but do you remember how you learned to walk, tie your shoelaces, ride a bike, or drive a car? Isn't it true that through a series of attempts and failures you finally got it? Have you seen a child ice-skate professionally? The combination of fearlessness, continuous practice, and enjoyment is the key to success.

My mission in writing this book is to instill confidence in you so that you can gain practical skills in programming. I am going to spend a great deal of time emphasizing how important it is to put your phobias aside and not to give up. Remember that no one is born with the ability to program. Programming is a skill you learn through the process of trial and error. You must have the desire to go for it. 

The pace of learning varies from person to person: some learn faster than others, some learn slowly, but retain the material learned longer. Some people must try harder than others, especially when unexpected situations arise. This may seem like a barrier to learning, but in the long run it is a valuable experience that will provide additional benefits. As experience builds, you will see there are many alternative ways to reach your goal.

The computer is now a pervasive force in our society and our daily lives, and we have little choice about whether we want it or not. Society is divided into two segments: those who know the computer and those who do not. With the emergence of the Internet, programming skills are increasingly valuable, not just for those pursuing a career as a professional programmer. Learning programming enables us to better conceptualize what is happening, and provokes critical thinking on how things are done or might be done. It gives us control over the otherwise overwhelming bombardment of information directed at us from seemingly everywhere in contemporary life. If you take the first step to learn programming, you may find that your creativity will take you further than you imagined. In fact, many accomplished programmers never dreamed of achieving their present success. 

HOW IS THIS BOOK DIFFERENT?

Unlike the traditional textbook format, this book will be presented in a conversational style. In other words, it is a virtual classroom. You are not just a reader anymore, but also a participating student. To ensure optimum comprehension of the subject matter, I will present the material to you from different approaches. Questions like why, what, how, and where are very often asked when the student encounters difficult materials. To address this problem, I attempt to explain such material with several techniques until the solution is clear. I will provide varying models to arrive at a solution using simple words in the hope that if one word is not understood, another might be clearer. 

As a teacher for more than two decades, including nineteen years as a professor teaching programming, I have been searching for a book that teaches how to program and how to use a programming language. Unfortunately, most of the programming books tend to focus on the programming language alone, and explain only grammar (syntax) and the meaning (semantics) of that particular language. Little emphasis is put on the problem-solving capability of the language. Books that do illustrate programming styles and problem-solving techniques are often abstract, hard to follow, and usually incorporate a lot of mathematical notations that intimidate the student. Some books even ignore the most viable programming languages altogether and express the algorithms (solutions) in English like statements (pseudo codes) instead. 

In this book, I am going to balance these two approaches in the proper way. Both language and problem-solving techniques are needed to write a program. This book will teach you how to program in the C and C++ languages, and how to apply their particular tools to solve problems. Cryptic and arcane notations will be minimized and explained, and difficult material will be approached slowly. From my teaching experience, I have found the following methods make teaching and learning programming fun. Neither the student nor the teacher is ever bored. 

DIFFERENT APPROACHES TO PROGRAMMING

1) Learning by analogy - A programming problem is better understood if you associate it with a similar problem that exists in real life and forming an analogy between the two. A sample analogy for writing a program that puts a series of numbers in order could be compared to the steps needed to sort a deck of playing cards. By forming an analogy between programming concepts and real-life situations, the material becomes easy to grasp and hard to forget. 
2) Learning by chaining - A program is extended to form a new program, and the new program is extended to create a newer program. Studying this chain of related programs promotes incremental learning and improves comprehension of the material. Examples that are “chained” help us to better understand the solution to a problem, and clarify the nature of the problem itself. The same basic example is continually expanded upon and re-incorporated as new subjects are introduced, so that the learning will be incremental and the transition from one subject to the next will be smooth. Also, you can compare different programming methods and problem solving-techniques through “chaining”. This is why the organization of this textbook differs from others.
3) Learning by doing - By testing existing programs and observing the input and output, you gain programming experience. You will be able to test the program yourself and see what is happening. Learning becomes easier when you explore, and analyze the program output by changing the input data. The ability to modify and enhance a program is a very rewarding experience.
4) Learning by creating a demand and providing a supply - Learning can be fun if we know why we should learn a new subject. In other words, what is its contribution? Can we live without it? Will it make certain problems easier to solve? Throwing in a lot of formulas and new information, without any practical justification, frustrates the student and hinders learning. A new subject is introduced only when it is needed (demand). "Why are we learning this?" is the kind of question that I look forward to hearing from my students.
5) Learning by error - Programmers spend many hours rectifying their errors. Studying common errors will help you become more prepared, and prevent you from repeating the same mistakes. Although learning by trial and error is very time consuming, it is widely known by educators that materials learned in this way are more likely to be retained. I will point out common programming errors, and the pitfalls that are most likely to occur in programming and C/C++ in particular. I will provide the shortcuts best designed to solve the problem on hand. 

In summary, the main purpose of this book is to learn programming in C/C++ the easy way. Simplicity is the heart of this book, although there is occasional redundancy. I am sure that by investing your time and effort, your newly acquired skill will make you very attractive in the growing job market. 


ACKNOWLEDGMENTS


I want to name everyone who helped me from the beginning, but I feared that I might have forgotten to include the names of some people who have helped me. While I have begun compiling a list, I decided to make my thanks a generic one for now. I am most grateful to my students for their encouragement to start this book and put it together. To my friends who kept me going and finally to my family from whom I took valuable time. Special thanks to Marci Taylor Editor of American Press for her supportive direction and positive feedback.