CS 1400 1 Sept 2006. Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
© 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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
Chapter 4 Summation.
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 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
Correction of the Handout #include //Preprocessor using namespace std; int main (){ ………….. return 0; } A namespace is a named group of definitions. When.
1 Engineering Problem Solving with C++ An Object Based Approach Chapter 2 Simple C++ Programs.
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 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Basic Elements of C++ Chapter 2.
Programming is instructing a computer to perform a task for you with the help of a programming language.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
Input & Output: Console
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
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
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Fundamental Programming: Fundamental Programming Introduction to C++
Chapter 2 Overview of C++. 2 Overview  2.1 Language Elements  2.2 Reserved Words & Identifiers  2.3 Data Types & Declarations  2.4 Input/Output 
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
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
Objective: Students will be able to: Declare and use variables Input integers.
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
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++
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
A Sample Program #include using namespace std; int main(void) { cout
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Today Variable declaration Mathematical Operators Input and Output Lab
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2: Introduction to C++
Programming Fundamentals
Computing Fundamentals
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Counting Loops.
Starting Out with C++: From Control Structures through Objects
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Presentation transcript:

CS Sept 2006

Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return 0; }

Output… Pseudocode Print “Enter a number: “ C++ cout << “Enter a number: “; Pseudocode Print square C++ cout << square;

Input… Pseudocode Get value from user C++ cin >> value;

Assignments… Pseudocode Square = n * n C++ square = n * n; Pseudocode Pay = hours * 40 + (hours-40) * Overtime_pay C++ pay = hours * 40 + (hours-40) * overtime_pay;

Declarations… All variables must be established or declared prior to use – usually at the top of the program Integers are declared using int. For example; int value; int width, height, depth; A variable name must begin with a letter, followed by letters, digits, or underscores.

Pseudocode Example: “Write a program to calculate the volume of a box, using dimensions provided by the user.” Print “Enter height, width, and depth of box:” Get height from user Get width from user Get depth from user volume = height * width * depth Print “Volume is: “ Print volume

C++ boilerplate… // Cannon, demo program #include using namespace std; int main() { return 0; }

Adding C++ instructions… // Cannon, demo program #include using namespace std; int main() {int height, width, depth, volume; cout << “Enter height, width, and depth: “; cin >> height >> width >> depth; volume = height * width * depth; cout << “Volume is: “ << volume; return 0; }

C++ is case sensitive! Use lower case for simplicity Upper case or underscore may be used to separate multi-word variable names int phone_number;// easiest to read int phoneNumber;// easier to read int phonenumber;// not as easy to read

Extended syntax… Input and output statements can be cascaded; cin >> height >> width >> depth; cout << “the value of width is: “ << width; Declarations can be a list; int height, width, depth, volume; Output messages can include control characters such as \n (new line) and \a (beep) cout << “This appears on line 1 \n This is on line 2”; Output messages may output endl to force a new line cout << “this is line1 “ << endl << “This is line 2”;

Chapter 2 issues -- Key words; Table 2.4 (4 th edition) Gloss over (for now) –Section 2.3 –Section 2.7 –Section 2.9 –Section 2.10 –Section 2.16

Integer variables Declaring variables as type int – –Only allows them to hold an integer (+ or -) –Range -2,147,483,648 to 2,147,483,647 Variations – –unsigned int –long –short… etcetera

Floating point variables… Declaring variables to be type float – –Allows them to hold an approximate floating- point value (precision to ~6 digits) –Range +/- 3.4 x to +/- 3.4 x –Constants may be expressed in floating-point notation or E-notation –E-notation is like scientific notation 3.14 x 10 5 is the same as 3.14E5