CS150 Introduction to Computer Science 1

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
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++.
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.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Course websites CS201 page link at my website: Lecture slides Assistant’s Information Recitations Office Hours Make-up.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
C++ Programming: Basic Elements of C++.
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 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
LESSON 2 Basic of C++.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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 # 2 Part 2 Programs And data
C++ First Steps.
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Basic Elements of C++
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
Documentation Need to have documentation in all programs
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)
Introduction to C++ October 2, 2017.
Lecture2.
Chapter 2: Introduction to C++
Chapter 2 Elementary Programming
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Course websites CS201 page link at my website: Lecture slides
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.
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to C++ Programming
Chapter # 2 Part 2 Programs And data
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:

CS150 Introduction to Computer Science 1 Announcements Website is up! http://zeus.pacificu.edu/shereen/CS150 All lecture slides, assignments, lab notes will be available on this site in two forms: Microsoft PowerPoint or Word PDF (Acrobat Reader) 12/6/2018 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Implementation //Program purpose: converts distance in miles to kilometers //Author: Friedman & Koffman //Date: August 30, 2000 #include <iostream> 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”; 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; } 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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 */ 12/6/2018 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Compiler directives #include <iostream> # 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 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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. 12/6/2018 CS150 Introduction to Computer Science 1

Main function definition int main( ) { main program } Your main program is where execution starts. Every program has one! 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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 ; 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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? Letter1 joe’s 1letter cent_per_inch Inches two-dimensional Inches*num hello 12/6/2018 CS150 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 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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' '?' 12/6/2018 CS150 Introduction to Computer Science 1

CS150 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) 12/6/2018 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Declarations Declarations are at the beginning of a program They list the variables used Format: datatype identifier; 12/6/2018 CS150 Introduction to Computer Science 1