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)

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Introduction to C Programming
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
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.
Three types of computer languages
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.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
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++.
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Chapter 01: Introduction to Computer Programming
COMPUTER SCIENCE I C++ INTRODUCTION
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Intro. to Game Programming Want to program a game?
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Programming Languages
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Chapter 3 Getting Started with C++
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
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.
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.
Object Oriented Programming with C++ Diploma in Computer System Design.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Slide 1. Slide 2 Chapter 1 C++ Basics Slide 3 Learning Objectives  Introduction to C++  Origins, Object-Oriented Programming, Terms  Variables, Expressions,
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
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
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Learners Support Publications Introduction to C++
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
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 Structure of Simple C++ Program Chapter 1 09/09/13.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
Chapter 1.2 Introduction to C++ Programming
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Introduction to C++ Programming
Programs written in C and C++ can run on many different computers
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Introduction to Programming - 1
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

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) C was developed in 1970s at AT&T (Richie) C is a procedure-oriented language C++ early 80s (Bjarne Stroustrup) C++ is an object-oriented superset of C Should I learn C first? Learn procedural programming before OO * * *

Edit Source Code Start Compile Errors yes no Link Errors Link yes no Link yes Run Time Errors Done no * * *

Source to Executable * source code compiler - h-files used object code linked to libraries a.out To ensure compilation was successful: 1.rm a.out 2.g++ myprog.cc 3.ls a.out

A First Program 1.#include 2.void main() 3.{ 4.cout 2.void main() 3.{ 4.cout <<"Hello World\n"; 5.}

#include Inserts the contents of a system file iostream.h the particular file to include Can include user files, too Breaking it Down Preprocessor can include a file *

Including Shared Code source code preprocessor expanded source code C++ compiler #include #include

#include<iostream.h> void main( ) { } A Simple Program Parts of a simple program * statements Header Body

int main ( ) int main ( ) Function Header Line main() is called by & returns to OS function name type of returned value argument * *

header void main( ) { } { } Parts of all Functions There must be exactly one main() note alignment * body { Function:

<< << insertion operator (“put to”) \t \n  endl \ttab \n  endlhard return - begin a new line Intro to cout (Console OUTput) Prints values to the screen Intro to cout (Console OUTput) Prints values to the screen *

cout <<"Here is 5: "<<5<<"\n"; Here is 5: 5 Output Here is 5: 5 cout Example Prints two strings and one literal integer *

cout <<"A big number: \t "<<70000<<endl; Output A big number: Note: endl does the same thing as “\n” Another cout Example Additional space from the TAB character *

cout <<"The sum of 8 & 5 is "<<8 + 5<<“\n”; Output The sum of 8 & 5 is 13 Expressions & cout The value of the expression is displayed *

cout <<"Big # : "<< 7000*7000<<endl; Big # : 4.9e+07 Output Big # : 4.9e+07 A Look at cout is bigger than default space * 4.9 *10 7 Scientific notation

cout <<"A fraction: "<<5/8 <<endl; A fraction: Output A fraction: A Look at cout A decimal fraction *

>> >>insertion operator (get from) Paired with cout. cout accesses and displays values cin reads and assigns values cin >> age; /*causes the program to stop and wait for user input*/ A Look at cin cin allows data to be input into variables

cout > num1; The contents of the address named num1 is... A Look at cin Parts of a simple program

cout << “Enter 3 numbers: “; cin >> num1 > num1 << num2 << num3; The contents of the address named num1 is … num2 is … num3 is... A Look at cin Parts of a simple program

Reserved Words Words that have special meanings in the language. They must be used only for their specified purpose. Using them for any other purpose will result in a error. e.g. coutdoifswitch cinwhileelsereturn *

Reserved Words C++ is case-sensitive. Thus: coutCOUTCoutcOut all have different meanings. The reserved words are all in lowercase. Don’t use reserved words other ways, even with different capitalization. *

Statements A statement controls the sequence of execution, evaluates an expression, or does nothing, and ends with a semicolon. Preprocessor statements do not end with semicolon #include They do always start with #

4 Statements 4 Statements { cout <<"A fraction: "<<5/8 <<endl; cout <<"Big # : "<< 7000*7000<<endl; cout <<8 + 5 <<" is the sum of 8 & 5\n"; cout << “Hello world”; }

Comments These are important parts of a program. Two types Two types // /* */or/* */ *

Comments Do: Add comments to source code. Keep comments up to date. Use comments to explain sections of code. Don't: Use comments for code that is self-explanatory. * *

Programming Style Always list function return type. Void is used to indicate no value is returned void main ( void ) { statements; } optional *

Programming Style group declarations at the beginning void main ( ) { declaration statements; other statements; }

Programming Style blank lines before and after control structures void main () { statements; if (expression) { statement; statement; } statements; } * * *

Slide 30 of 32

Slide 32 of 32

Success comes before work only in the dictionary.