C++ basics Getting started with, and Data Types.

Similar documents
Introduction to C++ (Extensions to C)

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Computer Programming

PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017

AN OVERVIEW OF C++ 1

Dr. Md. Humayun Kabir CSE Department, BUET

File I/O Christian Schumacher, Info1 D-MAVT 2013

WARM UP LESSONS BARE BASICS

Lab # 02. Basic Elements of C++ _ Part1

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

Programming Language. Functions. Eng. Anis Nazer First Semester

Bruce Merry. IOI Training Dec 2013

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Introduction to Programming EC-105. Lecture 2

Fundamentals of Programming CS-110. Lecture 2

Lab Instructor : Jean Lai

Computer Programming : C++

2 nd Week Lecture Notes

C++ Functions. Last Week. Areas for Discussion. Program Structure. Last Week Introduction to Functions Program Structure and Functions

Computing and Statistical Data Analysis Lecture 3

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

G52CPP C++ Programming Lecture 18

Chapter 15 - C++ As A "Better C"

C and C++ I. Spring 2014 Carola Wenk

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Getting started with C++ (Part 2)

Understanding main() function Input/Output Streams

Chapter 2 Basic Elements of C++

Scientific Computing

Introduction to C++ Systems Programming

Input And Output of C++

A First Program - Greeting.cpp

Types, Values, Variables & Assignment. EECS 211 Winter 2018

LECTURE 02 INTRODUCTION TO C++

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

C++ Quick Guide. Advertisements

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

CS2141 Software Development using C/C++ C++ Basics

Engineering Problem Solving with C++, Etter

CS3157: Advanced Programming. Outline

COMP322 - Introduction to C++

A SHORT COURSE ON C++

Chapter 2: Introduction to C++

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

I/O Streams and Standard I/O Devices (cont d.)

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

CS2141 Software Development using C/C++ Stream I/O

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Increment and the While. Class 15

1 Unit 8 'for' Loops

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

CS242 COMPUTER PROGRAMMING

CS11 Intro C++ Spring 2018 Lecture 1

CSCI 1061U Programming Workshop 2. C++ Basics

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Ch 6. Functions. Example: function calls function

BTE2313. Chapter 2: Introduction to C++ Programming

Programmazione. Prof. Marco Bertini

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

CMSC 202 Midterm Exam 1 Fall 2015

CS11 Introduction to C++ Fall Lecture 1

G52CPP C++ Programming Lecture 18. Dr Jason Atkin

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2. Procedural Programming

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

BITG 1113: Array (Part 2) LECTURE 9

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Computer Programming

Computer Programming

Fast Introduction to Object Oriented Programming and C++

Chapter 1 Introduction to Computers and C++ Programming

Why Is Repetition Needed?

CS 11 Ocaml track: lecture 3

Your first C++ program

Lecture 14: more class, C++ streams

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

CS 11 C++ track: lecture 1

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

Programming with C++ as a Second Language

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Module 7 b. -Namespaces -Exceptions handling

Transcription:

C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in

Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding Scope and life time of variables Also talked about Type Errors, Type Checking and Strongly Typed Languages

Getting Started with C++ Getting Started with C++ is easy. In principal every C program is valid C++ program too; C++ is superset of C. Here is the simple C++ program..

C++ Program This is C++ Program Any C program is also a valid C++ program! At this point you shall not find much difference in C and C++ except- C++ has different way of including header files. cin and cout using names std; endl

Note the syntax (difference) of Include using namespace Input/Output cin and cout

#include C++ introduces concept of namespaces. This is a mechanism to avoid name collisions from several developers a large number of developers are contributing toward developing various C++ libraries All C++ language library has been placed under namespace std We will talk about namespaces little later; till then just use it as such. #include <iostream> using namespace std;

#include For most old C header files, prefix c to header file name and drop.h #include <cstring> #include <cmath> #include <cstdio> #include <cstdlib> By the way what header file does?

Input and Output in C++ You can still use scanf and printf, include <cstdio> for this, recall all c library is available in C++ However you use cin and cout objects, wrapping stdin and stdout devices of C, respectively cin >> a >> b; cout << "Average= " << c << endl; cin operator is called as extraction operator, while cout is called as insertion operator! You also have cerr, object wrapper around stderr device of C More about input/output sometime later

Data Types A data type defines a collection of data values and a set of predefined operations on those values Can be categorized in, Primitive Data Types, and Abstract Data Types (or programmer defined data types) Primitive data types are also Abstract Data Types in precise sense (though we never call so), Most languages treat non-primitive data types differently. In C++, string and vector are most commonly used such data types

Primitive Data Types in C++ Following are Primitive Data types supported in C++ Integer: short, int, long Floating Point : float, double, long double Character: char Boolean: bool A quick overview is available athttp://www.cplusplus.com/doc/tutorial/variables.html

Strings in C++ One way is, you can use same old char array, however there are certain issues here..? Array bound problem use of functions for manipulation is not like a abstract data type C++ provides string Abstract Data Type, and you can use it the way you use any primitive data type string is a class, and you need to include <string> to use it

Operations on string Declare and initialize string s1 = "Welcome"; Assign s2 = s1; s1 = "Hello"; Concatenation string s3 = s1 + s2; More operations int n = s.length(); string student_id = "200601212"; string prog_code = student_id.substr(4,2); Compare this with the way you do this with char array Note that here string is a class and s,s1,s2 are objects of that class.

Variables and Objects Here is how we create a variable int x; Here is how we create object string name= Amit ; What is difference between? In principal.. no difference; both are instance of Abstract data Types; in imperative language we call variables, while in object oriented we call objects. However; the most OOP programming languages deal primitive data types and classes differently; and typically use of term variable for instances of primitive data types while objects for instances of classes

Thanks