C++ (intro) Created by Hwansoo Han Edited by Ikjun Yeom.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
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.
C Tutorial Ross Shaull cs146a Why C Standard systems language – Historical reasons (OS have historically been written in C, so libraries written.
C Intro.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Informática II Prof. Dr. Gustavo Patiño MJ
Writing and Testing Programs Drivers and Stubs Supplement to text.
Overview creating your own functions calling your own functions.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
How Create a C++ Program. #include using namespace std; void main() { cout
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
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)
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
University of Calgary – CPSC 441. C PROGRAM  Collection of functions  One function “main()” is called by the operating system as the starting function.
Input & Output: Console
Agenda Review Unix Review Algorithms Your first program Compiling programs What are functions? What is Object Oriented Programming? Variables Data Types.
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.
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.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
C/C++ Basics. Basic Concepts Basic functions of each language: Input, output, math, decision, repetition Types of errors: Syntax errors, logic errors,
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Functions in C++ Default arguments Overloading Inlining Call-by-reference Scope of variables, static, extern namespace new and delete assert.
Glenn Stevenson CSIS 113A MSJC CSIS 113A Lecture 2.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
C++ / G4MICE Course Session 1 - Introduction Edit text files in a UNIX environment. Use the g++ compiler to compile a single C++ file. Understand the C++
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
Pointers by Dr. Bun Yue Professor of Computer Science CSCI 3333 Data Structures.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Lecture 01a: C++ review Topics: Setting up projects, main program Memory Diagrams Variables / Types (some of) the many-types-of-const's Input / Output.
CSE 332: C++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Gramming An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
C is a high level language (HLL)
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
A Sample Program #include using namespace std; int main(void) { cout
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
An Introduction to C Programming (assuming that you already know Java; this is not an introduction to C++)
Lecture 3: Getting Started & Input / Output (I/O)
CSC 533: Programming Languages Spring 2016
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 13 Introduction to C++ Language
CSC 533: Programming Languages Spring 2015
Intro to ETEC Java.
Computer Science 210 Computer Organization
Chapter 2: Introduction to C++
Documentation Need to have documentation in all programs
Computing Fundamentals
Command Line Arguments
Introduction to C++ October 2, 2017.
C Basics.
Going from C++ to Java Jayden Navarro.
Computer Science 210 Computer Organization
2.1 Parts of a C++ Program.
Pointers, Dynamic Data, and Reference Types
Created by Hwansoo Han Edited by Ikjun Yeom
Building Java Programs
Programming Introduction to C++.
Pointers, Dynamic Data, and Reference Types
CSC 533: Programming Languages Spring 2019
Introduction to C CS 3410.
Presentation transcript:

C++ (intro) Created by Hwansoo Han Edited by Ikjun Yeom

Why New Languages?  Already know  C, Java, Python, Matlab, …  C++  Basically extension to C  All C code compiled with C++ compilers  But many libraries and “OO” concepts added 2

Many Use C++  Most recent open source projects  Written in C++ or Java  Easier to understand – “OO” design  Natural extension to C  C and C++ can be easily mixed (with a little efforts) 3

Hello, World! 4 /* * First program in C++ : hello world */ #include using namespace std; // main function int main() { cout << “hello, world!” << endl; return 0; } /* * First program in C++ : hello world */ #include using namespace std; // main function int main() { cout << “hello, world!” << endl; return 0; } console output

C++ IDE  Download Cygwin   Set PATH to include g++ or gcc ( 제어판 > 시스템및보안 > 시스템 > 고급시스템설정 > 고급 tab> 환경변수 )  Download JRE 6.0 or above  Google “JRE 64bit windows 7”  E.g. Downloads.cnet.com  Run the downloaded file to install JRE  Download Eclipse CDT (C/C++ development tooling)   Download “Eclipse IDE for C/C++ Developers”  Unzip the downloaded file into a directory  E.g. D:\bin\ 5

Genealogy of Programming Languages 6

C++ vs. C vs. Java: Minor Differences  Boolean type  C:int myBooleanValue = 1 ;  C++: bool myBooleanValue = true;  Java: boolean myBooleanValue = true;  Printing  C: printf(“Hello!\n”);  C++: cout << “Hello!” << endl;  Java: println(“Hello!”); 7

C++ vs. C vs. Java: Minor Differences  Calling other functions  C/C++ : define before use  Java : no such worries void PrintHello(); void PrintTime() { cout << “It’s time to go!” << endl; } int main() { PrintHello();// OK – Prototype defined earlier PrintTime();// OK – Function defined earlier SayHi();// ERROR – no prototype earlier } void PrintHello() { cout << “Hello!” << endl; } void SayHi() { cout << “Hi!” << endl; } void PrintHello(); void PrintTime() { cout << “It’s time to go!” << endl; } int main() { PrintHello();// OK – Prototype defined earlier PrintTime();// OK – Function defined earlier SayHi();// ERROR – no prototype earlier } void PrintHello() { cout << “Hello!” << endl; } void SayHi() { cout << “Hi!” << endl; } 8

C++ vs. C vs. Java: Major Differences 9  C/C++ has no garbage collector  Java :Integer myInt = new Integer(); myInt = NULL;// GC will delete  C++ : programmers need to delete  C : programmers need to free  Objects  Java : memory for all objects is put on the heap  C++ : Objects can be placed either on the stack or the heap  C : no objects, malloc gets the space from the heap

C++ vs. C vs. Java: Major Differences 10  C++ can choose to pass by value, pointer, and reference  C can choose to pass by value or pointer  Java cannot choose  Primitives only pass by value  Objects only pass by reference /* Java */ void AddOne(int x) { x++; } void run() { int x = 7; AddOne(x); println(x); // output 7 } /* Java */ void AddOne(int x) { x++; } void run() { int x = 7; AddOne(x); println(x); // output 7 } /* C++ */ void AddOne(int &x) { x++; } int main() { int x = 7; AddOne(x); cout << x << endl; // output 8 } /* C++ */ void AddOne(int &x) { x++; } int main() { int x = 7; AddOne(x); cout << x << endl; // output 8 } /* C */ void AddOne(int *x) { (*x)++; } int main() { int x = 7; AddOne(&x); printf(“%d\n”, x); // output 8 } /* C */ void AddOne(int *x) { (*x)++; } int main() { int x = 7; AddOne(&x); printf(“%d\n”, x); // output 8 }

Coding Style – Managing Large Code 11  Instead putting all into a single file, separate them for easier management  Files with extension.cpp/.cc contains implementations of functions  Files with extension.h contains function prototype .h files are used to overall shape of source code  Other programmers can roughly recognize your programs through header files (.h files)  If you don’t care the details on how a function works, you don’t have to look into.cpp files.

C++ vs. C vs. Java: Similarities 12  Short circuit evaluation  if (x < 4 || y == 3) // test the first (x<4), if true skip the second  Integer division  9/4 ⇒ 2  Primitives  char, short, int, long, float, double  Type conversion  3/2.0 ⇒ 1.5  ⇒ 18.2  Functions, objects (C++/Java), arithmetic operators, …