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)

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

C Language.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
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.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Programming Introduction to C++.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter 3 Getting Started with C++
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.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
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.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
Problem of the Day  Why are manhole covers round?
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,
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. The Week’s Goal.
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.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Chapter 2 part #1 C++ Program Structure
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.
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.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
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.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
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.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Lecture 3: Getting Started & Input / Output (I/O)
User-Written Functions
Chapter 2 part #1 C++ Program Structure
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Separate Compilation and Namespaces
Programming 1 (CS112) Dr. Mohamed Mostafa Zayed 1.
Introduction to C++ Programming
Programming Introduction to C++.
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Week 1 - Friday COMP 1600.
Presentation transcript:

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)  Palisano Pavilion Computer Lab in the basement(?)  Get out and meet people; many dorms have Mac labs

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

 Computers have no common-sense do what you tell them to do  They will only do what you tell them to do  NOT what you want them to do  NOT what you want them to do, which often differs

Case-Sensitivity  Example of computers being very literal  And language not helping by fixing what you say  main, Main, & MAiN treated as different words  Case of the letters matters, not just the words  Could be different, so 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 }

Using Commands #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 }  More “magic”, but using has less important purpose  Tells compiler we are lazy & save some typing  Two types of using statements to choose from  Specify single shortcut with using std::cout  using namespace std; to get all std shortcuts  Unlike #include statements, using never required  Do not worry about it – will not be using them

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 screiben  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 on Angel – covered 1 st two already  If problem takes more than 10 minutes, TALK TO ME!