12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,

Slides:



Advertisements
Similar presentations
Introducing C++ Elements. CSCE 1062 Outline Main algorithms’ constructs General form of a C++ program {section 2.5} C++ language elements {section 2.1}
Advertisements

What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Structure of a C program
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.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
CS150 Introduction to Computer Science 1
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
COMPUTER SCIENCE I C++ INTRODUCTION
By Dr. Awad Khalil Computer Science & Engineering Department
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Chapter 2 Overview of C++ Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville, PA
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Overview of C++ Chapter C++ Language Elements t Comments make a program easier to understand t // Used to signify a comment on a single line.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamental Programming: Fundamental Programming Introduction to C++
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
ICS103 Programming in C Lecture 3: Introduction to C (2)
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Chapter 2: Overview of C++
Presentation transcript:

12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments, lab notes will be available on this site in two forms:  Microsoft PowerPoint or Word  PDF (Acrobat Reader)

22/14/2016CS150 Introduction to Computer Science 1 //Program purpose: converts distance in miles to kilometers //Author: Friedman & Koffman //Date: August 30, 2000 #include int main() { using namespace std; const float KM_PER_MILE = 1.609; float miles, kms; //Get the distance in miles cout << “Enter the distance in miles” << endl; cin >> miles; //Convert the distance to kilometers kms = KM_PER_MILE*miles; //Display the distance in kilometers cout << “The distance in kilometers is” << kms << endl; } Implementation

32/14/2016CS150 Introduction to Computer Science 1 C++ Language Elements  Comments are  how you explain in English what your program does  Ignored by the compiler  Very, very, very important  Format of comments: //comment /* comment */

42/14/2016CS150 Introduction to Computer Science 1 Compiler directives  #include  # signifies compiler directive  Processed BEFORE program translation  #include tells the compiler to look for libraries  <> signifies part of standard C++ libraries  We’ll see other examples later of compiler directives

52/14/2016CS150 Introduction to Computer Science 1 Namespace std  using namespace std;  Indicates that we will be using objects that are named in a region called namespace std.  The statement ends in a semicolon.  The statement appears in all our programs.

62/14/2016CS150 Introduction to Computer Science 1 Main function definition int main( ) { main program }  Your main program is where execution starts.  Every program has one!

72/14/2016CS150 Introduction to Computer Science 1 Program statements  Declaration Statements  What data is needed by the program?  const float KM_PER_MILE = 1.609;  float miles, kms;  Executable Statements  Everything else  Examples: cout, cin Assignment  All end with semicolon ;

82/14/2016CS150 Introduction to Computer Science 1 Identifiers  Names used in program  Examples:  Variables  Functions  Rules:  Begin with letter or underscore  Consist of letters, digits and underscore  Cannot use reserved word

92/14/2016CS150 Introduction to Computer Science 1 Identifiers, Contd.  Reserved Words examples  const, float, int, return, main  Complete list in Appendix B of text  Case sensitive  Valid or Invalid? Letter1joe’s 1lettercent_per_inch Inchestwo-dimensional Inches*numhello

102/14/2016CS150 Introduction to Computer Science 1 Data Types and Declarations  A data type is a way to represent a particular set of values  Four types  Integers  Reals  Booleans  Characters

112/14/2016CS150 Introduction to Computer Science 1 Integers  Whole numbers, positive or negative  Stored as binary number  Datatype is called int  Operations?  Finite  Examples of integer literals are: 123, -23, 0, 32767

122/14/2016CS150 Introduction to Computer Science 1 Reals  Real numbers can contain fractional parts  Stored in floating point format  Datatype is float  Operations?  Examples of float literals are: 1.0, -.1, 0., 12E5, -1E-2

132/14/2016CS150 Introduction to Computer Science 1 Characters  Individual character--letter, digit, symbol  Characters stored as byte  Datatype is char  Operations?  Char literals are enclosed in single quotes and examples include: 'A' 'a' '?'

142/14/2016CS150 Introduction to Computer Science 1 Purpose of Datatypes  Different ones allow compiler to know how to represent value  Different datatypes can use different operations  The integer 2 is different from 2.0 and the character 2 (all stored differently)

152/14/2016CS150 Introduction to Computer Science 1 Declarations  Declarations are at the beginning of a program  They list the variables used  Format: datatype identifier;