Partha Sarathi Mandal

Similar documents
Partha Sarathi Mandal

Lab Instructor : Jean Lai

Scientific Computing

Introduction to C++ Systems Programming

Introduction to C++ Introduction to C++ 1

Cours de C++ Introduction

EP241 Computer Programming

Data Structures using OOP C++ Lecture 3

Fast Introduction to Object Oriented Programming and C++

C++ Quick Guide. Advertisements

CE221 Programming in C++ Part 1 Introduction

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

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

Computer Programming : C++

Chapter 1 Introduction to Computers and C++ Programming

CS242 COMPUTER PROGRAMMING

CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

Cpt S 122 Data Structures. Introduction to C++ Part II

AN OVERVIEW OF C++ 1

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

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

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

Dr. Md. Humayun Kabir CSE Department, BUET

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Fundamentals of Structured Programming

Functions and Recursion

Data Structures and Programming with C++

Introduction to Programming using C++

Chapter 3 - Functions

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

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE1303. B.Tech. Year - II

A SHORT COURSE ON C++

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Object-Oriented Programming (OOP) Fundamental Principles of OOP

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

Short Notes of CS201

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

Interview Questions of C++

SAURASHTRA UNIVERSITY

Tutorial-2a: First steps with C++ programming

2 nd Week Lecture Notes

CS201 - Introduction to Programming Glossary By

Polymorphism Part 1 1

C++ Programming Fundamentals

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Object Oriented Programming. Solved MCQs - Part 2

Introduction to C++ (Extensions to C)

COMP322 - Introduction to C++ Lecture 01 - Introduction

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Programming. C++ Basics

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

Constructor - example

Your first C++ program

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

Chapter Four: Loops II

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

C++ How to Program, 9/e by Pearson Education, Inc. All Rights Reserved.

Lecture 8: Object-Oriented Programming (OOP) EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

3.1. Chapter 3: The cin Object. Expressions and Interactivity

Object Oriented Design

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.

6.096 Introduction to C++ January (IAP) 2009

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

Use the template below and fill in the areas in Red to complete it.

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

IS 0020 Program Design and Software Tools

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

2. COURSE DESIGNATION: 3. COURSE DESCRIPTIONS:

Object Oriented Programming

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

CS3157: Advanced Programming. Outline

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

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

Engineering Problem Solving with C++, Etter/Ingber

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II

C++ For Science and Engineering Lecture 12

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Introductory Lecture. CS319: Scientific Computing (with C++) Week 1: 11 Jan, Lecturer: Niall Madden.

CSI33 Data Structures

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Transcription:

MA 253: Data Structures Lab with OOP Tutorial 1 http://www.iitg.ernet.in/psm/indexing_ma253/y13/index.html Partha Sarathi Mandal psm@iitg.ernet.in Dept. of Mathematics, IIT Guwahati

Reference Books Cormen, Leiserson and Rivest, Introduction to Algorithms, Prentice Hall-India. A. H. Aho, J. E. Hopcroft and J. Ullman, Data Structures and Algorithms, Addison-Wesley. Bjarne Stroustrup, The C++ Programming Language, Addison-Wesley (Third Edition & Special Edition). Horowitz, Sahni, Mehta, Fundamentals of Data Structures in C++, Galgotia. Timothy A. Budd, An Introduction to Object-Oriented Programming, Third edition, Pearson Education Inc. John R Hubbard, Programming with C++, Schaum s OuTLines, Tata McGRAW HILL

Exams and Marking Quiz + Assignment + Performance in Lab: 50% Midsem: 20% Endsem: 30%

Policy Laboratory attendance is very important and mandatory. You must be punctual. You must attend the proper section There may be pop quizzes in the labs. (A pop quiz is a quiz or test given to the class without prior warning or announcement)

Cheating Gets You equivalent -ve marks of the Question Specific Examples Of Cheating: If you help some body for cheating or providing your login passwd. If you're going to copy someone's assignment or copy code during test.

Overview on C++ Classes and objects Constructors and destructors Overloading operator Inheritance Polymorphism Templates Namespace

Class and Object Class: A data structure that can hold both data and functions. A template for creating objects. Object: Object is an instance of the class Object is usually used to describe variables whose type is a class. Object-oriented programming involves programs that use classes, where objects are used to interact with one another to design applications and computer programs

Object-Oriented Programming How is an object different from a struct? struct contains just data object has data and functionality An object is of a particular class class is the data type of that object an object would be a variable defines what data and functionality the object has And of course, we have the WALL OF ABSTRACTION dividing up the interface and implementation

file.cpp #include<iostream> using namespace std; int main(){ float n1, n2; cout << Enter two numbers: ; cin >> n1 >> n2; float average = (n1+n2)/2; Example code cout << Average = << average << endl; return 0; support Input and Output streaming: the capability to read from the keyboard (input) and write to the screen (output). this signals to the compiler that the code I'm writing is within the std (standard) namespace, it tells the compiler that when it sees cout it is to treat it like std::cout. C++ now includes a group of supporting code called the standard library (std), which provides objects to handle input and output. cin is an object that handles input from the keyboard, and cout is an object that handles output to the screen. main() always returns an int (integer) so we should always declare main to return an integer. $ g++ file.cpp $./a.out $ Enter two numbers: 3 7 $ Average = 5

Few important notes Declaration of variable Can be declared right at the place of its first use. Reference Variable Both of the variable refer to the same data object in memory float x = 10; float &y = x; Memory allocation (new, delete) int *x = new int(10); or int *x; x= new int; *x = 10; here 10 is value delete x; int *a = new int[10]; create a memory space for an array of size 10 delete []a; free the dynamically allocated array Type Casting float average = sum/ float(i);

Blocks and Local Scope A block is a list of statements within curly braces. Blocks can be put anywhere a statement can be put. Blocks within blocks are nested blocks. An object name is known only within the block in which it is defined and in nested blocks of that block. A parameter can be considered to be defined at the beginning of the block corresponding to the function body.

Local Object Manipulation void f() { int i = 1; cout << i << endl; // insert 1 { int j = 10; cout << i << j << endl; // insert 1 10 i = 2; cout << i << j << endl // insert 2 10 cout << i << endl; // insert 2 cout << j << endl; // illegal

Local Object Manipulation void f() { int i = 1; cout << i << endl; // insert 1 { int j = 10; cout << i << j << endl; // insert 1 10 int i = 2; cout << i << j << endl // insert 2 10 cout << i << endl; // insert 1 cout << j << endl; // illegal

Name Reuse If a nested block defines an object with the same name as enclosing block, the new definition is in effect in the nested block

Example void f(){ { int i = 1; cout << i << endl; // insert 1 { cout << i << endl; // insert 1 char i = 'a'; cout << i << endl; // insert a cout << i << endl; // insert 1 cout << i << endl; // illegal insert

Global Scope Objects not defined within a block are global objects. A global object can be used by any function in the file that is defined after the global object. It is best to avoid programmer-defined global objects Exceptions tend to be important constants. Global objects with appropriate declarations can even be used in other program files. cout, cin are global objects that are defined in by the iostream library. Local objects can reuse a global object's name. Unary scope operator :: can provide access to global object even if name reuse has occurred

Example int i = 1; int main() { cout << i << endl; // insert 1 { char i = 'a'; cout << i << endl; // insert a ::i = 2; cout << i << endl; // insert a cout << ::i << endl; // insert 2 cout << i << endl; return 0;

Stdlib Library Provides in part functions for generating pseudorandom numbers. rand() Returns a uniform pseudorandom unsigned int from the inclusive interval 0 to RAND_MAX #include <iostream> #include <string> #include <cstdlib> using namespace std; int main(){ for (int i = 1; i <= 5; ++i) cout << rand() << endl; return 0;

Different Sequences To produce a different sequence, invoke void srand(unsigned int); Consider seed.cpp int main() { cout << "Enter a seed: "; unsigned int Seed; cin >> Seed; srand(seed); for (int i = 1; i <= 5; ++i) cout << rand() << endl; return 0;

Different Sequences To automatically get a different sequence each time Need a method of setting the seed to a random value. The standard method is to use the computer's clock as the value of the seed. The function invocation time() can be used Returns an integral value of type time_t Invocation time(0) returns a suitable value for generating a random sequence.

Example #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main() { srand((unsigned int) time(0)); for (int i = 1; i <= 5; ++i) cout << rand() << endl; return 0;

Problem 1 Deploy 100 random points inside a square of size 10 unit. For given a circular with center and radius fine points which are (i) on perimeter of the circle, (ii) inside the circle and (iii) outside the circle. Find three points inside the circle for which area of the triangle is maximum.

Problem 2 Deploy 100 disks with random center point inside a square of size 10 unit with radius 1 unit. Find total area which is not covered by any of the disk inside the square.