26
Introduction to C++ Basic Commands

Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Embed Size (px)

Citation preview

Page 1: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Introduction to C++

Basic Commands

Page 2: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

A. When we learn any computer language, that knowledge helps us in many ways. It helps us edit our “Facebook” pages ,and even helps us to be prepared for the computer classes which are required by most college or career training programs

2

Page 3: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

B. A computer is mainly steel, plastic and silicon. The way a computer is wired gives it the ability to read if a tiny electrical current is off or on. When a current is on, the computer calls it 1, and when the current is off, it calls it 0.

3

Page 4: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

1. Using the 0’s and 1’s that computers can read, people have created a computer standard called ASCII in which “1”is written for the computer like this: 00000001 and “2” is written for the computer as “00000010. The letter “A” is written as 01000001 and the letter “B” is written for the computer as 01000010.

4

Page 5: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

2. They call that number language “machine language” and that is what computers can understand with their transistor brains.

5

Page 6: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

3. When people first started using computers, they could see that it was too hard to talk to computers with the 0s and 1s of “machine language”, so they put all the number codes together and called it a library.

6

Page 7: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

4. All the numbers are hidden away in the “libraries.” Now people create computer languages which use regular words instead of numbers to control the 0s and 1s in the libraries.

7

Page 8: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

5. A “computer language” is a system of controls that lets you control your computer in an easier way than just typing 0s and 1s.

8

Page 9: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

6. Some examples of computer languages are C++, Basic, Java, and Action script. When we write programs, we use words and symbols called code.

9

Page 10: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

I. Background of Computer Language

C. All computer languages must provide a way to “name” items. These names are called “variables.” In C++, a variable that describes a whole number is called an “int.” A single number is called a “single,” a large number is called a “double,” a group of letters is called a “string,” and an object is called a “class.”

10

Page 11: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

II. Using the cout<< command

A. cout<< is the command used in C++ to write words to the computer screen.

B. Words to be displayed are typed between two quotation marks.

Example:

cout<<“This text will appear on the

screen!”

11

Page 12: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Let’s look at an example of a cout command

Complete Activity 1, then return to this PowerPoint Outline.

12

Page 13: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

III.Using the cin>> command to receive information into the computer

A. If a program asks for information, the program will be written so that it will pause and allow the user to enter information.

13

The computer calls “words” a “string”. Therefore, you must tell the computer you are going to use a “string” variable and that you are going to name it.

Page 14: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

III.Using the cin>> command to receive information into the computer

14

A. (Continued)Since the computer calls “words” a “string,” you must tell the computer you are going to use a “string” variable, and that you are going to name it.

For example, if you are entering your name, the variable code might be:

string username;

Page 15: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

III.Using the cin>> command to receive information into the computer

B. To ask the user to enter his/her name, you use the cout << command.

cout<<“Enter your first name”;

This code will cause the computer to write “Enter your first name” to the screen. 15

Page 16: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

III.Using the cin>> command to receive information into the computer

C. Next, you will use the cin>> command to “receive” the user’s name.

cin>>username;

This code will cause the program to stop and wait for the user to type his/her name and remember it as the variable “userName.”

16

Page 17: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

III.Using the cin>> command to receive information into the computer

D. Elements of a code page.

17

Page 18: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Let’s look at an example of a cin command

Complete Activity 2, then return to this PowerPoint Outline.

18

Page 19: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

IV. Using the cout<< and cin>> commands to edit a program

19

To see how working with the cout<< and cin>> commands can edit a program, complete Activity 3.

Page 20: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Let’s edit a program using the cout<< and cin>> commands

Complete Activity 3, then return for summary questions.

20

Page 21: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz

1. What command allows you to type information into the computer from the keyboard?

A. switch

B. cout<<

C. cin>>

D. for

21

Page 22: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz

2. What command allows you to have information appear on the screen from the program?

A. cout<<

B. cin>>

C. case

D. while

22

Page 23: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz

3. How do you tell the computer that the following code is for comments only?

A. Place // in front of the code.

B. Place * in front of the code.

C. Place \\ in front of the code.

D. Place || in front of the code

23

Page 24: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz

4. The computer standard in which “1” is written for the computer as “00000001” is:

A. FDIC.

B. ASVAB.

C. ASKEY2.

D. ASCII.

24

Page 25: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz

5. A system of controls that lets you control your computer in an easier way than just typing in 0s and 1s is a:

A. keyboard.

B. computer language.

C. bin folder.

D. string.

25

Page 26: Introduction to C++ Basic Commands. Copyright © Texas Education Agency, 2011. All rights reserved. I.Background of Computer Language A.When we learn any

Copyright © Texas Education Agency, 2011. All rights reserved.

Summary Review Quiz Key

1. C

2. A

3. A

4. D

5. B

26