CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

C Language.
CSC 213 – Large Scale Programming. Today’s Goals  Look at how Dictionary s used in real world  Where this would occur & why they are used there  In.
1 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Programming Introduction to C++.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
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.
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
CSC 107 – Programming For Science. Announcements.
CSC 107 – Programming For Science. Announcements  Tutors available MTWR in WTC206/WTC208  Special lab (with Macs) & not in the Tutoring Center  Can.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing & using functions  How to declare them, use them, & trace them  Could write programs.
CSC 107 – Programming For Science. Spacing in a Program  C++ ignores spaces in a program  This also means where newlines placed ignored  #define &
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Problem of the Day  Why are manhole covers round?
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
CIT 590 Intro to Programming First lecture on Java.
PHY 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Problem of the Day  Why are manhole covers round?
CSC 107 – Programming For Science. Today’s Goal  Discuss how to hand data to functions  Review loopholes in variables & scoping rules  Ways to get.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
CSC 107 – Programming For Science. Announcements.
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
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.
CSC 107 – Programming For Science. Today’s Goal  When lecture over, start understanding pointers  What a pointer is and what it is not  Why pointers.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
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.
CSC 107 – Programming For Science. Announcements  Locations of Macs to use outside of lab time  Can find on Library ground floor (6) & main floor (6)
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  While at Bell Labs, created language to develop Unix 
CSC 107 – Programming For Science. Announcement Today’s Goal  Know how to write selections besides if-else  Why we use select or if - else and how.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
CSC 107 – Programming For Science. Announcements.
CSC Programming for Science Lecture 4: Beginning Programming.
CSC Programming for Science Lecture 10: Boolean Expressions & More If ­ Else Statements.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.
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.
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
CSC Programming for Science Lecture 37 : Course Review.
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.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
Problem of the Day  Why are manhole covers round?
CSC 107 – Programming For Science. Today’s Goal  Write functions that take & return values  How parameters declared and how we call functions  What.
CSC Programming for Science Lecture 5: Actual Programming.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
User-Written Functions
Getting Started with C.
Functions Inputs Output
Introduction to C++ Programming
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Programming Introduction to C++.
Presentation transcript:

CSC 107 – Programming For Science

History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation, language grown organically  Tradition of adding features beyond standard as desired

History of C++  Bjarne Stroustrup created to add “objects”  Also included many other improvements to language  Name is inside joke: "++" is increment operator in C  Updated for quick growth  ISO standard adopted in 1998  Recently updated to C x

C Versus C++ C++ is designed to be as compatible with C as possible, thereby providing a smooth transition from C

C Versus C++ C++ C

C Versus C++ C

 Latest definition of C added most C++ features  Not classes & objects, these only found in C++  For this reason, also not a part of CSC 107  Differences now minimal and easily avoided  Once objects removed, C++ just “looser” C  Removes annoying restrictions that had been in C  Since makes life easier, often supported in C anyway

Case-Sensitivity  Example of computers being very literal  And language not helping by fixing what you say  main, Main, & MAiN treated as totally different  Case of the letters matters, not just the words  Might want difference; C++ won’t change Main to main  Can help prevent easy mistakes from swapping names  With just a little practice, becomes second nature

“Whitespace”  One (very small) way C++ actually helps you  C++ treats whitespace equally – spaces, enters, & tabs  Whether 1 or – all will be ignored  Cannot use in symbol, whitespace splits words  Treats these as different “ : : ” and “ :: ”  Spaces between words needed, but not counted  Wecansplitwordsbutthecomputercannot

“Whitespace”  One (very small) way C++ actually helps you  C++ treats whitespace equally – spaces, enters, & tabs  Whether 1 or – all will be ignored  Cannot use in symbol, whitespace splits words  Treats these as different “ : : ” and “ :: ”  Spaces between words needed, but not counted  Wecansplitwordsbutthecomputercannot

Your First C++ Program #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }

#include Statements #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }  Nearly every C++ file begins with this directive  May add more #include to include other files  Contents of included file usable as if it were here  Easy way to copy ideas across multiple files  Programs can use two types of #include statements  Include system file using #include  #include “ filename ” includes a file you wrote

Watch Me Pull a Rabbit #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }  For now, automatically start each file with this line  Details are unimportant – consider it magic

Watch Me Pull a Rabbit #include using std::cout; /* Hi, Mom. This is a comment that goes over 2 line. */ int main() { std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }  For now, automatically start each file with this line  Details are unimportant – consider it magic

Your First C++ Program #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }

main Function #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }  All C++ programs contain function called main  Tells computer where to start running program  Code inside the braces will be what is executed  For the moment, consider this more “magic”

main Function #include using std::cout; int main() { /* Hi, Mom. This is a comment that goes over 2 line. */ std::cout << “Hello world!”; return 0; // This comment goes to the line’s end }  All C++ programs contain function called main  Tells computer where to start running program  Code inside the braces will be what is executed  For the moment, consider this more “magic”

Comments  Vital  Vital for writing and maintaining any program  Not required to run program - only for human eyes  Computer simply ignores anything in a comment  Use to describe code in simple English  Sie konnen auch auf Deutsch schreiben  o U c%d wrte n txt msg  Should be used liberally  I add comments where cannot see what code does  Impossible to have too many comments, if readable

Comments in C++  Double slash comments continue to line’s end a = a – 4; // Hi, Mom! // This entire line is a comment!  /* … */ comments can be on one or more lines a = a - /* Hi, Mom! */ 4; /* This comment takes an entire line. */ /* This is a really long comment that * goes on to multiple lines. The stars on * lines 2 and on are optional, but * makes things easier to read. */

Your Turn  Get in groups & work on following activity

For Next Lecture  Read sections 4.1 – 4.10 in book for Friday  What is a data type?  What are variables?  How can we use variables in a program?  How are literal, constant, & variable different?  Week #1 weekly assignment due Tuesday  Problems available via Angel – covered 1 st one already  If problem takes more than 10 minutes, TALK TO ME!