Programming in C++ - Cengage [PDF]

Programming in C++. Online module to accompany Invitation to Computer Science, 7th Edition, ISBN-10: 1305075773; ISBN-13

0 downloads 4 Views 16MB Size

Recommend Stories


[PDF] Programming in Objective-C
The butterfly counts not months but moments, and has time enough. Rabindranath Tagore

Programming in C & C++
You miss 100% of the shots you don’t take. Wayne Gretzky

[PDF] Download C Programming
Never let your sense of morals prevent you from doing what is right. Isaac Asimov

[PDF] Download C Programming
It always seems impossible until it is done. Nelson Mandela

PDF C++ Programming
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

Programming in C and C++
You can never cross the ocean unless you have the courage to lose sight of the shore. Andrè Gide

[PDF] Cengage Advantage Books
I cannot do all the good that the world needs, but the world needs all the good that I can do. Jana

Programming in C
When you talk, you are only repeating what you already know. But if you listen, you may learn something

[PDF] Download Programming in C (4th Edition)
Every block of stone has a statue inside it and it is the task of the sculptor to discover it. Mich

[PDF] Download Programming in C (4th Edition)
This being human is a guest house. Every morning is a new arrival. A joy, a depression, a meanness,

Idea Transcript


C8814_chapter_cpplus.qxd

1/17/15

5:34 PM

Page 1

Programming in C++ Online module to accompany Invitation to Computer Science, 7th Edition, ISBN-10: 1305075773; ISBN-13: 9781305075771 (Cengage Learning, 2016).

1.

2. 3.

4. 5.

6.

7.

8.

Introduction to C++ 1.1 A Simple C++ Program 1.2 Creating and Running a C++ Program Virtual Data Storage Statement Types 3.1 Input/Output Statements 3.2 The Assignment Statement 3.3 Control Statements Another Example Managing Complexity 5.1 Divide and Conquer 5.2 Using Functions 5.3 Writing Functions Object-Oriented Programming 6.1 What Is It? 6.2 C++ and OOP 6.3 One More Example 6.4 What Have We Gained? Graphical Programming 7.1 Graphics Hardware 7.2 Graphics Software Conclusion

EXERCISES ANSWERS TO PRACTICE PROBLEMS

1 ©2016 Course Technology, a part of Cengage Learning.

C8814_chapter_cpplus.qxd

1

1/17/15

5:34 PM

Page 2

Introduction to C++ Hundreds of high-level programming languages have been developed; a fraction of these have become viable, commercially successful languages. There are a half-dozen or so languages that can illustrate some of the concepts of a highlevel programming language, but this module uses C++ for this purpose. The popular C++ language was developed in the early 1980s by Bjarne Stroustrup at AT&T Labs and was commercially released by AT&T in 1985. Our intent here is not to make you an expert programmer—any more than our purpose in Chapter 4 was to make you an expert circuit designer. Indeed, there is much about the language that we will not even discuss. You will, however, get a sense of what programming in a high-level language is like, and perhaps you will see why some people think it is one of the most fascinating of human endeavors.

1.1 A Simple C++ Program Figure 1 shows a simple but complete C++ program. Even if you know nothing about the C++ language, it is not hard to get the general drift of what the program is doing. Someone running this program (the “user”) could have the following dialogue with the program, where boldface indicates what the user types: Enter your speed in mph: 58 Enter your distance in miles: 657.5 At 58 mph, it will take 11.3362 hours to travel 657.5 miles. The general form of a typical C++ program is shown in Figure 2. To compare our simple example program with this form, we have reproduced the example program in Figure 3 with a number in front of each line. The numbers are there for reference purposes only; they are not part of the program. Lines 1–3 in the program of Figure 3 are C++ comments. Anything appearing on a line after the double slash symbol (//) is ignored by the compiler, just as anything following the double dash (--) is treated as a comment in the assembly language programs of Chapter 6. Although the computer ignores comments, they are important to include in a program because they give information to the human readers of the code. Every high-level language has some facility for including comments, because understanding code that someone else

2

Programming in C++ ©2016 Course Technology, a part of Cengage Learning.

C8814_chapter_cpplus.qxd

1/17/15

5:34 PM

Page 3

FIGURE 1 A Simple C++ Program

//Computes and outputs travel time //for a given speed and distance //Written by J. Q. Programmer, 6/15/16 #include using namespace std; void main() { int speed; //rate of travel double distance; //miles to travel double time; //time needed for this travel cout > speed; cout > distance; time = distance/speed; cout

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.