Overview of C++ Chapter 2 in both books programs from books keycode for lab: 68394 get Program 1 from web test files.

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

C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
CS 117 Spring 2002 Basic Program Elements Chapter 2.
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.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Chapter 2: Introduction to C++.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
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.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Lecture 5: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept.
Basic Elements of C++ Chapter 2.
COMPUTER SCIENCE I C++ INTRODUCTION
By Dr. Awad Khalil Computer Science & Engineering Department
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
 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.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
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.
Course websites CS201 page link at my website: Lecture slides Assistant’s Information Recitations Office Hours Make-up.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Week 1 Algorithmization and Programming Languages.
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.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: 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 
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
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 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Comments Allow prose or commentary to be included in program Importance Programs are read far more often than they are written Programs need to be understood.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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
C++ First Steps.
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Course websites CS201 page link at my website: Lecture slides
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to C++ Programming
Chapter 2: Introduction to C++.
The Fundamentals of C++
Presentation transcript:

Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files

2 Hello.cpp char letter1, letter2; string lastName; // Enter letters and print message. cout << "Enter 2 initials and last name: "; cin >> letter1 >> letter2 >> lastName; cout << "Hello " << letter1 << ". " << letter2 << ". " << lastName << "! "; cout << "We hope you enjoy studying C++." << endl; return 0; }

Program format /* begins a c-style comment * (ignored by compiler) * which spans all lines occurring * before the concluding */ // comments which extend to // the end of the line

4 2.1 C++ Language Elements t Comments make a program easier to understand t // Used to signify a comment on a single line t /* Text text */ use if comments on multi lines t Don’t embed comments within /* */ comments

Program format // # compiler directive // you will nearly always need: #include // for your header files #include "myHeader.h"

6 Compiler Directives t #command –Compiler directive –Processed at compilation time –include, define, … t #include –Instructs compiler on what you want in the program –Adds library files to program –Used with –Also " " for user defined

Program format // Global constants and variables should be declared here // constants const type CONST_NAME // global variables - use sparingly type globalVar

main program int main ( void) { // declarations type varName // body of main program return 0;// 0 => success }// end of main

Basic Syntax { } can be used to group statements into blocks () can be used in arithmetic expressions to control order of evaluation [] are used for array indices

Basic syntax The words that are part of the language are reserved words or keywords. Identifiers are words you make up A statement corresponds to a sentence; it ends with a semicolon. It may span multiple lines.

Identifiers Consist of letters (a…z, A…Z), digits (0 …9), underscore (_) cannot start with a digit must not be the same as keywords case sensitive

Input and Output C++ uses streams for input and output sequential - data comes out in same order as it goes in character based. >> extraction operator for input << insertion operator for output

Examples Output cout << "Program …" << endl; Input: cout << "enter data: "; cin >> data;

14 iostreams t Stream data type –Object that is a stream of characters –Defined in iostream –Entered on the keyboard(cin) –Displayed on monitor(cout)

15 Hello.cpp // FILE: Hello.cpp // DISPLAYS A USER'S NAME #include using namespace std; int main () {

16 Hello.cpp Program output Enter first two initials and last name and press return: EBKoffman Hello E. B. Koffman! We hope you enjoy studying C++.

Executable Statements t Memory status –Before and after t Assignments –Form: result = expression; –sizeInSqyards = metersToYards * sizeInMeters; –sum = sum + item;

1/25/02 Homework 1 submit tcole cs117 h1 Programs done independently you may discuss general ideas but don't share your code if someone else explains how to do something, acknowledge their contribution in your readme

Picture Gallery At bottom of web page for your section Each student can put a picture, an link, some text about themselves, link to another personal web page, or nothing

Gallery How To You can me the information at Submit it using submit tcole cs117 pg

Variables Variables provide a means to store values that may change as the program runs.

22 Declarations t Set aside memory for storing program data t Use an identifier to refer to a particular piece of data t Each identifier needed must be declared t type associated with identifier determines how much memory is needed t Can declare more than one variable at a time –Comma used to separate identifiers

Declarations t format t type varID; t int i; t Comma used to separate identifiers t double var1, var2, var3;

Reserved Words and Identifiers t Reserved words have special meanings –Can NOT be used for other purposes (const, float and void are some examples) t Identifiers (variables) –Used to store data by the program (user defined) –Valid identifiers - letter, letter1, _letter –Invalid identifiers - 1letter, const, hell o

25 Identifiers t Identifiers should be –Short enough to be reasonable to type (single word is norm) Standard abbreviations are fine (but only standard abbreviations) –Long enough to be understandable When using multiple word identifiers capitalize the first letter of each word

26 Reserved Words and Identifiers t Special symbols –C++ has rules for special symbols –= * ; { } ( ) // > t Appendix B –Examples of reserved words –Special characters

27 Upper and Lower Case t C++ case sensitive –Compiler differentiates upper & lower case –Identifiers can be either –Be careful though (cost != Cost) t Blank spaces –Use space to make program readable –Use care in placing spaces

Data Types and Declarations t Predefined data types –int(integers) Positive or negative whole numbers INT_MAX- largest int allowed by compiler –float(real numbers) Positive or negative decimal numbers

29 Data Types and Declarations t Predefined data types –bool(boolean) true false –char(Characters) Represent characters

30 Data Types and Declarations t The basic integer type is int –The size of an int depends on the machine and the compiler On pc’s it is normally 16 or 32 bits t Other integers types –short: typically uses less bits –long: typically uses more bits

31 Data Types and Declarations t Different types allow programmers to use resources more efficiently t Standard arithmetic and relational operations are available for these types

32 Data Types and Declarations t Floating-point types represent real numbers –Integer part –Fractional part t The number breaks down into the following parts –108 - integer part – fractional part

33 Data Types and Declarations t C++ provides three floating-point types –float –double –long double

34 Data Types and Declarations t Predefined data types –char(characters) Individual character value (letter or number) Character literal enclosed in single quotes ‘A’ –bool(true / false) t Ordinal types –intboolchar –Values can be listed

35 Data Types and Declarations  Character type char is related to the integer types t Characters are encoded using a scheme where an integer represents a particular character

36 Data Types and Declarations t ASCII is the dominant encoding scheme –Examples ' ' encoded as 32 '+' encoded as 43 'A' encoded as 65 'Z' encoded as 90 ’a' encoded as 97 ’z' encoded as 122

Special Characters Some characters can't be entered into the program directly unprintable characters such as tab, newline, new page characters that have a special meaning such as " and ' Represented by two-character sequence that begins \

Special Characters \nnewline \ttab \"double quote in a text string \'for the single quote character \\to put a \ into a text string