|
|
|
|
|
|
|
|
|
|
Introductions
Nerf
Steil Cup
Chapel
Schaum's
book
Easel
Decimal- base 10
Binary - base 2
Digital information measurement units
- bit -
binary digit representing on/off or 1/0
- byte - 8
bits, number of bits needed to encode a single character of
text
- kilobyte
- 1000 bytes (or 210 = 1024 bytes)
- megabyte
- 1000 KB (or 210 = 1024 KB)
- gigabyte
- 1000 MB (or 210 = 1024 MB)
- terabyte
- 1000 GB (or 210 = 1024 GB)
Assign Homework
|
|
Hexadecimal (hex) - base 16
bit
& byte
ASCII
- American Standard Code for Information
Interchange
See
ASCII Table in decimal, binary, and hex in Appendix A
of Schaum
computer - Electronic machine that operates under
the control of stored instructions and can:
- accept
data (input),
- process
data arithmetically and logically
- produce
results (output)
programming - telling the computer in minute
detail (typically with a programming language) the sequence of
steps required to perform a task.
software development - The entire process
involved in creating software and ensuring its future availability.
This includes the following:
- analysis
of the problem the software should solve
-
designing how the software should be constructed
-
implementation (programming)
- testing
the software
-
deploying the software
-
maintaining the software and fixing bugs
Hardware vs. software
Hardware - The physical parts of a computer that
you can see and touch
Software - The programs that control the
hardware
data vs programs (programs are instructions run
by the processor, data are values used by the programs, they are
both just bytes)
Algorithm (Defined by Google) - a process or set
of rules to be followed in calculations or other problem-solving
operations, esp. by a computer.
Primitive - A task that one can perform in an
algorithm with no further explanation
Assign
Homework
|
|
Algorithm (ways To Represent)
-
Verbal
-
Textual
- Flow
chart
-
Program
Fundamental Theorem of Structured
Programming
sequence - one process
after another
choice
- one way or two way choice
repetition - pretest or
post test loop
flow chart control structures - a grouping of
flow chart logic with one way in and one way out
examples: a process, one way choice, two way
choice, prest loop, post test loop
Finding remainders with % (the modules
operator)
terminator
process
choice/decision
Structured vs. Unstructured flowcharts
nesting
count to 10
|
|
|
|
|
|
Review "what is it #1 & #2 flowcharts"
Algorithm/Flowchart examples
Algorithm Constructs: 1 way choice, 2 way choice,
pretest loop, post-test loop
See Notes on Easel
increment, decrement
Assign
Homework
|
|
More Flow chart examples
Assign
Homework
|
|
|
|
Examples
Decimal To Binary Flowchart using Overflow
Assign
Homework
|
|
Booting a computer (bootstrapping)
BIOS (Basic Input Output System)
Dream Spark - MS Software
data vs programs (programs are instructions run
by the processor, data are values used by the programs, they are
both just bytes)
programming languages & generations
Compile - translate to machine language
Compiler - program that compiles
syntax - how symbols are combined to form valid
expressions
semantics - meaning of the symbols that form an
expression
language - symbols with semantic meaning and
syntax used to write instructions for the computer
Language Generations
Low
1st - Machine (.exe
files in windows)
2nd - Assembly
High
3rd - High Level (c++ is
here)
4th - Very High Level
Intro to C++ syntax
|
|
History of C++
- 1950s -
Early programming languages where difficult to use, and maintaining
large programs was becomming increasingly difficult
- 1960s -
Martin Richards, working the University of Cambridge, developed a
structured programming language called BCPL (Basic Combined
Programming Language). Ken Thompson at Bell Labs created B, a
modified version of BCPL
- 1970s -
Dennis Ritchie at Bell Labs improved on the B language and called
his creation C. It is one of the most widely used programming
lanugages of all time
- 1980s -
A new paradigm was being adopted called Object-Oriented Programming
(OOP) which sought to reduce the cost of designing, implementing,
debugging, and modifying large, complex programs. Bjarne Stroustrup
at Bell Labs created C++ by adding OOP constructs to the C
programming language. C++ is one of the most popular programming
languages in the world
- Many
programming languages (Java, C#, JavaScript, Python) are very
similar to C++, so once you learn C++ it is not difficult to learn
other programming languages
IDE - Integrated Development Environment
Compiler, code editor,
Debugger, Help system
#include<iostream>
using namespace std;
void main() {}
literal - a number such as 45 or a word such as
"Bob" that is not a variable
// - begins a comment line in c++
# - lines that begin with this are instructions
to the compiler (aka, compiler directive)
brief introduction to variables
writing to output stream... cout
<<
reading from input stream... cin >>
>> - stream extraction operator
<< - stream insertion operator
cascading <<
Homework
Read chapters 1 from Schaum's (Due Monday)
|
|
|
|
declaring variables
data types
short - 2 bytes, no decimals
int - 4 bytes, no decimals
float - 4 bytes, with decimals
double - 8 bytes, with decimals
bool - 1 byte, true or false
_______________
Integer vs. Floating point Division
integer division - decimals are lost
% - modulas operator - used to find remainders of
integer division
_______________
cin >> - reads until white
space
example - 1 2 3 4 5 - entered
into the input stream
cascading >>
_______________
Examples
Assign
Homework
Read chapter 2 from Schaum's (Skip 2.3) Due
Wednesday
|
|
Type conversions
Scope
Arithmetic operators
increment & decrement
Round-off error
|
|
conditional statements - if, if-else, if-else-if
control structures
if - one way choice
if else - two way choice
use of {} with conditions
escape sequences "\n, \r, \t, \a, \\, \b"
_______________
logical and &&
logical or ||
use ! (aka not) to negate a boolean
expression
Examples
Assign
Homework
Read Schaum's Chapter 3.1-3.8 (Due Monday)
|
|
|
|
if-else-if
when can nested if-else structures be turned into
if-else-if structures
accidental use of a ";" at the end of an if
statement
Examples
|
|
|
|
|
|
|
|
|
|
-
Computer Hardware
- Booting
a computer (bootstrapping)
- BIOS
(Basic Input Output System)
-
Operating System
-
Instruction Cycle
|
|
while
"I will not talk in class" example
#include <iomanip>
++ increment operator
-- decrement operator
Examples
Assign
Homework
Read chapters 4 from Schaum
|
|
nested loops
do while
determinate(counted) vs indeterminate loops
data validation loops
Controlling the width of the next item to be
displayed
- cout
<< setw(4) << value;
Example
Assign
Homework
Read chapters 4 from Schaum
|
|
|
|
4 parts to every loop
1. Initialize the test condition
2. Test the condition
3. Body of the loop.... Do something useful
4. Change the test condition
for loops
|
|
|
|
More on nested loops and drawing ascii
rectangles, checkerboards and checkerboards with frames.
Assign
Project
|
|
|
|
Controlling decimal number output
cout.setf(ios::fixed) makes all floating-point
numbers display their decimal points (no scientific notation)
cout.precision(places) rounds the decimal places
to a given number. When the precision that is set causes some
digits to not be shown, those that are displayed are rounded.
|
|
|
|
|
|
|
|
Introduction to functions
examples of built in functions
- sqrt
& other math functions
void - verb names
non-void - noun names - must return a
value
function signature (aka. declaration/definition)
vs function call
arguments and parameters
-
parameter - part of the function's signature
- argument
- part of the function call
non-void functions can only return one value but
can have multiple return statements
//function aka method, routine,
sub-routine, sub
Why use functions?
-
documentation
-
modularization aka componentization aka hiding the mess
- reuse -
saves time and is more reliable
- reduces
complexity: Functions can simplify a program greatly and make it
easier to understand what is happening, and program tend to be
shorter
Examples
none
Assign
Homework
Read Chapter 5 sections 1-10
|
|
|
|
c++ return statement
by value vs. by reference
By Value:
- By
default, arguments are passed by value to a function which means a
copy is made of the argument
- Any
changes made to a parameter are only changing the copy, not the
actual argument
- It's
like handing someone a photocopy of a paper you wrote; any changes
the person makes to the photocopy doesn't change the original
paper
By Reference:
- This
means the parameter is just another name for the argument
-
Therefore any changes made to the reference parameter will also
change the argument (modifying x will change a, and modifying y
will change b)
- It's
like handing someone the original paper you wrote; any changes the
person makes to the original will affect the original.
- Uses an
ampersand (&)
only variables can be passed to a function that
receives arguments by reference (literals cannot be passed by
ref)
Work examples from Schaum's book chapter 5
Examples
none
Assign
Homework
Work problems 5.21, 5.22, 5.24 and 5.25 from
Schaum's book. Use Boolean return values rather than integers
for 5.21 and 5.22. (Due Wednesday)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|