Fundamentals of Programming Chapter 1 & 2 Notes

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The line that must be in your program if you intend to read inputs is

#INCLUDE <IOSTREAM>

The ________ directive causes the contents of another file to be inserted into a program.

#include

The first step in using the string class is to .....

#include the string header file. -This is accomplished with the following preprocessor directive: #include <string>

Two examples of high-level programming languages are :

-C++ and Java -C++ and JavaScript -C++ and C# -C++ and Visual Basic

Decode:

-The instruction is encoded in the form of a number. -The control unit decodes the instruction and generates an electronic signal.

Execute

-The signal is routed to the appropriate component of the computer (such as the ALU, a disk drive, or some other device). -The signal causes the component to perform an operation.

Application software refers to programs that make the computer useful to the user.

-These programs solve specific problems or perform general operations that satisfy the needs of the user. -Word processing, spreadsheet, and database programs are all examples of applica- tion software.

Which of the following is an example of a secondary storage device?

-a hard disk drive -a USB flash drive -a CD -a DVD

True/False: The following is a legal C++ statement to define and initialize a variable. char firstName = "Jack";

FALSE

True/False: The following statements both declare the variable num to be an integer. int num; INT num;

FALSE

True/False: The following two C++ statements perform the same operation. regWages = regPay + overTime; regPay + overTime = regWages;

FALSE

________ data types are used to define variables that can hold real numbers.

Floating-point

In the following example,...

H' is a character constant and "Hello" is a string constant.

The scope of a variable is defined as the part of the program where the variable may be used. There is a scope problem with variable ____ in the following code segment. int r = 2; Q = 1.5 + 2 * 4;

Q

What makes the computer so useful?

Quite simply, the computer can do such a wide variety of tasks because it can be programmed. -It is a machine specifically designed to follow instructions. -Computers are designed to do whatever job their programs, or software, tell them to do.

In order for the computer to execute a program, the program must be loaded into this component of the computer: __________________

RAM

________ is an example of volatile memory, used for temporary storage while a program is running.

RAM

Syntax

Rules that must be followed when constructing a program. -Syntax dictates how key words and operators may be used, and where punctuation symbols must appear.

True/False: Program specifications, charts and diagrams of screen output, hierarchy charts and pseudocode are some of the tools used in the craft of software engineering.

TRUE

True/False: Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.

TRUE

True/False: Syntax involves rules that must be followed when writing a program.

TRUE

True/False: The following statements could be used interchangeably in a C++ program. // Program Payroll /* Program Payroll */

TRUE

True/False: Variables represent storage locations in the computer's memory.

TRUE

C++ is also popular because of its portability.

This means that a C++ program can be written on one type of computer and then run on many other types of systems.

return 0;

This sends the integer value 0 back to the operating system upon the program's completion. -The value 0 usually indicates that a program executed successfully.

C++ is a widely used language because ....

in addition to the high-level features necessary for writing applications such as payroll systems and inventory programs, it also has many low-level features.

cout -

is used to display information on the computer's screen

CD and DVD drives use a laser to detect the....

pits and thus read the encoded data

Optical devices such as the CD (compact disc) and the DVD (digital versatile disc) are also :

popular for data storage.

What value will be assigned to the variable number by the following statement? int number = 7.8;

7

The constant 5 is :

preceded by the minus sign. -The minus sign, when used this way, is called the negation operator. -Since it only requires one operand, it is a unary operator.

#include is an example of a(n) ________.

preprocessor directive

A ________ is a complete instruction that causes the computer to perform some action.

statement

Variables represent :

storage locations in the computer's memory.

Short data type :

stores both positive and negative numbers, so it uses its 16 bits to represent the values from −32,768 to +32,767

Notice that a character constant is enclosed in single quotation marks whereas a .......

string constant is enclosed in double quotation marks.

Placing quotation marks around a variable name made it a:

string constant, or string literal. -When string literals are sent to cout, they are printed exactly as they appear inside the quotation marks. -You've probably noticed by now that the endl stream manipulator is written with no quotation marks around it. -If we were to put the following line in a program, it would print out the word endl, rather than cause subsequent output to begin on a new line.

For example, the following statement defines a string object named movieTitle.

string movieTitle;

Variables are :

symbolic names that represent locations in the computer's random-access memory (RAM). -When information is stored in a variable, it is actually stored in RAM.

The process of encoding an algorithm in machine language is very :

tedious and difficult.

Binary operators :

work with two operands.

A typical computer system consists of the following major components:

1. The central processing unit (CPU) 2. Main memory (random-access memory, or RAM) 3. Secondary storage devices 4. Input devices 5. Output devices

The CPU :

1. The heart of the computer 2. The CPU's job is to fetch instructions, follow the instructions, and produce some result. 3. The CPU consists of two parts: the control unit and the arithmetic and logic unit (ALU)

The value of the following expression is ______ 1 + 1234L + 2S

1237

The * operator :

multiplies its two operands.

The term hardware refers to :

the physical components that make up a computer

Computer programmers do a very important job.

-They create software that transforms computers into the specialized tools of many trades. -Without programmers, the users of computers would have no software, and without software, computers would not be able to do anything.

An integrated development environment (IDE) normally includes :

-a text editor -a compiler -a debugger

At the heart of a computer is its central processing unit. The CPU's job is to :

-fetch instructions -carry out the operations commanded by the instructions -produce some result

In C++ there are three data types that can represent floating-point numbers :

-float -double -long double

// Semicolon examples # include <iostream> int main() cout << "Hello";

// This is a comment // This is a preprocessor directive // This begins a function // This is a complete statement

If you want to force a value to be stored as a long double, append an L to it, as shown here:

1034.56L NOTE: The compiler won't confuse this with a long integer because of the decimal point.

Unix and Windows are examples of: A. operating system B. system software C. application software D. none of the above.

A

Each cell typically contains eight "switches" that may be either on or off.

A switch that is in the on position usually represents the number 1, while a switch in the off position usually represents the number 0.

When a C++ program is written it must be typed into the computer and saved to a file.

A text editor, which is similar to a word processing program, is used for this task.

Write one C++ assignment statement for the equation below. A + B + C avg = --------- 3.5 NOTE: (1) Use the same variables that are in the equation, and assume the variables have already been declared. (2) End the statement with a semicolon.

AVG = (A + B + C)/3.5;

Write one C++ assignment statement for the equation below. A - B avg = ------- A + B NOTE: (1) Use the same variables that are in the equation, and assume the variables have already been declared. (2) End the statement with a semicolon.

AVG = (A-B)/(A+B);

________ are data items whose values cannot change while the program is running.

Constants

Suppose you had to write a program that computes the pay earned by an hourly employee. The program reads in the rate of pay and the number of hours worked, computes the pay (no taxes withtheld), then prints the pay. The most appropriate data type for all variables is A. string B. char C. int D. float E. long

D

The unit of storage that holds 8 bits is a A) terabyte B) word C) kilobyte D) byte E) megabyte F) gigabyte

D

True/False: Although an object file contains machine language instructions, it is not a complete program. Because prewritten code from the run-time libraries must be added to the object code by the linker, and then an executable file is created.

TRUE

True/False: C++ is a case-sensitive language.

TRUE

True/False: If a new value is stored in a variable, it replaces whatever value was previously there.

TRUE

True/False: Key words, programmer-defined symbols, operators, punctuation, and syntax are common to all programming languages.

TRUE

True/False: Most of the lines in a program contain something meaningful; however, some of the lines may contain nothing at all.

TRUE

The = and * symbols are both operators.

They perform operations on pieces of data, known as operands.

}

This brace marks the end of the main function. -Because main is the only function in this program, it also marks the end of the program.

{

This is called a left-brace, or an opening brace, and it is associated with the beginning of the function main. -All the statements that make up a function are enclosed in a set of braces. -If you look at the third line down from the opening brace you'll see the closing brace. -Everything between the two braces is the contents of the function main.

int number;

This is called a variable definition. -It tells the compiler the variable's name and the type of data it will hold. -Notice that the data type is written first, followed by the name of the variable. -This variable's name is number. -The word int stands for integer, so number may only be used to hold integer numbers.

number = 5;

This is called an assignment statement and the = sign is called the assignment operator. -This operator copies the value on its right (5) into the variable named on its left (number). -This line does not print anything on the computer's screen. -It runs silently behind the scenes, storing a value in RAM. After this line executes, number will be set to 5.

You have also seen that it is possible to assign values to variables when they are defined.

This is called initialization.

int main() :

This marks the beginning of a function.

The word double in the statement indicates that the variables hours, rate, and pay will be used to hold double precision floating-point numbers.

This statement is called a variable definition.

(T/F) The following is a legal C++ statement to define and initialize a variable. string lastName = "Jackson";

True

Problem: Compute the pay earned by an hourly employee. Read in the rate of pay and the number of hours worked, compute the pay (no taxes withtheld), then print the pay. (T/F) The example below gives three valid instances of the problem: rate = 15.00 hours = 10.0 ==> pay = 150.00 rate = 12.50 hours = 20.0 ==> pay = 250.00 rate = 12.50 hours = 0.0 ==> pay = 0.00

True

#include <iostream> int main() { cout << "Good " << endl << endl << "job"; return 0; } Provide the missing line: ____________________________

USING NAMESPACE STD;

For example, look at the following code. int number; number = 7.8; // Assigns 7 to number This code attempts to assign the floating-point value 7.8 to the integer variable number. Because this is not possible, the value 7 is assigned to number, and the fractional part is discarded.

When part of a value is discarded in this manner, the value is said to be truncated. Assigning a floating-point variable to an integer variable has the same effect. For example, look at the following code. int intVar; double doubleVar = 7.8; intVar = doubleVar; // Assigns 7 to intVar // doubleVar remains 7.8

The << operator is used to send the string "Programming is great fun!" to cout.

When the << symbol is used this way, it is called the stream-insertion operator. -The item immediately to the right of the operator is sent to cout and then displayed on the screen. -The stream insertion operator is always written as two less-than signs with no space between them.

RAM is usually a volatile type of memory, used only for temporary storage.

When the computer is turned off, the contents of RAM are erased.

Programmer-Defined Identifiers

Words or names defined by the programmer. -They are symbolic names that refer to variables or programming routines.

Key Words :

Words that have a special meaning. -Key words may only be used for their intended purpose. -Key words are also known as reserved words.

Program :

a sequence of instructions stored in the computer's memory. - A program is a set of instructions a computer follows in order to perform a task. -A programming language is a special language used to write computer programs.

A ________ variable can hold only one of two values: true or false.

bool

A variable defined as a char can hold a single character,.....

but strictly speaking, it is an integer data type.

Each cell, which is a collection of eight bits, is known as a :

byte

The next step is to define a string type variable, .....

called a string object.

External disk drives :

can be used to create backup copies of important data or to move data to another computer -In addition to external disk drives, many types of devices have been created for copying data and for moving it to other computers

#include <iostream> using namespace std; int main() { int Num; const int Year = 2011; cout << Num; cout << Year + 1; return 0; } In this program, the semicolon(;) is called the statement _________ .

terminator

Disk drives, USB flash drives, and CD/DVD recorders can also be considered out- put devices because .....

the CPU sends information to them so it can be saved.

Internally, the central processing unit (CPU) consists of two parts :

the arithmetic and logic unit (ALU) and the control unit

If the program is free of syntax errors .....

the compiler stores the trans- lated machine language instructions, which are called object code, in an object file.

Random-access memory or RAM:

the computer's main memory is a device that holds information. -Specifically, RAM holds the sequences of instructions in the programs that are running and the data those programs are using.

Common input devices are :

the keyboard, mouse, scanner, digital camera, and microphone.

C++ automatically places ________ at the end of string constants.

the null terminator

In E notation,........

the number 47,281.97 would be 4.728197E4. -The part of the number before the E is the mantissa, and the part after the E is the power of 10. -When a floating-point number is stored in memory, it is stored as the mantissa and the power of 10.

Hardware (PLEASE FINISH !!!)

the physical components that a computer Note: All computer systems consist of similar hardware devices and software components.

By writing the algorithm in pseudocode first,....

the programmer can focus on just the logical steps the program must perform, without having to worry yet about syntax or about details such as how output will be displayed.

Through a technique called time sharing :

the system divides the allocation of hardware resources and the attention of the CPU among all the executing programs. -UNIX, Windows XP, and Win- dows Vista are multitasking operating systems.

The layout of the actual output looks nothing like the arrangement of the strings in the source code.

cout displays messages exactly as they are sent. If spaces are to be displayed, they must appear in the strings.

Because the programmer accidentally wrote /n instead of \n,......

cout will simply display the /n characters on the screen, rather than starting a new line of output.

In fact, placing double quotation marks around anything that is not intended to be a string literal will :

create an error of some type.

The bool data type allows you to :

create variables that hold true or false values.

The statement using namespace std; :

declares that the program will be accessing entities whose names are part of the namespace called std.

Defining a string object is similar to .....

defining a variable of a primitive type.

You must have a(n) ________ for every variable you intend to use in a program.

definition

Which of the following is/are valid C++ identifiers?

department_9 & aVeryLongVariableName

The sizeof operator may be used to ......

determine the size of a data type on any system.

Prepro- cessing, compiling, linking, and even executing a program is :

done with a single click of a button, or by selecting a single item from a menu.

The double data type is usually twice as big as float, so it is considered :

double precision. -8 bytes -Significant Digits : 16 -Numbers between ±1.7E-308 and ±1.7E308

The long double is intended to be larger than the......

double. -8 bytes -Significant Digits : 16 -Numbers between ±1.7E-308 and ±1.7E308 -*Some compilers use more than 8 bytes for long doubles. These allow greater ranges.

Floating-point constants are normally stored in memory as:

doubles.

A variable has all the following properties, except for ___ A. It is stored in RAM B. It has an address C. It has a unique name (identifier) D. It can hold one value at a time E. It can hold many different types of values. F. C and E

e

Computers must contain all the components below except for: A. input/output devices B. random-access memory C. central processing unit D. storage devices E. wireless card

e

Data is not recorded magnetically on an optical disc, but rather is...

encoded as a series of pits on the disc surface.

Software engineering :

encompasses the complete process of crafting computer software. -It includes designing, writing, testing, debugging, documenting, modifying, and maintaining complex software development projects.

A special operator called sizeof will.....

eport the number of bytes of memory used by any data type or variable.

\n is an example of an.....

escape sequence.

Although most C++ programs have more than one function,......

every C++ program must have a function called main. It is the starting point of the program.

The program needs access to the std namespace because .....

every name created by the iostream file is part of that namespace. -In order for a program to use the entities in iostream, it must have access to the std namespace

Escape sequences give you the ability to :

exercise greater control over the way information is output by your program.

#include <iostream> using namespace std; int main() { int Num; const int Year = 2011; cin >> Num; cout << Year + 1; return 0; } In this program, the symbols >> are called the ______________ operator.

extraction

When a computer is running a program, the CPU is engaged in a process known formally as the :

fetch/ decode/execute cycle

Problem: Write a program that computes the pay earned by an hourly employee. The program reads in the rate of pay and the number of hours worked, computes the pay (no taxes withtheld), then prints the pay. The most appropriate data type for all variables is __________ .

float

Suppose your program performs a scientific calculation that has to produce 12 decimal digits of accuracy. Complete the declaration for the variable that will hold the result of your calculation. ____________ ScienceAnswer; // Answer to scientific calculation.

float

Escape sequences are written as a backslash char- acter (\):

followed by one or more control characters and are used to control the way output is displayed.

The smallest unit of storage is a A) byte B) word C) kilobyte D) megabyte E) gigabyte F) terabyte G) bit

g

The Unix command to compile program myProg.cpp and to produce the executable file a.out is:

g++ myProg.cpp

You should always choose names for your variables that :

give an indication of what the variables are used for. However, the rather nondescript name, x, gives no clue as to the variable's purpose. -Here is a better example: int itemsOrdered; -The name itemsOrdered gives anyone reading the program an idea of the variable's use. -This way of coding helps produce self-documenting programs, which means you can get an understanding of what the program is doing just by reading its code. -In fact, some programmers use the underscore character to separate words in a variable name, as in the following: int items_ordered;

A function can be thought of as a :

group of one or more programming statements that has a name. -The name of this function is main, and the set of parentheses that follows the name indicates that it is a function. -The word int stands for "integer." -It indicates that the function sends an integer value back to the operating system when it is finished executing.

Output sent to a printer is called :

hard copy

The library contains :

hardware-specific code for displaying messages on the screen and reading input from the keyboard. -It also provides routines for mathematical functions, such as calcu- lating the square root of a number.

The bool data type ________.

has only two values: true and false

Many development systems, particularly those on personal computers, ......

have integrated development environments (IDEs). -These environments consist of a text editor, compiler, debugger, and other utilities integrated into a package with a single set of menus.

When a floating-point value is assigned to an integer variable,......

he fractional part of the value (the part after the decimal point) is discarded. -This occurs because an integer variable cannot hold any value containing decimals.

Each printable character, as well as many nonprintable characters, are assigned a unique number.

he most commonly used method for encoding characters is ASCII.

After the source code is saved to a file ....

he process of translating it to machine language can begin.

Three common design tools are :

hierarchy charts, flowcharts, and pseudocode.

The easiest languages for people to learn are :

high-level languages

A variable of the char (character) data type :

holds only a single character. - 1-byte integer data type

Key words ......

however, are reserved and cannot be used for anything other than their designated purposes. -Part of learning a programming language is learning what the key words are, what they mean, and how to use them.

When the compiler generates an object file.....

however, it does not include machine code for any run-time library routines the programmer might have used.

Programming style refers to the way a programmer uses :

identifiers, spaces, tabs, blank lines, and punctuation characters to visually arrange a program's source code.

The numeric data types in C++ are broken into two categories:

integer and floating-point.

IDE stands for :

integrated development environment

A statement :

is a complete instruction that causes the computer to perform some action.

Hierarchy chart :

is a diagram that graphically depicts the structure of a program. -It has boxes that represent each step in the program. -The boxes are connected in a way that illustrates their relationship to one another.

A variable :

is a named storage location in the computer's memory for holding a piece of data. -The data stored in variables may change while the program is running (hence the name "variable").

The #include <iostream> statement .....

is a preprocessor directive.

An identifier :

is a programmer-defined name that represents some element of a program. -Variable names are examples of identifiers. -You may choose your own variable names in C++, as long as you do not use any of the C++ key words. -The key words make up the "core" of the language and have specific purposes.

Algorithm :

is a set of well- defined steps for performing a task or solving a problem. -It is important that these instructions be performed in their proper sequence.

Secondary storage :

is a type of memory that can hold data for long periods of time—even when there is no power to the computer.

Input :

is any information the computer collects from the outside world.

Output :

is any information the computer sends to the outside world

The = symbol :

is called the assignment operator. -The assignment operator has two operands.

Multitasking operating system :

is capable of running multiple pro- grams at once.

Single tasking operating system :

is capable of running only one program at a time. -The computer devotes all its hardware resources and CPU time to each program as it executes. -MS-DOS is an example of a single tasking operating system.

The arithmetic and logic unit :

is designed to perform arithmetical operations

Memory :

is divided into sections, or cells, that each hold an equal amount of data.

The executable file contains machine language instructions, or executable code, and .....

is ready to run on the computer.

The first rule of scope :

is that a variable cannot be used in any part of the program before it is defined.

A variable's scope.....

is the part of the program that has access to the variable.

Because a char variable can only hold a single character,.....

it can be assigned the character 'A', but not the string "A".

When the computer is instructed to print the value on the screen,.......

it displays the character that corresponds with the numeric code.

When cout encounters \n in a string,....

it doesn't print it on the screen but interprets it as a special command to advance the output cursor to the next line. -You have probably noticed inserting the escape sequence requires less typing than inserting endl.

Anytime a program works with a character,......

it internally works with the code used to represent that character, so this program is still assigning the values 65 and 66 to letter.

Although it appears that it is storing the words true and false,.......

it is actually an integer variable that stores 0 for false and 1 for true, as you can see from the program output.

When a character is stored in memory .....

it is actually the numeric code that is stored.

When a value is assigned to a variable as part of the variable's definition,.....

it is called an initialization.

Although an object file contains machine language instructions,.....

it is not a complete program.

Once a model of the program has been created,.....

it should be checked for logical errors. -The programmer should trace through the charts or pseudocode, checking the logic of each step. -If an error is found, the model can be corrected before the actual program source code is written. In general, the earlier an error is detected in the programming process, the easier it is to correct.

The number of bytes a data type can hold is called :

its size. -Typically, the larger the size a data type is, the greater the range of values it can hold.

Words with a special meaning that may be used only for their intended purpose are known as ________.

key words

In C++ ......

key words are written in all lowercase.

The syntax rules of C++ dictate how and where to place ....

key words, semicolons, commas, braces, and other components of the language. -Ideally, it is a consistent method of putting spaces and indentions in a program so visual cues are created. -These cues quickly tell a programmer important information about a program. -It is a common C++ style to indent all the lines inside a set of braces.

One of the problems of portability is the......

lack of common sizes of data types on all machines. -If you are not sure what the sizes of data types are on your computer, C++ provides a way to find out.

Often, the contents of a program are thought of in terms of :

lines and statements

Mistakes that allow a program to run, but cause it to produce erroneous results are called ________.

logic errors

In a broad sense, there are two categories of programming languages:

low-level and high-level

There are two general categories of software:

operating systems and application software

#include <iostream> using namespace std; int main() { int Num; const int Year = 2011; cout << Num; cout << Year + 1; return 0; } In this program, + is called a(n) _________ [one word].

operator

Characters or symbols that perform operations on one or more operands are :

operators

The preprocessor searches for :

pecial lines that begin with the # symbol. -These lines contain commands, or directives, that cause the preprocessor to amend or process the source code in some way.

Numbers are used to :

perform mathematical operations and charac- ters are used to print information on the screen or on paper.

C++ is conveniently equipped with a library of prewritten code for :

performing common operations or sometimes-difficult tasks.

When a line begins with a # it indicates it is a ....

preprocessor directive. -The preprocessor reads your program before it is compiled and only executes those lines beginning with a # symbol. -Think of the preprocessor as a program that "sets up" your source code for the compiler.

A computer is controlled by a specific set instructions called a _____________ .

program

A(n) ________ is a set of instructions that tells the computer how to solve a problem.

program

Creating a program requires many steps. Three of these are :

program design, writing source code, and testing

High level pseudocode simply lists the steps a....

program must perform.

Disk drives, CD/DVD drives, and USB flash drives can also be considered input devices because .....

programs and information are retrieved from them and loaded into the computer's memory.

The null terminator is another example of something that sits......

quietly in the background.

The computer's main memory is commonly known as

random-access memory (RAM)

During the first phase of this process, a program called the preprocessor .....

reads the source code.

Software :

refers to the programs that run on a computer

Computers typically use E notation to.....

represent floating-point values.

Ternary operators :

require three operands.

The keyword that must ALWAYS appear inside the body { ... } of the main program is ____________ .

return

A ________ is used to mark the end of a complete C++ programming statement.

semicolon

Which of the following key words is/are the names of C++ data types?

short long double bool

A semicolon in C++ is .....

similar to a period in English. -It marks the end of a complete sentence (or statement, as it is called in programming).

Character constants can only hold a ....

single character.

The float data type is considered :

single precision. -4 bytes -Significant Digits : 7 -Numbers between ±3.4E-38 and ±3.4E38

A C++ character constant (character literal) is enclosed in ________ quotation marks, whereas a string constant (string literal) is enclosed in ________ quotation marks.

single, double

USB flash drives are:

small devices that plug into the computer's USB (universal serial bus) port and appear to the system as a disk drive. -These drives, which use flash memory to store data, are inexpensive, reliable, and small enough to be carried in your pocket.

Output sent to a computer screen is sometimes called :

soft copy

The statements written by a programmer are called :

source code

The statements written by the programmer are called :

source code -The file they are saved in is called the source file.

Standard C++ provides a .....

special data type for storing and working with strings.

\n - Newline \t - Horizontal tab \a - Alarm \b - Backspace \r - Return \\ - Backslash \' - Single quote \" - Double quote

*Causes the cursor to go to the next line for subsequent printing. *Causes the cursor to skip over to the next tab stop. *Causes the computer to beep. *Causes the cursor to back up, or move left one position. *Causes the cursor to go to the beginning of the current line, not the next line. *Causes a backslash to be printed. *Causes a single quotation mark to be printed. *Causes a double quotation mark to be printed.

// - Double slash # - Pound sign < > - Opening and closing brackets ( ) - Opening and closing parentheses { } - Opening and closing braces " " - Opening and closing quotation marks ; - Semicolon

*Marks the beginning of a comment. *Marks the beginning of a preprocessor directive. *Encloses a filename when used with the #include directive. *Used in naming a function, as in int main(). *Encloses a group of statements, such as the contents of a function. *Encloses a string of characters, such as a message that is to be printed on the screen. *Marks the end of a complete programming statement.

Arithmetic operations occur frequently in programming.

+ - * / % Addition, Subtraction, Multiplication, Division, Modulus Examples: total = cost + tax; cost = total - tax; tax = cost * rate; salePrice = original / 2; remainder = value % 3; Here is an example of how each of these operators works. *The addition operator returns the sum of its two operands. total = 4 + 8; // total is assigned the value 12 *The subtraction operator returns the value of its right operand subtracted from its left operand. candyBars = 8 - 3; // candyBars is assigned the value 5 *The multiplication operator returns the product of its two operands. points = 3 * 7 // points is assigned the value 21 *The division operator works differently depending on whether its operands are integer or floating-point numbers. *When both numbers are integers, the division operator performs integer division. *This means that the result is always an integer. If there is any remainder, it is discarded. fullBoxes = 26 / 8; // fullBoxes is assigned the value 3 *The variable fullBoxes is assigned the value 3 because 8 goes into 26 three whole times with a remainder of 2. The remainder is discarded. *If you want the division operator to perform regular division, you must make sure at least one of the operands is a floating-point number. boxes = 26.0 / 8; // boxes is assigned the value 3.25 *The modulus operator computes the remainder of doing an integer divide. leftOver = 26 % 8; // leftOver is assigned the value 2

The most common type of secondary storage device is the disk drive.

-A disk drive stores data by magnetically encoding it onto a circular disk. -Most computers have a disk drive mounted inside their case.

What Is a Program?

-Computers are designed to follow instructions. -A computer program is a set of instructions that tells the computer how to solve a problem or perform a task.

Computer programming is both an art and a science.

-It is an art because every aspect of a program should be designed with care and judgment.

Consider the code segment (comments contain line numbers): /* 1 */ char S, T_ /* 2 */ int J, K; /* 3 */ cin >> K; /* 4 */ J = K = 4; /* 5 */ K = K % T_; Line ____ contains an error.

1

The expression 5 % 2 evaluates to ________.

1

The expression 7 % 2 evaluates to ________.

1

These are the steps recommended for the process of writing a program.

1. Define what the program is to do. 2. Visualize the program running on the computer. 3. Use design tools to create a model of the program. 4. Check the model for logical errors. 5. Write the program source code. 6. Compile the source code. 7. Correct any errors found during compilation. 8. Link the program to create an executable file. 9. Run the program using test data for input. 10. Correct any errors found while running the program. Repeat steps 4 through 10 as many times as necessary. 11. Validate the results of the program.

include <iostream> using namespace std; int main() { int Num = 14.75; cout << Num; return 0; } The output displayed by this program is: ________

14

Consider the code segment (comments contain line numbers): /* 1 */ float J = 25.3; /* 2 */ int Pay, 2k; /* 3 */ cout << K + 2; /* 4 */ K = K + 1; /* 5 */ J = 4 + K; Line ____ contains an error.

2

The expression 5 / 2 evaluates to ________.

2.5

#include <iostream> using namespace std; int main() { float Dec = 14.89483; int Num; Num = Dec + Dec; cout << Num; return 0; } The output displayed by this program is: ________

29

#include <iostream> using namespace std; int main() { cout << "Good " << endl << endl << "job"; return 0; } The number of output lines is _____ .

3

#include <iostream> using namespace std; int main() { float Num; Num = pow(25.0, 0.5) - 2; cout << Num; return 0; } The output from this program: _____________

3

The expression 7 / 2 evaluates to ________.

3

What value will be assigned to the variable number by the following statement? int number = 3.75;

3

The following are real, or floating-point, numbers:

3.14159 6.7 1.0002

#include <iostream> using namespace std; int main() { float Num; Num = 8 % 5 * 2 - 9 / 4; cout << Num; return 0; } The output from this program: _____________

4

Consider the code segment (comments contain line numbers): /* 1 */ char S; /* 2 */ int J, K; /* 3 */ cin >> K; /* 4 */ S = "G"; /* 5 */ K = K + S; Line ____ contains an error.

4

What constant(s) appear in the following C++ statement? int number = 4 + 8;

4 & 8

Consider the code segment (comments contain line numbers): /* 1 */ string S, T; /* 2 */ int J, K; /* 3 */ cin >> S; /* 4 */ T = "This is a good /* 5 */ day for a test." /* 6 */ S = S + T; Line(s) ____ contains an error. NOTE: If multiple lines contain errors, list them separated by + sign, e.g., 2+3+8.

4+5

#include <iostream> #define MAX 499 #using namespace std; int main() { int Num = 148; cout << MAX << '+' << Num << endl; return 0; } The output from this program: _____________

499+148

Consider the code segment (comments contain line numbers): /* 1 */ char S, T; /* 2 */ int J, K; /* 3 */ cin >> K; /* 4 */ J = K = 4; /* 5 */ K = J % 3.0; Line ____ contains an error.

5

Consider the code segment (comments contain line numbers): /* 1 */ char S; /* 2 */ int J, _K; /* 3 */ cin >> J; /* 4 */ S = 'G'; /* 5 */ K = K + S; Line ____ contains an error.

5

Consider the code segment (comments contain line numbers): /* 1 */ int J = 25; /* 2 */ int I, M, K; /* 3 */ J = M + 2; /* 4 */ K = K + 1; /* 5 */ 3 = 4 + K; Line ____ contains an error.

5

Consider the code segment (comments contain line numbers): /* 1 */ int J = 25; /* 2 */ int I, M, K; /* 3 */ J = M + 2; /* 4 */ K = K + 1; /* 5 */ J + 1 = 4 + K; Line ____ contains an error.

5

Numeric data can be categorized even further. For instance, the following are all whole numbers, or integers :

5 7 -129 32154

To summarize, do not confuse the backslash (\) with the forward slash (/).

An escape sequence must start with a backslash, be placed inside quotation marks, and have no spaces between the backslash and the control character.

Expressions that have a true or false value are called :

Boolean expressions

Floating-point constants may be expressed in a variety of ways.

As shown in Program 2-15, E notation is one method. -When you are writing numbers that are extremely large or extremely small, this will probably be the easiest way. -E notation numbers may be expressed with an uppercase E or a lowercase e.

NOTE:

Because floating-point constants are normally stored in memory as doubles, some compilers issue a warning message when you assign a floating-point constant to a float variable. For example, assuming num is a float, the following statement might cause the compiler to generate a warning message: num = 14.725; You can suppress the error message by appending the f suffix to the floating-point constant, as shown here: num = 14.725f;

Do not use semicolons at the end of preprocessor directives.

Because preprocessor directives are not C++ statements, they do not require them.

There is also a scientific, or engineering side to programming. (PLEASE REDO THIS ONE)

Because programs rarely work right the first time they are written, a lot of experimentation, correction, and rede- signing is required.

When a variable's contents change, or information is displayed on the screen, this is noted.

By stepping through each statement in this manner, many errors can be located and corrected.

Given the schematic below, write the PROCESS portion of required program. SCHEMATIC: +-------------- float num1 | | -------->| program | float product | |------------> float num2| MULTIPLY | -------->| | | | +--------------+ TESTCASES: A) 1 2 2 B) 0 1 1 C) 1.5 1.5 2.25 D) 0.0 1.0 1.0 NOTE: if more than one choice is correct, connect with + sign (e.g.,A+F).

C

The main reason the program and schematic below do not match is: A. The names of the variables do not match. B. The number of outputs do not match. C. The number of inputs do not match. D. The program documentation is missing. PROGRAM: #include <iostream> using namespace std; int main() { float num1 = 3, num2 = 4.5; cout << num1 + num2; } SCHEMATIC: float var1 --------> anyProgam ----------->| float |------------> float var2

C

What if you are in a situation where you have an integer constant, but you need it to be stored in memory as a long integer?

C++ allows you to force an integer constant to be stored as a long integer by placing the letter L at the end of the number. Here is an example: 32L -On a computer that uses 2-byte integers and 4-byte long integers, this constant will use 4 bytes. This is called a long integer constant. -Although C++ allows you to use either an uppercase or lowercase L, the lowercase l looks too much like the number 1, so you should always use the uppercase L.

By default,.......

C++ assumes that all integer constants are expressed in decimal. -You express hexadecimal numbers by placing 0x in front of them. (This is zero-x, not oh-x.) Here is how the hexadecimal number F4 would be expressed in C++: 0xF4 -Octal numbers must be preceded by a 0 (zero, not oh). For example, the octal 31 would be written : 031

Preprocessor directives are not :

C++ statements. -They are commands to the preprocessor, which runs prior to the compiler (hence the name "preprocessor"). -The preprocessor's job is to set programs up in a way that makes life easier for the programmer. -The solution is to let the preprocessor insert the contents of iostream automatically.

Write one C++ statement to read the first number into variables N1, and the second number into variable N2.

CIN >> N1 >> N2;

Write the C++ statement to display the output shown below: TODAY

COUT << "TODAY";

This computer component consists of a control unit and the arithmetic and logic unit.

CPU

Suppose assignment PROG3 requires that source file add15.cpp be submitted. The command to submit is: ________________________

CSSUBMIT PROG3 ADD15.CPP

The entire CS repository command you would use to find out when the assignment NEXTWORK is due is

CSprograms

The complete CS repository command you would use to see the names of the .cpp files you have submitted for programming assignments is

CSstatus.cpp

The main reason the program and schematic below do not match is: A. The names of the variables do not match. B. The number of outputs do not match. C. The number of inputs do not match. D. The program documentation is missing. E. None of the above. PROGRAM: #include <iostream> using namespace std; int main() { float num1 = 3, num2 = 4.5; cin >> num2 >> num1; num1 = num1 + num2; cout << num1; return 0; } SCHEMATIC: float --------> Program --------->| float float Add2 -------->

E

The computer stores data by setting the switches in a memory cell to a pattern that represents a piece of information.

Each of these switches is known as a bit, which stands for binary digit.

(T/F) Input/output devices store data.

F

True/False: A variable of the char data type holds a set of characters like "January".

FALSE

True/False: An escape sequence must start with a forward slash (/) .

FALSE

True/False: Executable code is computer code that contains no errors.

FALSE

True/False: If number has been defined as an int variable, both of the following statements will print out its value: cout << number; cout << "number";

FALSE

True/False: Most modern computers can understand and execute pseudocode.

FALSE

True/False: Once a value has been stored in a variable it cannot be changed.

FALSE

True/False: The following two statements both assign the value 5 to the variable dept. 5 = dept; dept = 5;

FALSE

True/False: The purpose of the compiler is to convert object code into source code.

FALSE

Unary operators only require a single operand.

For example, consider the following expression: −5

The second type of comment in C++ is the multi-line comment.

Multi-line comments start with /* (a forward slash followed by an asterisk) and end with */ (an asterisk followed by a forward slash).

Floating-point variables can hold a much larger range of values than integer variables can.

If a floating-point value is stored in an integer variable, and the whole part of the value (the part before the decimal point) is too large for the integer variable, an invalid value will be stored in the integer variable.

Frequently used programs are stored in secondary memory and loaded into main memory as needed.

Important information, such as word processing documents, payroll data, and inventory figures, is saved to secondary storage as well

12 = unitsSold; // Incorrect! unitsSold = 12; unitsSold = 4 + 8;

In C++ terminology, the operand on the left side of the = symbol must be an lvalue. -An lvalue is something that identifies a place in memory whose contents may be changed, so a new value can be stored there. -Most of the time the lvalue will be a variable name. -It is called an lvalue because it is a value that may appear on the left-hand side of an assignment operator. -The operand on the right side of the = symbol must be an rvalue. -An rvalue is any expression that has a value. -This could be a single number, like 12, or the result of a calculation, such as 4 + 8. -The assignment statement evaluates the expression on the right-hand side to get the value of the rvalue and then puts it in the memory location identified by the lvalue.

cout << "Programming is great fun!";

In programming terms, the group of characters inside the quotation marks is called a string literal, a string constant, or simply a string.

Notice that in line 10 the word number has double quotation marks around it and in line 11, it does not. cout << "The value of number is " << "number" << endl; cout << "The value of number is " << number << endl;

In the first cout statement, the string constant "number" is inserted into the output stream, so the output produced is: The value of number is number In the second cout statement, because there are no quotation marks around it, it is the variable name number that is inserted into the output stream, causing its value to print. The value of number is 5

number = "5"; // Wrong!

In this line, 5 is no longer an integer, but a string literal. -Because number was defined to be an integer variable, you can only store integers in it. -The integer 5 and the string literal "5" are not the same thing. -Just remember that strings are intended for humans to read. They are to be printed on computer screens or paper. -Numbers, however, are intended primarily for mathematical operations. -You cannot perform math on strings, and you cannot display numbers on the screen without first converting them to strings.

The word console is an old computer term.

It comes from the days when a computer operator interacted with the system by typing on a terminal.

You have learned that some strings look like a single character but really aren't.

It is also possible to have a character that looks like a string. -A good example is the newline charac- ter, \n. -Although it is represented by two characters, a slash and an n, it is internally repre- sented as one character. -In fact, all escape sequences, internally, are just 1 byte.

When multiple variables are defined in the same statement,.....

It is possible to initialize some of them without having to initialize all of them.

The item on the left hand side of an assignment statement must be a variable.

It would be incorrect to say 5 = number;

Which of the following is/are valid C++ identifiers?

June_2010

#include <iostream> using namespace std; int main() { char Keystroke; string Word; short Year = 2011; cout << Keystroke; cout << Year; return 0; } In this program, eight (8) bits are used to store values for variable _______.

KEYSTROKE

A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called :

None of the Above

Bytes are grouped together to make words.

On most computers a word contains four bytes.

Operators :

Operators perform operations on one or more operands. -An operand is usually a piece of data, like a number.

________ is/are used in a C++ program to mark the beginning or ending of a statement, or to separate items in a list.

Punctuation

Punctuation

Punctuation characters that mark the beginning or ending of a statement, or separate items in a list.

In addition, operating systems fall into one of the following categories, which describe the number of users they can accommodate.

Single user -This type of system allows only one user to operate the computer at a time. -MS-DOS and older versions of Windows are single user operating systems. Multiuser -Multiuser systems allow several users to run programs and operate the computer at once. -Most variations of the UNIX operating system are multiuser systems.

While C++ does not have a built- in data type able to do this,.....

Standard C++ provides something called the string class that allows the programmer to create a string type variable.

Integer Constants 20 15 0

String Literals "On Sunday we sold" "On Monday we sold" "bushels of apples. \n"

(T/F) The scope of a variable is defined as the part of the program where the variable may be used. There a scope problem with the following code segment. int x = 2, y = 3; Y = -2; X = 1.3 + Y; cin >> Y;

T

Internally, floating-point numbers are stored in a manner similar to scientific notation.

Take the number 47,281.97. In scientific notation this number is 4.728197 × 104. (104 is equal to 10,000, and 4.728197 × 10,000 is 47,281.97.) -The first part of the number, 4.728197, is called the mantissa. The mantissa is multiplied by a power of 10.

Fetch:

The CPU's control unit fetches, from main memory, the next instruction in the sequence of program instructions

Most of the lines contain something meaningful; how- ever some of the lines are empty.

The blank lines are only there to make the program more readable.

________ is/are used to display information on the computer's screen.

The cout object

Operators perform operations on data.

The data that operators work with are called operands

There are two ways to instruct cout to start a new line.

The first is to send cout a stream manipulator called endl (pronounced "end-line" or "end-L").

________ must be included in a program in order to use the cout object.

The iostream header file

Every time cout encounters an endl stream manipulator it advances the output to the beginning of the next line for subsequent printing.

The manipulator can be inserted any- where in the stream of characters sent to cout, outside the double quotes. -Another way to cause subsequent output to begin on a new line is to insert a \n in the string that is being output.

The first line that uses the operator is line 9. cout << "The size of an integer is " << sizeof(int); The name of the data type or variable is placed inside the parentheses that follow the operator.

The operator "returns" the number of bytes used by that item. -This operator can be used anywhere you can use an unsigned integer, including in mathematical operations.

An #include directive must always contain the name of a file.

The preprocessor inserts the entire contents of the file into the program at the point it encounters the #include direc- tive. -The compiler doesn't actually see the #include directive. -Instead it sees the code that was inserted by the preprocessor, just as if the programmer had typed it there.

Every variable has a scope.

The scope of a variable is the part of the program where it may be used.

For many years floppy disk drives were popular. A floppy disk drive records data onto a small, flexible ("floppy") disk, which can be removed from the drive.

The use of floppy disk drives has declined dramatically in recent years, in favor of superior devices such as USB flash drives.

Semicolons do not appear at the end of every line in a C++ program.

There are rules that govern where semicolons are required and where they are not. -Part of learning C++ is learning where to place semicolons and other punctuation symbols.

What are constants used for?

They are commonly used to store known values in variables and to display messages on the screen.

First, notice the quotation marks are not stored with the string.

They are simply a way of marking the beginning and end of the string in your source code. -Second, notice the very last byte of the string. It contains the null terminator, which is represented by the \0 character. -The addition of this last byte means that although the string "Sebastian" is 9 characters long, it occupies 10 bytes of memory.

Which of the following will cause the next output to begin on a new line?

cout << endl;

The pico command to move the cursor the end of a line is _____ .

^E

The pico command to save the file without leaving the editor is _____ .

^O

The pico command to paste deleted lines is ________ . NOTE: Use ^ to indicate the CTRL key.

^U

The pico command to move backward one screen is _____

^Y

char data type :

a 1-byte integer data type

In a C++ program, two slash marks ( // ) indicate the beginning of ________.

a comment

Pseudocode :

a cross between human language and a programming language. -Although the computer can't understand pseudocode, programmers often find it helpful to write an algorithm using it. -This is because pseudocode is similar to natural language, yet close enough to programming language that it can be easily converted later into program source code.

Unlike a variable, a constant is :

a data item whose value cannot change during the program's execution.

Flowchart :

a diagram that shows the logical flow of a program. -It is a useful tool for planning each operation a program must perform, and the order in which the operations are to occur.

Every C++ program must have ________.

a function called main

C++ is an example of ________.

a high-level programming language

Desk-checking :

a process that can help locate these types of errors. -The term desk-checking means the programmer starts reading the program, or a portion of the program, and steps through each statement. -A sheet of paper is often used in this process to jot down the current contents of all variables and sketch what the screen looks like after each output operation.

Even when there is no power to the computer, data can be held in :

a secondary storage device

Operating system :

a set of programs that manages the computer's hardware devices and controls their processes.

A line is just that— :

a single line as it appears in the body of a program.

In programming terms, a group of characters inside a set of double quotation marks (" ") is called

a string constant & a string literal

The programmer usually enters source code into a computer using :

a text editor

Each word is assigned a unique number known as an :

address -The addresses are ordered from lowest to highest. -A word is identified by its address in much the same way a post office box is identified by an address.

In C++,......

all variables must be defined before they can be used because the variable definition is what causes the variables to be created in memory.

Variables :

allow you to store and work with data in the computer's memory. -They provide an "interface" to RAM. -Part of the job of programming is to determine how many variables a program will need and what type of information each will hold.

A set of well-defined steps for performing a task or solving a problem is known as ________.

an algorithm

Once the linker has finished with this step,.....

an executable file is created.

In the C++ statement pay = rate * hours; the * symbol is an example of ________.

an operator

As you can see, 'A' is a 1-byte element .....

and "A" is a 2-byte element.

A hierarchy chart begins with the overall task,...

and then refines it into smaller subtasks. Each of the subtasks is then refined into even smaller sets of subtasks, until each is small enough to be easily performed.

Because a char variable can store only one character in its memory location,.......

another data type is needed for a variable able to hold an entire string.

During the last phase of the translation process,....

another program called the linker combines the object file with the necessary library routines.

Constants :

are data items whose values cannot change while the program is running.

Logical errors, also called logic errors :

are mistakes that cause a program to produce erroneous results.

Variables :

are the names of memory loca- tions that may hold data.

A run-time error occurs when the running program ......

asks the computer to do something that is impossible, such as divide by zero. -Normally a run-time error causes the program to abort. -If the program runs, but fails to produce correct results, it likely contains one or more logic errors.

An operation that copies a value into a variable is called a(n) ________ operation.

assignment

The = symbol is called the :

assignment operator -It takes the value of the expression on the right and stores it in the variable whose name appears on the left.

A value is stored in a variable with an....

assignment statement.

An assignment operation :

assigns, or copies, a value into a variable.

Optical discs hold large amounts of data, and ....

because recordable CD and DVD drives are now commonplace, they are good media for creating backup copies of data.

A variable must be defined ________.

before it can be used

Strings, which allow a series of characters to be stored in consecutive memory locations.......

can be virtually any length. -This means that there must be some way for the program to know how long the string is. -In C++ this is done by appending an extra byte to the end of string constants. -In this last byte, the number 0 is stored. -It is called the null terminator or null character and marks the end of the string. -Don't confuse the null terminator with the character '0'. -If you want to print the character 0 on the screen, you use ASCII code 48. -If you want to mark the end of a string, you use ASCII code 0.

A variable defined as a char .....

can hold a single character, but strictly speaking, it is an integer data type.

The #include directive :

causes the contents of another file to be inserted into the program.

Complete the declaration for the variable that will hold the grade in this course. Only grades like A, B, C, D, F, I and W are assigned. _________ myGrade; // Student course grade.

char

The reason an integer data type is used to store characters is because....

characters are internally represented by numbers.

Low-level language :

close to the level of the computer, which means it resembles the numeric machine language of the computer more than the natural language of humans.

Run-time library :

collection of code -Programs almost always use some part of it.

The // marks the beginning of a.....

comment. The compiler ignores everything from the double-slash to the end of the line. -That means you can type anything you want on that line and the compiler will never complain! -Although comments are not required, they are very important to programmers.

Common output devices are :

computer screens, printers, and speakers.

A machine language program :

consists of a sequence of binary numbers (numbers consisting of only 1s and 0s) which the CPU interprets as commands.

The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components.

control unit

The control unit :

coordinates all of the computer's operations 1. It is responsible for determining where to get the next instruction and regulating the other major components of the computer with control signals

The contents of movieTitle can be displayed on the screen with cout, as shown in the next statement:

cout << "My favorite movie is " << movieTitle << endl;

Syntax errors are :

illegal uses of key words, operators, punctuation, and other language elements.

The header file iostream must be included :

in any program that uses the cout object. -This is because cout is not part of the "core" of the C++ language. -Specifically, it is part of the input-output stream library. -The header file, iostream, contains information describing iostream objects. -Without it, the compiler will not know how to properly compile a pro- gram that uses cout.

The #include directive causes the preprocessor to ......

include the contents of another file in the program. -The word inside the brackets, iostream, is the name of the file that is to be included. -The iostream file contains code that allows a C++ program to display output on the screen and read input from the keyboard. -Because this program uses cout to display screen output, the iostream file must be included. -Its contents are included in the program at the point the #include statement appears. -The iostream file is called a header file, so it should be included at the head, or top, of the program.

A variable name should :

indicate what the variable is used for.

Input is :

information a program collects from the outside world. -It can be sent to the program by the user, who is entering data at the keyboard or using the mouse. -It can also be read from disk files or hard- ware devices connected to the computer.

Output is :

information that a program sends to the outside world. -It can be words or graphics displayed on a screen, a report sent to the printer, data stored in a file, or information sent to any device connected to the computer.

The device that collects the information and sends it to the computer is called an :

input device

Three primary activities of a program are ________.

input, processing, and output

The three primary activities of a program are :

input, processing, and output.

A computer's CPU can only process instructions that are written in :

machine language.

There are many operators for:

manipulating numeric values and performing arithmetic operations.

You can assign a string literal to movieTitle with the assignment operator:

movieTitle = "Wheels of Fury";

The data stored on a computer storage device is not lost when the power is turned off. These devices are called non-___________ storage devices.

non-volatile

Comments are .....

notes of explanation that document lines or sections of a program.

C++ automatically places the .....

null terminator at the end of string constants.

#include <iostream> using namespace std; int main() { int Num; const int Year = 2011; cout << Num; cout << Year; return 0; } In this program, _______ is a variable, Year is not.

num

In programming, there are two general types of data :

numbers, such as 3, and characters, such as the letter 'A'.

They are called "high- level" because .....

they are closer to the level of human-readability than computer-readability.

Hexadecimal (base 16) and octal (base 8) are popular because ......

they make certain pro- gramming tasks more convenient than decimal numbers do.

Floating-point data types are used ....

to define variables that can hold real numbers.

The purpose of a memory address is :

to identify the location of a memory cell

Another common mistake is to forget :

to put the \n inside quotation marks. For example, the following code will not compile.

During the next phase the compiler steps through the preprocessed source code .....

translating each source code instruction into the appropriate machine language instruction. -This process will uncover any syntax errors that may be in the program.

Boolean variables are set to either :

true or false.

Generally, there are three types of operators:

unary, binary, and ternary. -These terms reflect the number of operands an oper- ator requires.

A common mistake made by beginning C++ students is to :

use a forward slash (/) instead of a back slash (\) when trying to write an escape sequence.

Programmers save their programs in text files, and then ....

use special software to convert their programs to machine language.

A storage location in the computer's memory that can hold a piece of data is called a(n) ________.

variable

Memory locations that can hold data are called

variables

To store a series of characters in a constant .....

we need a string constant.

A variable definition always specifies the name of a variable and tells :

what type of data it can hold

The terminal,.....

which consisted of a simple screen and keyboard, was known as the console.

Variables are classified according to their data type, ......

which determines the kind of information that may be stored in them. - Integer variables can only hold whole numbers.

The information is sent to an output device ......

which formats and presents it.

The programming process consists of several steps :

which include design, creation, testing, and debugging activities.

Unsigned short data type :

which is for storing non-negative integers such as ages or weights, uses its 16 bits to represent the values 0 through +65,535.

he simplest type of screen output that a program can display is console output, .......

which is merely plain text

cout is classified as a stream object,.....

which means it works with streams of data. -To print a message on the screen, you send a stream of characters to cout.

Programming languages :

which use words instead of numbers, were invented to ease the task of programming. -A program can be written in a programming language such as C++, which is much easier to understand than machine language.

Just in case you need to force a constant to be stored as a float,.....

you can append the letter F or f to the end of it. - For example, the following constants would be stored as float numbers: 1.2F 45.907f

If you are writing a program that works with dollar amounts or precise measurements,.......

you need a data type that allows fractional values. -In programming terms, these are called floating-point numbers.

The exact sizes of these data types is dependent on the computer you are using. The only guarantees are:

• A double is at least as big as a float. • A long double is at least as big as a double. Note: You will notice there are no unsigned floating-point data types. Note: On all machines, variables of the float, double, and long double data type can store both positive and negative numbers.

Software engineers use a number of tools in their craft :

• Program specifications • Charts and diagrams of screen output • Hierarchy charts • Pseudocode • Examples of expected input and desired output • Special software designed for testing programs

Legal Identifiers

• The first character must be one of the letters a through z, A through Z, or an under- score character (_). • After the first character you may use the letters a through z or A through Z, the digits 0 through 9, or underscores. • Uppercase and lowercase characters are distinct. This means ItemsOrdered is not the same as itemsordered.

Listed below are a few of the things that must be designed for any real-world computer program:

• The logical flow of the instructions • The mathematical procedures • The appearance of the screens • The way information is presented to the user • The program's "user-friendliness" • Manuals and other forms of written documentation

Your primary considerations for selecting the best data type for a numeric variable are the following:

• whether the variable needs to hold integers or floating-point values, • the largest and smallest numbers that the variable needs to be able to store, • whether the variable needs to hold signed (both positive and negative) or only unsigned (just zero and positive) numbers, and • the number of decimal places of precision needed for values stored in the variable.


Set pelajaran terkait