CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Programming in Java; Instructor:Alok Mehta Objects, Classes, Program Constructs1 Programming in Java Objects, Classes, Program Constructs.
Guide To UNIX Using Linux Third Edition
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Review of C++ Programming Part II Sheng-Fang Huang.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Input & Output: Console
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
The Java Programming Language
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Lecture #5 Introduction to C++
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 9 Questions 1. What are the difference between constructors and member functions? 2. Design and implement a simple class as you want, with constructors.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CS 261 – Data Structures Introduction to C Programming.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Object Oriented Software Development 4. C# data types, objects and references.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
C is a high level language (HLL)
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
C++ Functions A bit of review (things we’ve covered so far)
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
Programming what is C++
The Machine Model Memory
Introduction to C++ Systems Programming.
Java Primer 1: Types, Classes and Operators
Objects, Classes, Program Constructs
Road Map Introduction to object oriented programming. Classes
C Basics.
Programming Language Concepts (CIS 635)
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Java Programming Language
Chapter 1: Computer Systems
Introduction to Primitive Data types
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
C Programming Getting started Variables Basic C operators Conditionals
Java Programming Language
Introduction to Primitive Data types
SPL – PS3 C++ Classes.
Presentation transcript:

CS-341 Dick Steflik Introduction

C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining new types (classes) provides symbolic constants provides inline substitution of functions allows default function arguments allows function name overloading allows operator overloading operators for managing free storage provides a reference type

C++ Usage procedural programming - a better version of C –cleaner handling of arrays as function parameters –stream based I/O model object oriented programming –encourages reuse of already tested code rather than inventing a problem solution over and over –encourages data abstraction –encourages data hiding

The C++ Compiler Translates C++ source code into the machine language for the hardware platform –output of the compiler are object files (.obj) which are partially ready to run –object files must be linked together using the system linker to make an executable file (.exe).exe files are specific for the hardware platform C++ is portable only at the source level

C++ application development C++ Source File compiler C++ Include Files Object File Linker System Object Files.EXE File

C++ include statements indicate to the compiler preprocessor which files (source) to include in the file to be compiled. Included files are actually copied into the source file and replace the #include statement as part of precompilation. #include “myclass.h” –the quotes indicate that the file is in the same directory as the file being compiled #include –the indicate the file is in the compiler system directory #include “fully qualified file name ”

C++ application classes are/can be used by a C++ application; but the application is not itself an instantiated class (like Java) main() is the name of the function where the executable file starts execution C++ classes do not have main() functions C++ objects are initialized via class constructors, C++ applications are initialized in the main() function.

Data Types

Primitive Types Integer types –char : 8 bit –short : 16 bit –int : 32 bit –long : 64 bit Real Types –float - 32 bit real numbers –double - 64 bit real numbers

Constants In C++ constants are similar to variables but are never allowed to be the target of an assignment (explicit or implicit) In C++ constants are defined as: –const int abc = 100 ; const char plus = ‘+’;

Strings C++ has no native built-in String type Strings are implemented as null terminated arrays of characters, last character of the string is a null character (‘\0’) char [3] abc = “me” –array abc consists of “m”, “e”, null abc = “me” (shortcut for defining and initializing a string) string functions are in

Boolean (false/true) C++ has no boolean type like Java – the value 0 represents false – any other value represents true the statement “if (50) cout <<“t”; – will always print “t” as 50 is not 0 so the predicate is true the statement “if (5-5) cout<<“t”; else cout << “f” ; –will always print “f” as (5-5) is 0 (i.e. False)

Derived Types These operators create new types from the basic types –*pointer to –*constconstant pointer –&reference to (addressing operator) –[ ]vector of –()function returning

Null statements the simplest statement is the null statement ; useful if the syntax requires a statement for instance to introduce a time delay into a program: –for (int j = 0 ; j < 100 ; j++) {;}

Function Parameters pass by value (default): upon invoking the function the function creates a local copy of the parameter and copies the value to the copy. int foo (int a, int b) { … } int x = 5 ; int y = 7; int b = foo(a, b); x=5 y=7 foo a = 5 b = 5 This gives the effect of x and y being input only as the function can’t change them.

Function Parameters pass by reference: passes a reference to the parameter to the function, the function works with the reference. The function can both read from and write to the argument. Internal to the function the name in the definition is used as an alias for the argument use the & operator to indicate “pass by reference int foo(int &a, int & b) {….} int x=5 ; int y = 7; int t = foo(x,y);

Arrays Array definition is the same: ex. int myarray[5]; when used with a function the syntax is different, to pass an array to a function you no longer need to pass a pointer to the array, just pass the array name. int sum(int cnt, int [ ] m){ int t = 0; for (int i=0 ; i<cnt ; i++) t = t + m[i]; return t } int x = sum(5,myarray);

Array passing always pass by reference (default method)