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,

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 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.
Getting Data into Your Program
Using MatLab and Excel to Solve Building Energy Simulation Problems Jordan Clark
© 2000 Scott S Albert Structured Programming 256 Chapter 7 Streams and File I/O.
CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
Computer Science 1620 Loops.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
Lecture 18:Topic: I/O Formatting and Files Dale/Weems/Headington
CSC 110 – Intro to Computing Lecture 14: Midterm Review.
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.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.
CS 117 Spring 2002 Using Files Hanly: Chapter 9, some in Chapter 4 Freidman-Koffman: Chapter 8, iomanip in Chapter 5.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
Computer Science: A Structured Programming Approach Using C1 3-7 Sample Programs This section contains several programs that you should study for programming.
CSC 107 – Programming For Science. Science Means Solving Problems  Physics – How does an atom work?
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.
Prof. Matthew Hertz SH 1029F /
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
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 /
Introduction to PASS, and Exercises on Operators and Basic I/O.
Dividing Polynomials  Depends on the situation.  Situation I: Polynomial Monomial  Solution is to divide each term in the numerator by the monomial.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
Binary Values and Number Systems
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.
Prof. Matthew Hertz WTC 207D /
CSC 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with C++ I/O Basics.
CSC 107 – Programming For Science. Announcements.
PHY 107 – Programming For Science. Positional Notation  Used in nearly all modern numerical systems  Right-to-left ordering of digits within larger.
Chapter 3 Working with Batches of Data. Objectives Understand vector class and how it can be used to collect, store and manipulate data. Become familiar.
Scientific Notation N SPI Use scientific notation to compute products and quotients.
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
Streams One of the themes of this course is that everything can be reduced to simple (and similiar) concepts. Streams are one example. Keyboard and Screen.
Program Input and the Software Design Process ROBERT REAVES.
Input/Output. Objectives In this chapter you will: Learn what a stream is and examine input and output streams Explore how to use the input stream functions.
CSC Programming for Science Lecture 37 : Course Review.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
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.
PHY 107 – Programming For Science. Final Exam  Wed., Dec. 16 th from 2:45PM – 4:45PM in OM110  For exam, plan on using full 2 hours  If major problem,
Input, Output and Variables GCSE Computer Science – Python.
CHAPTER 18 Circuits for Arithmetic Operations
Convert Decimal to Binary
File I/O.
Applying Exponent Rules: Scientific Notation
Final Exam Wednesday, 12/14, 5:00-7:00
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.
Chapter 3: Input/Output
File I/O in C++ I.
Multiplying and Dividing in Scientific Notation
Dividing a whole number to get decimal
Dividing a decimal by a whole number
CS 101 First Exam Review.
Review for Midterm Spring 2019
Dale/Weems/Headington Program Input and the Software Design Process
Finding Equations of Exponential Function
Scientific Notation N SPI Use scientific notation to compute products and quotients.
Do not use a calculator for the following!!.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
File I/O in C++ I.
Division Vocabulary Review.
Function Notation.
Presentation transcript:

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, come talk to me ASAP  Exam covers material from entire semester  Open-book & open-note so bring what you’ve got  My handouts, solutions, & computers are not allowed  Cannot collaborate with a neighbor on the exam  Problems will be in a similar style to 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

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 argument’s 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) assignment (=)  NOT the same as assignment (=)

NOT Gate  Simplest gate: computes opposite of input  Output false when input true  Output true when input false !a  Written in C++ as !a ("bang a")  a is gate’s input a !a!a!a!a true false 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 a || b  Written in C++ as a || b  a & b are inputs ab a || b false true false true 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 a && b  Written in C++ as a && b  a & b are inputs ab a && b false true false true a b

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

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

“Subtle” Hint

For Final  You can use on this final:  Your textbook & notes  At the same time, you may NOT use:  Computer, calculator, cell phone, or similar  Copies of daily activities and/or solutions  Friends, Romans, countrymen or their ears

How to Prepare for Midterm DODON'T  Redo activities, labs, weekly…  Make cheat sheets for the test  Review how parts of C/C++work  Assume notes replace studying  Ever, ever invade Russia in winter  Assume you'll pass cause you're cute

How to Prepare for Midterm DODON'T  Redo activities, labs, weekly…  Make cheat sheets for the test  Review how parts of C/C++work  Assume notes replace studying  Ever, ever invade Russia in winter  Assume you'll pass cause you're cute

How to Prepare for Midterm DODON'T  Redo activities, labs, weekly…  Make cheat sheets for the test  Review how parts of C/C++work  Add post-its to important pages  Assume notes replace studying  Ever, ever invade Russia in winter  Drink case of 40s before test  Use post-its as clothing

Final Exam Schedule  Lab Mastery Exam is: Tues., Dec. 11 th 2:45PM – 3:45PM in SH1008  Final Exam is: Fri., Dec. 14 th from 12:30PM – 2:30PM in SH1028