CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.

Slides:



Advertisements
Similar presentations
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.
Advertisements

This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
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,
CPS120: Introduction to Computer Science INPUT/OUTPUT.
CSC Programming for Science Lecture 5: Actual Programming.
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
CS Sept Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
CS150 Introduction to Computer Science 1
Basic Elements of C++ Chapter 2.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
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.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Input & Output: Console
CSC 107 – Programming For Science. Announcements.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
C Programming Lecture 4 : Variables , Data Types
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++ (4)
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Using Data.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
Fundamental Programming: Fundamental Programming Introduction to C++
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
CSC 107 – Programming For Science. The Week’s Goal.
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.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
PHY 107 – Programming For Science. The Week’s Goal.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
CSC 107 – Programming For Science. Today’s Goal  Know how to write selections besides if-else  When each of the options makes sense  When each selection.
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
CSC 107 – Programming For Science. Today’s Goal  Get familiar with opening & closing files  Declaring variables for use with files  Using variables.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter Topics The Basics of a C++ Program Data Types
Basics (Variables, Assignments, I/O)
Chapter 1.2 Introduction to C++ Programming
Programming Fundamentals
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Computing Fundamentals
Basic Elements of C++.
Introduction to C++ October 2, 2017.
OUTPUT STATEMENTS GC 201.
Basic Elements of C++ Chapter 2.
Basics (Variables, Assignments, I/O)
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Fundamental Programming
What Actions Do We Have Part 1
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

CSC 107 – Programming For Science

Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead use your resources: notes, books, slides, etc.  Figured out problem using Eclipse in labs  Easy to work around problem via several options  Bringing thumbdrive easiest, but is not required  During the day, tutors available in WTC 206/208  Weekly assignment #2 posted to Angel

Variables, Constants, & More General CasesExamples Variable Declaration dataType name; dataType name = value; dataType name(value); dataType name, anotherName; dataType name = value, anotherName; int count; bool monkey = true; float avg(10.0); char help,letter; char a=‘a’,letter; Constant Declaration const dataType name = value; const double PI=3.1; Symbolic Constant #define NAME value #define AGE 34

Data Types  Each variable also has data type  How program treats variable’s value defined by this  Single true or false value held by bool  C/C++ defines 7 numeric data types  Integer types: short, int, long, long long  Decimal types: float, double, long double  char data type can hold a character

Data Types  Each numeric data type can be one of 2 types  Signed (both positive & negative) version is default  If data must be non-negative use unsigned _____  Upper range of variable is doubled  Warned when using signed & unsigned together  Only certain assignments allowed in system  Can assign an integer to a decimal variable  Error assigning decimal to integer variable, since its hard

Program Outline  Once upon a time…  … some stuff happens…  … and they all lived happily ever after

Program Outline  Once upon a time…  All programs must begin somewhere  Defines what is worked upon during rest of program  For non-trivial programs, requires receiving input  When starting program, first steps always same: 1. What is the input? 2. What will the input look like? 3. How will the data be entered?

Reading From The Keyboard  Easiest to get input from the keyboard  Reading from files possible; discussed later in term  C++ lacks standard, so writing GUI much harder  C++ defines cin to get user’s input  As easy to use as delivering food to Granny’s house  When cin hit, program waits until it has input  User must press enter for line to be able to be read  Editing not seen by program; only receives final line

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

cin Example >>

cin Example >>

cin Example >>

Program Outline  Once upon a time…  Get the input using cin from the keyboard  … some stuff happens…  … and they all lived happily ever after

Some Stuff Happens  This really depends on specific project details  Focus of most of term, we will skip this today

Program Outline  … and they all lived happily ever after  All good processing comes to end & report results  Shows program worked and provides feedback  Results takes many forms, focus on printing today  When starting program, second steps ask: 1. What must be output? 2. How can output be presented best? 3. Will it be pretty?

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  Use escape sequences for fancier text output \n  newline (move to start of next line) \t  tab (go to next column that is multiple of 8) \\  \ (backslash character) \”  “ (quotation mark)

Can Print Out Multiple Items  cout can also print out value of variables int bob = 2; double j = 4.5; char var = ‘a’; cout << “Hello ”; cout << bob << endl; cout << j << endl; cout << var << endl; cout << j << “ is not ” << bob << endl; cout << bob << “ equals bob” << endl; cout << var << bob << j << endl;

But Can It Be Used?  cout built to provide basics needed to work  Prints out as many digits as needed  No extra spaces or tabs used  Scientific notation cannot be used  Often want to format results  Significant digits can matter  Tables make reading faster

Real World Strikes Again TrollPrincess

First Way To Format Output #include using namespace std; int main() { int k = 4; cout << k << endl; cout.width(4); cout << k << endl; cout << k << endl; cout.setf(ios::showpos); cout << k << endl; cout.width(3); cout.setf(ios::left); cout << k << k << endl; }

Second Way To Format Output #include #include using namespace std; int main() { int k = 4; cout << k << endl; cout << setw(4) << k << endl; cout << k << endl; cout.setf(ios::showpos); cout << k << endl; cout.setf(ios::left); cout << setw(3) << k << k << endl; }

Your Turn  Get in groups of 3 & work on following activity

For Next Lecture  Read sections 6.1 – 6.7 for Friday  How can we use the variables?  What operations exist for us to use?  What do we mean by order of operations?  Week #2 weekly assignment due Tuesday  Problems available on Angel  If problem takes more than 10 minutes, TALK TO ME!