first day orientation
TRANSCRIPT
-
8/22/2019 First Day Orientation
1/86
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
First Day
Orientation
-
8/22/2019 First Day Orientation
2/86
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
First Day
Orientation
-
8/22/2019 First Day Orientation
3/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
CLASSROOM POLICIES
Tardiness:
15 min after the start time Late
16 min onwards after the start time Absent
3 Recorded Tardiness 1 Absence
-
8/22/2019 First Day Orientation
4/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
CLASSROOM POLICIES
Absences:
Excused, if an excuse letter is presented the next meeting
Excuse letter must be accompanied by an ID with
signature of the signatory from the said letter.3 excused absences 1 official absence
Max number of absences 20% of total
number of meetings in a term (5 absences only)
-
8/22/2019 First Day Orientation
5/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
CLASSROOM POLICIES
Use of Cell Phones:
Must be kept in silent mode during the
class/exams
No texting during the classA call may be entertained outside the room
-
8/22/2019 First Day Orientation
6/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
CLASSROOM POLICIES
Use of Other Electronic Gadgets:
Not allowed inside the classroom
-
8/22/2019 First Day Orientation
7/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
CLASSROOM POLICIES
No eating or drinking inside the room
Let your presence or absence from the room be
known to your professor
Group cooperation is encouraged
Ask questions
RESPECT for each individual is a MUST
-
8/22/2019 First Day Orientation
8/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
GRADING SYSTEM
MG = 60% CS + 40% ME
FG = 60% CS + 15% ME + 25% FE
Lecture 70%Laboratory 30%
Passing is 75%
-
8/22/2019 First Day Orientation
9/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
GRADING SYSTEM
Laboratory Class Standing 60%
40% Machine Problems
30% Project
25% Practical Exam5% Teachers Evaluation
Midterm Grade = 60% CS + 40% ME
-
8/22/2019 First Day Orientation
10/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
GRADING SYSTEM
Laboratory Class Standing 60%
20% Long Quiz (Average of at least 3 quizzes)
20% Machine Problems
15% Seatwork, Assignments, Recitations (ClassParticipation)
5% Teachers Evaluation
Midterm Grade = 60% CS + 40% ME
-
8/22/2019 First Day Orientation
11/86
First Day Orientat ion
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
GRADING SYSTEM
Lecture Class Standing 60%
40% Long Quiz (Average of at least 3 quizzes)
30% Short Quizzes
25% Seatwork, Assignments, Recitations (ClassParticipation)
5% Teachers Evaluation
Midterm Grade = 60% CS + 40% ME
-
8/22/2019 First Day Orientation
12/86
Quest ions and Comments
FEUEAST ASIA COLLEGEInformation
TechnologyDepartment
-
8/22/2019 First Day Orientation
13/86
Lecture 3: Intro to C++
programming
Engr. J. Cansino
-
8/22/2019 First Day Orientation
14/86
C++ Anatomy
The Parts of a C++ Program
// A simple C++ program
#include using namespace std;
intmain()
{cout
-
8/22/2019 First Day Orientation
15/86
The cout Object
cout is used to produce console output,
hence cout!
It is classified as a stream object, which
means it works with a stream of data, such
as a string literal (stream of characters)
Run Example
-
8/22/2019 First Day Orientation
16/86
Program 2-2
Can be used to send more than one item out.
// A simple C++ program
#include
using namespace std;
intmain()
{ cout
-
8/22/2019 First Day Orientation
17/86
Program 2-3
Output can also be broken up into many
statements, but still shows up on a single
line.// A simple C++ program
#include
using namespace std;
intmain()
{cout
-
8/22/2019 First Day Orientation
18/86
Program 2-4
Unless otherwise specified, the output ofcout is displayed on a continuous stream.
Sometimes, this is not desireable
// A simple C++ program#include
using namespace std;
intmain()
{
cout
-
8/22/2019 First Day Orientation
19/86
Solution: start a new line
Stream manipulator : endl (end-L or end line)
Newline escape sequence: \n// A simple C++ program
#include
using namespace std;
intmain()
{
cout
-
8/22/2019 First Day Orientation
20/86
// A simple C++ program
#include
using namespace std;
intmain(){
cout
-
8/22/2019 First Day Orientation
21/86
Common Escape Sequences
\a Bell (beep)
\b Backspace
\n Newline \r Return
\t Tab
\\ Backslash \' Single quote
\" Double quote
-
8/22/2019 First Day Orientation
22/86
The #include directive
Example: #include
This is a header file that contains
information describing iostream objects,
such as cout
Part of the input-output stream library
Header file contains C++ code andtypically describes complex objects, like
cout
Later on, we will create our own header
files
-
8/22/2019 First Day Orientation
23/86
Variables and Literals
Variables represent storage locations in
the computers memory
int number; variable definition
Sets up name and type of data the variable
will hold
number = 5;variable assignment
(integer literal)
number = 5;string literal
-
8/22/2019 First Day Orientation
24/86
// A simple C++ program
#include
using namespace std;intmain()
{
int number;
number = 5;
cout
-
8/22/2019 First Day Orientation
25/86
Identifiers
Identifier: programmer-defined name that
represents some element of a program
Example: variable names Usually indicates what the variable is used
for
Caveat: cannot use C++ key words andmust be legal
-
8/22/2019 First Day Orientation
26/86
Identifier Rules
First character must be a z, A Z, or an
underscore( _ )
After the first character, a z, A Z, an
underscore, or 0 9
Upper and lower are distinct, that is C++ is
case sensitive
-
8/22/2019 First Day Orientation
27/86
Integer Data Types
Two general data types:
Numeric
Character
Number is further broken down
integer
floating point
Variables declared as integers can only hold whole
numbers
i.e. 1, 2, 3
Floating point can store decimal numbers
i.e. 4.657, -8.96, 3.5
-
8/22/2019 First Day Orientation
28/86
Concerns when selecting
numeric data types Largest and smallest value that may be
stored
How much memory that value uses
Signed or unsigned
Decimal Precision
-
8/22/2019 First Day Orientation
29/86
Tips
use unsigned
Combine same type variable definitions on
one line
Use L after integer literals if long is
needed
Example : number = 32L
Uses 4 bytes of memory instead of just 2
-
8/22/2019 First Day Orientation
30/86
Lecture 3b: Intro to C++
program (Contd)Engr. J.Cansino
-
8/22/2019 First Day Orientation
31/86
The char Data Type
1 byte integer data type
Used for storing characters as an int
ASCII (American Standard Code forInformation Interchange) Table
-
8/22/2019 First Day Orientation
32/86
Character literals are not string literals!
Program 2-12 and 2-13
char letter;
Letter = a;
char letter;
Letter = a;
-
8/22/2019 First Day Orientation
33/86
// Relationship between integers and characters
#include
using namespace std;
intmain()
{
char letter;
letter = 65;
cout
-
8/22/2019 First Day Orientation
34/86
// A simple C++ program
#include
using namespace std;
intmain()
{
char letter;
letter = A;
cout
-
8/22/2019 First Day Orientation
35/86
Floating-Point Data Types Used to define variables that hold real
numbers float (single precision)
double (double precision)
long double (at least 2x double size)
-
8/22/2019 First Day Orientation
36/86
Tips
1.2F forces literal to be stored as a float
The following are equivalent floating-point
literals
1.4E11
1.4e11
1.4E+11
1.4e+11
140000000000.0
-
8/22/2019 First Day Orientation
37/86
// A simple C++ program
#include
using namespace std;
intmain()
{ float distance;
double mass;
distance = 1.496979E11;
mass = 1.989E30;
cout
-
8/22/2019 First Day Orientation
38/86
The bool Data Type
Boolean variables can either be true or
false ( 0 or 1)
Program 2-16
-
8/22/2019 First Day Orientation
39/86
// A simple C++ program
#include
using namespace std;
intmain()
{ bool boolValue;
boolValue = true;
cout
-
8/22/2019 First Day Orientation
40/86
Determining the Size of a Data
Type The sizeofoperator can be used to
determine the size of a data type on any
system.
Example: sizeof(int);
Program 2.17
-
8/22/2019 First Day Orientation
41/86
// A simple C++ program
#include
using namespace std;
intmain()
{ long double apple;
cout
-
8/22/2019 First Day Orientation
42/86
Variable assignments and
initializations An assignment operation assigns, or
copies, a value into a variable. When a
value is assigned as part of its definition, it
is called initialization.
Program 2-18
-
8/22/2019 First Day Orientation
43/86
// A simple C++ program
#include
using namespace std;
intmain()
{ int month =2, days =28;
cout
-
8/22/2019 First Day Orientation
44/86
Scope
A variables scope is that part of the
program that has access to that variable.
Complex, and the rules that define a
variables scope will be covered throughout
the lectures
Rule 1: A variable cannot be used in any
part of the program until it is defined.
-
8/22/2019 First Day Orientation
45/86
Arithmetic Operators
There are many operators for manipulating
numeric values and performing arithmetic
operations.
Three types
Unirary (requires only 1 operand. Exmp. -5)
Binary (requires 2. Exmp. A = 3)
Ternary (requires 3. Exmp. Discussed in chp.4)
-
8/22/2019 First Day Orientation
46/86
Common Arithmetic Operators
Binary operators.
+ addition, total = cost + tax;
- subtraction, cost = total tax;
* multiplication, tax =
/ division, salePrice = original / 2;
% modulo, remainder = value % 3;
Tip: when both operands in a division areintegers, the statement will perform int division.
Use one number as floating point if need.
Do program 2-20
C t d P i
-
8/22/2019 First Day Orientation
47/86
Comments and Programming
Style Not used by the compiler, i.e. invisible
// - single line comment
/* */ - multiline comment
Programming Style is the visual
arrangement of your code.
Make it readable for yourself and others!
-
8/22/2019 First Day Orientation
48/86
Lecture 3c: Expressions and
InteractivityCS 126
Engr. J. Cansino
-
8/22/2019 First Day Orientation
49/86
The cin Object
The cout objects counterpart for input is
cin
Standard console input object
Promptthe user for input
>> stream extraction operator (remember
-
8/22/2019 First Day Orientation
50/86
// This program asks the user to enter the length and width of
// a rectangle. It calculates the rectangle's area and displays
// the value on the screen.
#include
using namespace std;
int main()
{
int length, width, area;
cout width;
area = length * width;
cout
-
8/22/2019 First Day Orientation
51/86
Entering multiple values// This program asks the user to enter the length and width of
// a rectangle. It calculates the rectangle's area and displays
// the value on the screen.
#include
using namespace std;
int main(){
int length, width, area;
cout width;
area = length * width;
cout
-
8/22/2019 First Day Orientation
52/86
Entering different data types// This program demonstrates how cin can read multiple values
// of different data types.
#include
using namespace std;
int main()
{int whole;
double fractional;
char letter;
cout > whole >> fractional >> letter;
cout
-
8/22/2019 First Day Orientation
53/86
Reading Strings
cin can read more than one character and store
it in memory as a character array, or C-string
char company[12]
Note: A larger string entered will overflow the
arrays boundaries and destroy data in memory!
Char
TypeName
Number
indicates thesize of the array
-
8/22/2019 First Day Orientation
54/86
// This program demonstrates how cin can read a string into
// a character array.
#include
using namespace std;
int main()
{
char name[21];
cout > name;
cout
-
8/22/2019 First Day Orientation
55/86
// This program reads two strings into two character
arrays.
#include
using namespace std;
int main(){
char first[16], last[16];
cout first >> last;
cout
-
8/22/2019 First Day Orientation
56/86
Mathematical Expressions
C++ allows you to construct complex
mathematical expressions using multiple
operators and grouping symbols
Expression: statement that has a value
Example: sum = 21 + 3;
Num = 4;
Result = x;
Result = 15 / 3;
Result = a + b + c;
// This program asks the user to enter the numerator
-
8/22/2019 First Day Orientation
57/86
// This program asks the user to enter the numerator
// and denominator of a fraction and it displays the
// decimal value.
#include using namespace std;
int main()
{
double numerator, denominator;
cout denominator;
cout
-
8/22/2019 First Day Orientation
58/86
Operator Precedence
PMDAMS!1. Parentheses
2. Multiplication
3. Division4. Addition
5. Modulus
6. Subtraction Examples
5 + 2 * 4 = ?
10 / 2 -3 = ?
8 + 12 * 2 4 = ?
4 + 17 % 2 1 = ?
6 3 * 2 + 7 1 = ?
-
8/22/2019 First Day Orientation
59/86
Associativity and Grouping
Either left to right or right to left
If two operators sharing an operand have
the same precedence, they work
according to their associativity
* / % + - (left to right)
Unary negation (right to left)
You can use () to group operations andforce their precedence
Result = (a + b) / 4;
Converting Algebraic Expressions to
-
8/22/2019 First Day Orientation
60/86
g g p
Programming Statements
Examples
6B 6 * B
(3)(12) 3 * 12
4xy 4 * x * y;
Insert parentheses where necessary
x = (a + b) / c;
Using exponents y = pow(x,2);
This statement callspow , with arguments x and 2
c
bax
2xy
// This program calculates the area of a circle.
-
8/22/2019 First Day Orientation
61/86
p g
// The formula for the area of a circle is Pi times
// the radius squared. Pi is 3.14159.
#include
#include // needed for pow functionusing namespace std;
int main()
{
double area, radius;
cout radius;
area = 3.14159 * pow(radius, 2.0);
cout
-
8/22/2019 First Day Orientation
62/86
When you mix apples and
oranges: Type Conversion When an operators operands are different
data types, C++ will automatically convert
to the same data type, affecting the results
Depends on Ranking and Rules
-
8/22/2019 First Day Orientation
63/86
Rules
1. chars, shorts, and unsigned shorts are
automatically converted to int
2. when an operator works with two values
of different data types, the lower rankingvalue is promoted to the type of the
higher-ranking value
3. when the final value of an expression isassigned to a variable, it will be converted
to the data type of the variable
-
8/22/2019 First Day Orientation
64/86
Overflow and Underflow
When a variable is assigned a value that is
too large or too small in range for that
variables data type, the variable overflows
or underflows
// This program demonstrates integer overflow and underflow
-
8/22/2019 First Day Orientation
65/86
// This program demonstrates integer overflow and underflow.
#include
using namespace std;
int main(){
// testVar is initialized with the maximum value for a short.
short testVar = 32767;
// Display testVar.cout
-
8/22/2019 First Day Orientation
66/86
// This program can be used to see how your system handles
// floating point overflow and underflow.
#include using namespace std;
int main()
{
float test;
test = 2.0e38 * 1000; // Should overflow test.
cout
-
8/22/2019 First Day Orientation
67/86
Type Casting
Type castingallows for manual data type
conversion
General format
static_cast(Value)
Example
Double number = 3.7;
int val; val = static_cast(number);
//
-
8/22/2019 First Day Orientation
68/86
// This program uses a type cast to avoid integer division.
#include
using namespace std;
int main()
{
int books; // Number of books to read
int months; // Number of months spent reading
double perMonth; // Average number of books per month
cout > books;
cout > months;
perMonth = static_cast(books) / months;cout
-
8/22/2019 First Day Orientation
69/86
// This program uses a type cast expression to print a
character
// from a number.
#include
using namespace std;
int main()
{
int number = 65;
// Display the value of the number variable.
cout
-
8/22/2019 First Day Orientation
70/86
Named Constants
Literals may be given names that
symbolically represent them in a program
Example: PI
const double PI = 3.1459;
-
8/22/2019 First Day Orientation
71/86
// This program calculates the area of a circle.
// The formula for the area of a circle is PI times
// the radius squared. PI is 3.14159.
#include #include // needed for pow function
using namespace std;
int main()
{const double PI = 3.14159;
double area, radius;
cout radius;
area = PI * pow(radius, 2.0);
cout
-
8/22/2019 First Day Orientation
72/86
Lecture 3d: Expressions and
InteractivityCS126
Engr. J. Cansino
Multiple Assignment and
-
8/22/2019 First Day Orientation
73/86
Multiple Assignment and
Combined Assignment Multiple assignment: assign the same
value to several variables with one
statement
example: a = b = c = d = 12;
Combined assignment:
number = number + 1;
New
Value
Old
Value
// This program tracks the inventory of three widget stores
-
8/22/2019 First Day Orientation
74/86
// that opened at the same time. Each store started with
the
// same number of widgets in inventory. By subtracting the
// number of widgets each store has sold from its
inventory,
// the current inventory can be calculated.
#include using namespace std;
int main()
{
int begInv, // Begining inventory for all stores
sold, // Number of widgets sold
store1, // Store 1's inventory
store2, // Store 2's inventory
store3; // Store 3's inventory
// Get the beginning inventory for all the stores.
cout sold;
store2 -= sold; // Adjust store 2's inventory.
// Get the number of widgets sold at store 3.
cout > sold;
store3 -= sold; // Adjust store 3's inventory.
// Display each store's current inventory.
cout
-
8/22/2019 First Day Orientation
75/86
Formatting Output
More on output stream manipulation
The way a value is printed is called its
formatting
set(w): sets the field width (in characters)
for the value immediately following it
Requires: #include
Larger numbers will be fully printed
// This program displays three rows of numbers.
-
8/22/2019 First Day Orientation
76/86
#include
using namespace std;
int main(){
int num1 = 2897, num2 = 5, num3 = 837,
num4 = 34, num5 = 7, num6 = 1623,
num7 = 390, num8 = 3456, num9 = 12;
// Display the first row of numbers
cout
-
8/22/2019 First Day Orientation
77/86
setprecision: floating point numbers are rounded
setprecision(n)
fixed
Setprecision sometimes does not give you what youwant, use fixed to force cout to print the digits in fixed-
point notation or decimal
showpoint
Shows trailing zeros (not shown by default)
left and right manipulators
left right justification
// This program asks for sales figures for 3 days. The total
// sales are calculated and displayed in a table.
-
8/22/2019 First Day Orientation
78/86
p y
#include
#include
using namespace std;
int main()
{double day1, day2, day3, total;
// Get the sales for each day.
cout > day1;
cout > day2;
cout > day3;
// Calculate the total sales.
total = day1 + day2 + day3;
// Display the sales figures.
cout
-
8/22/2019 First Day Orientation
79/86
Formatted Input
cin provides ways of controlling string andcharacter input
Similar to those of cout
setw(10): prevents buffer overrun by limiting
number of characters
cin.getline()
char sentence[81]; cin.getline(sentence,20);
cin.get()
Gets a single character, including spaces or the
return character
-
8/22/2019 First Day Orientation
80/86
Mixing cin and cin.get
use cin.ignore(n,c)
n: number of characters to skip
c: character encountered
Which ever comes first
Member functions
getline, get, ignore are all examples of cins
member functions or procedures that are part of
cin cin is an object
Introduction to File Input and
-
8/22/2019 First Day Orientation
81/86
Introduction to File Input and
Output
Simple techniques to write input andoutput operations with files
#include ;
Define filesream objects
ofstream output to files
Ifstream input from files
Fstream w/r to and from files
M M th Lib F ti
-
8/22/2019 First Day Orientation
82/86
More Math Library Functions
// This program writes data to a file.
#include
-
8/22/2019 First Day Orientation
83/86
#include
using namespace std;
int main(){
ofstream outputFile;
outputFile.open("demofile.txt");
cout
-
8/22/2019 First Day Orientation
84/86
#include
using namespace std;
int main()
{
ifstream inFile;const int SIZE = 81;
char name[SIZE];
inFile.open("demofile.txt");
cout > name; // Read name 1 from the filecout name; // Read name 2 from the file
cout name; // Read name 3 from the file
cout name; // Read name 4 from the file
cout
-
8/22/2019 First Day Orientation
85/86
using namespace std;
int main()
{
ifstream inFile;
int length, width, area;
inFile.open("dimensions.txt");
cout > length;inFile >> width;
area = length * width;
cout > width;
area = length * width;
cout > width;
area = length * width;
cout > width;
area = length * width;
cout > width;
area = length * width;
cout
-
8/22/2019 First Day Orientation
86/86