Programming

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Preprocessor Directives

#include <iostream>. In a C++ program, statements that begin with the symbol # are called preprocessor directives. These statements are processed by a program called preprocessor.

Arithmetic operators

+ Addition - Subtraction or negation * Multiplication / Division % Modulus or remainder

Assignment statements

...

Function Main

A C++ program is a collection of functions, one of which is the function main. All C++ programs require a function main.

Output devices

A monitor, printer, and secondary storage.

Compiler

A program that translates instructions written in a high-level language into the equivalent machine language.

Reserved Words

A second category of tokens is reserved word symbols. Some of the reserved word symbols include the following: int, float, double, char, const, void, return Reserved words are also called keywords. The letters that make up a reserved word are always lowercase. Each reserved word is considered to be a single symbol. Furthermore, reserved words cannot be redefined within any program.

Programming language

A set of rules, symbols, and special words. Special symbols, words, and syntax rules.

Identifiers

A third category of tokens is identifiers. Identifiers are names of variables, constants, and functions. Identifier must begin with a letter or underscore and must consists of letters, digits, and the underscore character (_), no other symbols are permitted to form an identifier. Some identifiers are predefined; two predefined identifiers that you will encounter frequently are cout and cin. Unlike reserved words, predefined identifiers can be redefined, but it would not be wise to do so.

<iostream>

scientific

<iomanip>

setfill

<iomanip>

setprecision

<iomanip>

setprecision, setw, setfill

<iomanip>

setw

<iostream>

showpoint

int main ()

{ }

Data type rules

• You can use the operators +, -, *, and / with both integral and floatingpoint data types. These operators work with integral and floating-point data the same way as you learned in a college algebra course. • When you use / with the integral data type, it gives the quotient in ordinary division. That is, integral division truncates any fractional part; there is no rounding. • You use % with only the integral data type, to find the remainder in ordinary division.

User readability

Formatting

Structured Programming

Functions

Function arguments/parameters

Header/library<cmath> Function Pow(x,y); Argument (x,y);

Expressions

Integral expression Floating-point Mixed expressions

Machine Language

Is the most basic language of a computer, the machine language, provides program instructions in bits.

Fail state

Is when the wrong data type is inputted.

Structured Programming

Iteration

Order of precedence

Left to right ( ) Left to right * / % Left to right + -

Logic errors

Logic errors are when the answer does not meet the expectations. Logic errors are typically not caught by the compiler. Example 1+1=5

Long

Long is used to represent integers between -9223372036854775808 9223372036854775807.

Block comment

Multiple-line comments are enclosed between /* and */. The compiler ignores anything that appears between /* and */.

Predefined Function

Predefined or standard functions, are already written functions when it is activated, or executed, it accomplishes something.

Code readability

Proper indentation can show the natural grouping and subordination of statements. If your program is properly indented, you can spot and fix errors quickly.

Run-time errors

Run-time errors are given when the code cannot be executed at that particular moment. Example a division by 0.

Structured Programming

Selection

Structured Programming

Sequence

Single line comment

Single-line comments begin with // and can be placed anywhere in the line. Everything encountered in that line after // is ignored by the compiler.

Software

Software are programs written to perform specific tasks. There are two types of programs: system programs and application programs. System programs control the computer. Application programs perform a specific task. Word processors, spreadsheets, and games are examples of application programs.

Predefined identifiers - cin and cout

Some identifiers are predefined; two predefined identifiers that you will encounter frequently are cout and cin. Unlike reserved words, predefined identifiers can be redefined, but it would not be wise to do so.

Syntax errors

Syntax errors are given when the rules of the language are used incorrectly. Errors in syntax are detected during compilation. Example missing ";" or ">>".

Short

The Short data type is used to represent integers between -32,768 and 32,767, or numbers without a decimal part.

Source Code

The code of a program written in a high-level language.

Bool

The data type bool has only two values: true and false. True and false are reserved words. The identifier true is set to 1, and the identifier false is set to 0

Char

The data type char is mainly used to represent single characters—that is, letters, digits, and special symbols. Thus, the char data type can represent every key on your keyboard. When using the char data type, you enclose each character represented within single quotation marks.

Double

The data type double is to represent any decimal number between -1.7*E308 and 1.7*E308 . The memory allocated is eight bytes.

Float

The data type float is used to represent any decimal number between -3.4*E38 and 3.4*E38. The memory allocated is four bytes.

Int

The int data type is used to represent integers between -2,147,483,648 and 2,147,483,647, or numbers without a decimal part.

Input devices

The keyboard, mouse, scanner, camera, and secondary storage.

Object Code

The machine language version of the high-level language program.

Using namespace std;

The namespace mechanism is a feature ofANSI/ISO Standard C++. using namespace std;

Operating System

The operating system handles the overall activity of the computer and provides services. Some of these services include memory management, input/output activities, and storage management.

Concatenate

The operator + can be used to concatenate two values of the type string. width + length outputs WitLen.

Data Types

int short long char bool unsigned float double

Extraction

int main()

<iostream>

left

Insertion

<<

Extraction

>>

ASCII

ASCII is a patterns of seven bits that represent in computers the upper and lowercase letters of the English alphabet, punctuation symbols, the digits 0 through 9, and certain control information such as line feeds, carriage returns, and tabs

Program Planning

Algorithm Get.... Do.... Print Input....Process....Output Pseudo code

Literals

Are of the data type string and are declare with "quotations marks"

Case sensitive

C++ is case sensitive—uppercase and lowercase letters are considered different. Thus, the identifier Number is not the same as the identifier number or NUMBER.

Casting data types

Casting data types means to converter a floating-point (decimal) number to an integer by simply dropping the decimal part of the floating-point number.

Cin

Cin (pronounced ''see-in''), which stands for common input (Keyboard).

Const

Const is a memory location whose content is not allowed to change during program execution. In C++, const is a reserved word. Count must be initialized and declared all in one statement because from this statement on the compiler will reject any attempt to change the value.

Cout

Cout (pronounced ''see-out''), which stands for common output (Monitor).

Header file (#include < > )

Every library has a name and is referred to by a header file. #include <iostream>

Declarations

Declaration statements are used to declare things, such as variables.

Structured Programming

Dividing a problem into smaller subproblems is called structured design. Each subproblem is then analyzed, and a solution is obtained to solve the subproblem. The solutions to all of the subproblems are then combined to solve the overall problem. This process of implementing a structured design is called structured programming.

Special Symbols

The smallest individual unit of a program written in any language is called a token. C++'s tokens are divided into special symbols, word symbols, and identifiers. Following are some of the special symbols: + Addition - Subtraction * Multiplication / Division % Modulus/Remainder . Decimal point and regular expression operator. ; End of statement. , Commas are used to separate items in a list. = Means assign what is on the right to the left of the symbol. <= Item on the left is less than or equal to the item on the right of the symbol. >= Item on the left is greater than or equal to the item on the right of the symbol. == Item on the right equals to the item on the left of the symbol. != Item on the right not equals to the item on the left of the symbol.

return 0;

The statement return 0; must be included in the function main and must be the last statement. For now, think of this statement as the end-of-program statement. In C++, return is a reserved word.

Syntax

The syntax rules of a language tell what is legal and what is not legal.

Initialization

There are two ways to initialize a variable: by using the assignment statement and by using a read statement (common input).

whitespace

Whitespaces include blanks, tabs, and newline characters. Whitespaces are nonprintable.

Escape Sequence

\t Tab \n Next line \\ Backslash \" Double quotations \' Single quotations \b Backspace \r Beginning of current line

Extraction

cin

Insertion

cout

fixed

cout << fixed;

ostreamVar << left;

cout << left;

ostreamVar << right;

cout << right;

ostreamVar << setfill(ch);

cout << setfill('#');

setprecision(n)

cout << setprecision(#);

setw

cout << setw(#) << x << endl;

unsetf

cout.unsetf(ios::fixed);

ostreamVar.unsetf(ios::left);

cout.unsetf(ios::left);

<iostream>

endl

<iostream>

endl, fixed, showpoint, scientific, left

<iostream>

fixed


Kaugnay na mga set ng pag-aaral

TEAS- Determine the meaning of words by analyzing word parts

View Set

Admin Chapter 1 Questions and Vocab

View Set

Net Auth & Security Exam 2 Ch. 4-8

View Set

Diagnostic Imaging, CervicoThoracic, Supine ALIF, XLIF Quiz, Biologics, iOS - NVM5 & Bendini, iGA, Spine Fundamentals, NVM5 Troubleshooting, TL Fixation, MAS Midline / TLIF

View Set

Adult Health II Musculoskeletal Assessment Chapter 35 PREP U

View Set

Sociology Final Exam Chapter 1-3

View Set