0% found this document useful (0 votes)
2K views7 pages

Zybooks Notes: Section One (1.1-1.6)

The document provides an overview of programming concepts covered in sections 1-8 of a programming textbook. It discusses topics like variables, data types, arithmetic operations, functions, loops, strings, and debugging. The key topics covered include the basic structure of a program, using variables to store and manipulate data, writing reusable functions, different types of loops to repeat tasks, and operations to manipulate string values.

Uploaded by

Michael Michaud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views7 pages

Zybooks Notes: Section One (1.1-1.6)

The document provides an overview of programming concepts covered in sections 1-8 of a programming textbook. It discusses topics like variables, data types, arithmetic operations, functions, loops, strings, and debugging. The key topics covered include the basic structure of a program, using variables to store and manipulate data, writing reusable functions, different types of loops to repeat tasks, and operations to manipulate string values.

Uploaded by

Michael Michaud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Wednesday, September 9, 2020

ZYBOOKS NOTES
https://www.icloud.com/pages/0qcM__l6ZT3igEg1pWhlXdmsQ#ZYBOOKS_NOTES

Section One (1.1-1.6)


1.1 Programming

- A program is instructions executing one at a time.

- Basic instructor types:

- Input: A program gets data

- Process: Performs computations in the data

- Output: Puts the data somewhere

- Uses variables to refer to data (x, y, z)

- Computational thinking - creating a sequence of instructions to solve a problem

- Sequence of instructions to solve a problem is an algorithms.

1.2 Programming Basics

- Code: The textual representation of a program

- Starts with main ( ) {

- Each statement ends with ;

- Int___ introduces an integer

- Cout prints to screen

- Return 0; ends the program

- Cin is characters in

- cout<<“__” prints text

- cout<<____; outputs a variable’s value

1.3 Comments and White Space

- Comment: text that a programmer adds to a code, not read by an computer

- Single line comment: starts with // and includes all the following text on that line.

1
Wednesday, September 9, 2020
- Multiline comment: starts with /* and ends with */ where alll the text between is the
comment.

- Whitespace: Blank spaces between items within a statement and blank lines
between statements

1.4 Error and Warnings

-Syntax Errors: Violates a programming language’s rules on how symbols can be


combined to create a program

-Logic Error or Bug: Code works but completes incorrect functions.

1.5 Variables

- Variable Declaration: A statement that declares a new variable, specifying name and
type.

- Assignment Statement: Assigns the variable on the left hand side of the = to the right
hand side.

1.6 Variables and Assignments

Assignment: Assigns a variable with a value such as x = 5

Section Two (2.1-2.9)


2.1 Arithmetic Expressions

- Expression: A combination of items like variables and such

- Literal: A speci c value in code

- Operator: A symbol that performs a function in calculation

2.2 Arithmetic Conventions

- Put a space around operators

- Compound Operators: numBox + = 2 is equivalent to numBox + 2

- Integral Literals cannot have commas

2.3 Floating Point Numbers

- Floating point numbers: a real number containing a decimal point that can appear
anywhere in the number

- A double variable: stores a oating-point number

2
fi
fl
Wednesday, September 9, 2020
- Floating-point literal: A number with a fractional part

- Using int for countable items and double for measurements

2.4 Characters

- Identi er: A name created by a programmer for an item

- Sequence of letters from a - z

- Start with a letter or underscore

- They are case sensitive

2.5 Characters

- Declare a character variable: char ___;

- Character literal can store one variable

- Ex: myKey = ‘m’;

- Cin can be used to get a one character output

- Ex: cin>>myKey ==> m

- Escape sequences:

- \n ==> new line

- \+ ==> new tab

- \’ ==> single quote

- \“ ==> double quote

- \\ ==> backslash

2.6 Strings

- String: sequence of characters

- String Literal: Surrounds a character sequence with double quotes

- Whitespace Character: a character used to represent horizontal and vertical spaces


in text

- userString puts variables in until whitespace

- Ex: cin>>userString;

- Hello there (will put in only Hello)

2.7 Constant Variables

-Useless Information

3
fi
Wednesday, September 9, 2020
2.8 Type Conversions

-Type Conversion: A conversion of one data to another

-Type Cast: Explicitly converts a value of one type to another type

2.9 Integer Division and Modulo

- Modulo Operator (%) evaluates the remainder of the division

- Ex: 23%10 —> 3

- Both sides of the % must be integers

Section Three (3.1-3.5)


3.1 Using Math Functions

- Function: A list of statements executed by invoking the function's name, such


invoking known as a function call.

- Arguments: Function input values that appear within ( ).

- Functions:

- sqrt(x)- square root of a function

- pow(x,y)- raise x to y power

- fabs(x)- absolute value of x

3.2 User-de ned function Basics

- Functions are prede ned statements for repeatably used functions, and help speed
up programs and reduce redundancy.

- Functions are named lists of statements:

- Function De nition: The new function's name and a block of statements

-Function Call: An invocation of a function name causes the function to execute

-Parameter: A function input speci ed in a function de nition

-Argument- A value provided to a function's parameter during a function call

3.3 Return

-Return Statement: A statement a function returns

-void statement: Indicates the function does not return any value

4
fi
fi
fi
fi
fi
Wednesday, September 9, 2020
3.4 Reasons for De ning Functions

- Allows for easier reading for the program by people

-Programmers commonly use functions to write programs modularly and incrementally

- Modular Development: The process of dividing a program into separate


modules that can be developed and tested separately and then integrated into a single
program.

-Incremental Development: A process in which a programmer writes, compiles,


and tests a small amount of code, then writes, compiles, and tests a small amount
more.

-Function Stub: A function de nition whose statements have not yet been
written.

3.5 Common Errors

-Nothing of importance

Section Four (4.1 - 4.3)


4.1 Unit Testing

- Unit testing: The process of individually testing a small part of a program, usually a
function

- Testbench: Program that checks that a function returns the correct output values
through inputing values known as test vectors

- Assert() is a function that returns an error message and exits the program if assert ()'s
input expression is false

-Boarder cases: Inputs that represent the extreme of input values into a function.

4.2 Scope of Variable/Function De nitions

-Scope: The de ned variable or function item that is visible to a certain amount of code

-Global Variable: A variable declared outside any function

-Local Variable: A variable declared inside a function

-Function Declaration: Speci es the function's return type, name, and parameters, also
known as a function prototype

5
fi
fi
fi
fi
fi
Wednesday, September 9, 2020
4.3 Debugging

-Debugging: The process of determining and xing the cause of a problem in a


computer program also known as troubleshooting.

Section Six (6.1-6.5)


6.1 Loops

-Loops: A program construct that repeatedly executes the loop's statements (known as
the body) while the loop's expression is true. When false, execution proceeds past the
loop.

6.2 While Loops

-While Loop: A program that repeatedly executes a list of sub-statements (known as a


loops body) while the loop's expression evaluates to true. Each execution is an
iteration.

6.3 More While Examples

-sentinel value: special value indicating the end of a list

6.4 Function with Branches/Loops

-nothing

6.5 Developing Programs Increment

Section Seven (7.1-7.5)


7.1 For Loops

-For Loop: A loop that loops a speci c number of time and has three parts: a loops
variable initialization, a loops expression, and a loop variable update.

- for (i = 0; i < 10; ++1)

7.2 More For Loop Examples

- The loops are initialized to i = 0

- The ++ operators: pre x form (++i) and post x form (i++)

7.3 Nested Loops

- Nested Loop: Loop that appears in the body of another loop. Parts referred to as the
inner and outer loops.

7.4 Variable Name Scope

-Scope: The region of code where a declared name is valid

6
fi
fi
fi
fi
Wednesday, September 9, 2020

Section Eight (8.1-8.2)


8.1 String Access Operations

-A string is a sequence of characters in memory. Each string character has a position


number called an index that starts from zero.

- at(): variable.at(x) gets the x index of a string.

- can use at() to replace a string index in a word.

variable.at(3) = "!";

runs --> run!

-.size() returns the length of a string

x = word

x.size() --> 4

-.append adds letters to a word

x = word

x.append("!!!") --> word!!!

- index = length - 1

8.2 Loops and Strings

-Nothing

You might also like