CSC 107 – Programming For Science. Final Exam Thurs., Dec. 10 th from 8AM – 10AM in OM 221 For exam, plan on using full 2 hours If major problem, come.

Slides:



Advertisements
Similar presentations
Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
Advertisements

(CSC 102) Discrete Structures Lecture 5.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
CSC 107 – Programming For Science. Final Exam  Fri., Dec. 14 th from 12:30PM – 2:30PM in SH1028  For exam, plan on using full 2 hours  If major problem,
CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
Computer Science 1620 Loops.
CSC 110 – Intro to Computing Lecture 14: Midterm Review.
A review of concepts and computational skills Chapters 1-2
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
C++ plus. 2 Goals Some general C++ tips 3 C++ Tips is header file for a library that defines three stream objects Keyboard an istream object named cin.
2.1 – Linear Equations in One Variable
Computer Programming Skills Revision Prepared by: Ghader Kurdi.
Section 1.1 Numbers and Their Properties.
CS231 Fundamentals1 Fundamentals What kind of data do computers work with? – Deep down inside, it’s all 1s and 0s What can you do with 1s and 0s? – Boolean.
CSC 107 – Programming For Science. Today’s Goal ALL  Understand why ALL I/O is file I/O  Common bugs to avoid when coding with files in C++  Get a.
CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Test #1 rescheduled to next Tuesday, 09/20/05 The contents will cover chapter 1, 2, and part of Chapter 4. The contents will cover chapter 1, 2, and part.
Binary Numbers.
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
CSC 107 – Programming For Science. Follow-Up From Last Lecture.
Week 4. Due for this week…  Homework 4 (on MyMathLab – via the Materials Link)  Monday night at 6pm.  Prepare for the final (available tonight 10pm.
Prof. Matthew Hertz WTC 207D /
CSC Intro. to Computing Lecture 5: Boolean Logic, Gates, & Circuits.
Today we will review “Multiplying & Dividing Decimals”
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
1 Boolean Logic & Number Systems Today: Some Announcements First Hour: Introduction to Logic –Section 1.2, 1.3 of Katz’s Textbook –In-class Activity #1.
Semester Review. As we have discussed, Friday we will have in class time for you to work on a program, this program will come with instructions and you.
Binary Values and Number Systems
PERCENTS. WHAT ARE PERCENTS?  We’ve done lots of work with fractions and decimals. We’ve determined that fractions that denominators of 100 are useful.
CSC 107 – Programming For Science. Announcements.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
Prof. Matthew Hertz WTC 207D /
CSC 107 – Programming For Science. The Week’s Goal.
CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.
CSC 107 – Programming For Science. Announcements.
June 10, 2002© Howard Huang1 Number systems To get started, we’ll discuss one of the fundamental concepts underlying digital computer design:
PHY 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
CSC 107 – Programming For Science. Today’s Goal  Get familiar with opening & closing files  Declaring variables for use with files  Using variables.
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
CSC 107 – Programming For Science. Final Exams Dec. 16, 8AM – 10AM in OM221  Exam for CSC107: Dec. 16, 8AM – 10AM in OM221  Will be done using paper.
Figure 5–5 Exclusive-OR logic diagram and symbols. Open file F05-05 to verify the operation. Thomas L. Floyd Digital Fundamentals, 9e Copyright ©2006 by.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.
1 Stream Input and Output Read Text, page Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) KeyboardScreen executing.
LOGIC CIRCUITLOGIC CIRCUIT. Goal To understand how digital a computer can work, at the lowest level. To understand what is possible and the limitations.
Input, Output and Variables GCSE Computer Science – Python.
EET 1131 Unit 5 Boolean Algebra and Reduction Techniques
Data Types and Expressions
Introduction to Real Numbers and Algebraic Expressions
Logic Gates.
What is a File? A file is a collection on information, usually stored on a computer’s disk. Information can be saved to files and then later reused.
Convert Decimal to Binary
CMSC201 Computer Science I for Majors Lecture 03 – Operators
File I/O.
Computer Science 210 Computer Organization
Text Files All the programs you've seen so far have one thing in common: Any data the program uses or calculates is lost when the program ends. In order.
Logic Gates.
Dividing Decimals by Whole Numbers
SSEA Computer Science: Track A
Function Notation.
Presentation transcript:

CSC 107 – Programming For Science

Final Exam Thurs., Dec. 10 th from 8AM – 10AM in OM 221 For exam, plan on using full 2 hours If major problem, come talk to me ASAP Exam covers material from entire semester Open-book & open-note so bring what youve got My handouts, solutions, & computers are not allowed Cannot collaborate with a neighbor on the exam Problems will be in a similar style to 2 midterms

Positional Notation To convert d n... d 3 d 2 d 1 d 0 into decimal: From base-b d 0 * b 0 d 1 * b 1 d 2 * b 2 d 3 * b 3 … + d n * b n

Converting Decimal To Base-b General way to convert from decimal to base-b: While decimal number 0 Divide decimal number by b Move remainder to left end of answer Replace decimal number with quotient

NOT Gate Simplest gate: computes opposite of input Output false when input true; Output true when input false; Written in C++ as !a a is gates input !a is functions output a!a!a true false a !a!a

OR Gate Equivalent to addition in Boolean algebra If either input is true is going to be checked True when either a OR b are true; false otherwise Written in C++ as a || b a & b are inputs; a || b is output ab a || b false true false true a b a || b

AND Gate Equivalent to multiplication in Boolean algebra If both inputs are true is going to be checked True when a AND b are true; false otherwise Written in C++ as a && b a & b are inputs; a && b is output aba && b false true false true a b a && b

Monkeys!

Programming Using cin Used to read one or more values at once: cin >> variable ; cin >> variable1 >> variable2 ; Reads where last cin stopped reading input Automatically skips past whitespace Data type of variable determines what is read Stops reading at first non-usable value in input If input is not usable, will set variable equal to 0

Using cout to Print Already seen how to print text using cout cout << Hello World << endl; Prints out whatever is placed between quotes endl goes to next line and prints out immediately Can format output in variety of ways Print numbers to preset level of precision Use fixed format versus which ever makes sense

Priority of Operations Equations can become very complex * 6 * = …? Very Very strict order of operations used by computer ( ) Solve from inner- to outermost + (positive) & - (negative) Solve from right to left * & % & / (division) Solve from left to right + (addition) & - (subtraction) Solve from left to right use lots of parentheses My suggestion: use lots of parentheses

Compound Assignment Operators Short simple operators that allow us to be lazy Save some typing for several common actions Lowest priority operation; expression evaluated first OperatorEquivalent C++ Expression a += 2;a = a + 2;a = a + 2; b -= d;b = b – d;b = b – d; c *= ;c = c * ( ); d /= 0.3 * e;d = d / (0.3 * e);

Mathematical Functions Add #include at top of file All these functions return a value Will NOT change arguments value sin( x ), cos( x ), tan( x ), asin( x ), atan( x ), log10( x ), sqrt( x ), log( x ), exp( x ), pow( x, y ), floor( x ), ceil( x )

Relational Operators < ( less than) > ( greater than) <= ( less than of equal to) >= ( greater than of equal to) != ( inequality ) == ( equality – if two things have same value) NOT the same as assignment (=) NOT the same as assignment (=)

if (…) statement First evaluates expression in parenthesis Add opening brace ( { ) after closing parenthesis Can now write all statements to execute Add closing brace ( } ) to show where if ends If expression false, execution restarts at that point If expression is true, executes code in block Skips over block, when expression is false

if – else if – else Usage Must begin with if statement at the start This is required; what would we be saying else to? Only Only required part of this entire process Can then have zero or more else if s Tests can be anything; do not have to be related Until one is true, will be examined one-by-one Execute 1 st clause where true expression is found Only at the very end can have else clause If nothing else matches then else is executed

Executing switch Statement 1. Evaluates expression 2. Finds matching case or default (if it exists) If no default, may not have match - skips switch 3. Execution starts at 1 st matching label Execution will continue until break; found Will continue into next case if break; is not hit 4. Restarts running after switch once break hit May reach end of switch without a break Continues running code after switch

while Loop while (expression) { statement;... } Evaluates expression to find its value If true, executes entire loop body Re-check after each pass through loop, only Continue with loop while expression checks true

for Loop

Function Definition

return Statement

More Monkeys

Declaring Arrays

String Theory!

Program Basics For Files All built-in file I/O code means adding to header #include #include Place with other #include s to use files in program Even if no files are used, no cost to adding this line Must specify namespace of file I/O code, also If you really want, this can be done individual but… using namespace std; much easier and probably habit by now anyway

Opening a File Within program, may use file in 2 possible ways To read file, ifstream variables will be needed Need variable of type ofstream to write to file Open ofstream 2 different ways depending on use ofstream nukeIt("byebye.txt"); ofstream begone; begone.open("erasedOld.dat"); ofstream keepIt("saved", ios::app); ofstream faithAlone; faithAlone.open("preserve", ios::app); 3

Read File W/ ifstream Variable Used to read one or more values at once: ifstream myFile; myFile >> variable ; myFile >> variable1 >> variable2 ; Starts where last read stopped reading input Automatically skips past whitespace Data type of variable determines what is read Stops at first non-usable value found in the input If input is not usable, will set variable equal to 0

Print to File With ostream Easy to output: output via ostream variable ofstream outFile; outFile << Hello World << endl; Prints out whatever is placed between quotes Value of variable printed if variable not in quotes

Declaring an Pointer

& and * Operators variable & operator gets the address of a variable Used only with variables Used only with variables, including array elements Types must match, no automatic promotion possible Pointers to pointers okay, but needs to be type ** Follow the pointer to get value at location with * Only used with pointers, as * could also be multiply double x, *y = &x; int *a, *b = &a; float *c = a, d = *a;

Pointers versus Arrays Both types of variables store an address Can be assigned to one another if types match To access value, can either use * or [ index ] *p same as p[0] - they are "synonyms" in C++ Arithmetic works similarly - *(p+5) same as p[5] Do not get carried away exploiting this idea Unlike arrays, memory not reserved for pointer Arrays not used to alias other variables (usually)

Using struct s variables Can assign struct variables to one another Variables must be of identical struct types Copies value of all fields but still remain independent Locations will be same, since pointers & arrays aliased In all other situation, must use fields Cannot add, multiply, compare struct variables For any legal use, individual fields always available Arrays of struct s can also be declared Within the array, each entry is struct variable

And Finally…

And Finally Monkees

Subtle Hint

Final Exam Schedule Lab Mastery Exam is: Tues., Dec. 8 th from 9AM – 10AM in OM 115 Final Exam is: Thurs., Dec. 10 th from 8AM – 10AM in OM 221