WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.

Slides:



Advertisements
Similar presentations
Structures Spring 2013Programming and Data Structure1.
Advertisements

1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
Chapter 5 Functions.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT], MPhil (Comp. Sci), PGDCA, ADCA, Dc. Sc. & Engg.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Guide To UNIX Using Linux Third Edition
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science)
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.
Java Unit 9: Arrays Declaring and Processing Arrays.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
DCT1063 Programming 2 CHAPTER 5 ADVANCED DATA TYPE (part 1) Mohd Nazri Bin Ibrahim Faculty of Computer Media and Technology TATi University College
CCSA 221 Programming in C CHAPTER 14 MORE ON DATA TYPES 1 ALHANOUF ALAMR.
Presentation on Structure. Structure Structure - It is a collection of variables referenced under one name. The keyword struct tells the compiler that.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
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.
CPS120: Introduction to Computer Science
CHAPTER 3 Function Overloading. 2 Introduction The polymorphism refers to ‘one name having many forms’ ‘different behaviour of an instance depending upon.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Structure A structure is a collection of variables of different data type under one name. It is a derived data type. e.g. struct employee {int empno; char.
Learners Support Publications Classes and Objects.
DATA STRUCTURES LAB 1 TA: Nouf Al-harbi
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
+ Structures and Unions. + Introduction We have seen that arrays can be used to represent a group of data items that belong to the same type, such as.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
Manish K Parmar PGT (CS) K V VVNagar Thursday, December 24, 2015 Lesson on USER DEFINED FUNCTION IN C++ Presented by Manish K Parmar PGT Computer Science.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Chapter 6 Methods Chapter 6 - Methods.
CPS120: Introduction to Computer Science Data Structures.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
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.
1 CS161 Introduction to Computer Science Topic #15.
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
STRUCTURES. INTRODUCTION A structure is same as that of records. It stores related information about an entity. Structure is basically a user defined.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Chapter Topics The Basics of a C++ Program Data Types
Pointers, Enum, and Structures
Basic Elements of C++.
Objectives Identify the built-in data types in C++
Functions Separate Compilation
Introduction to C++.
C Basics.
Basic Elements of C++ Chapter 2.
11/10/2018.
Lecture 4-7 Classes and Objects
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science)
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Govt. Polytechnic,Dhangar
Classes and Objects.
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Chapter 1: Introduction to Data Structures(8M)
Java Programming Language
Submitted By : Veenu Saini Lecturer (IT)
C Language B. DHIVYA 17PCA140 II MCA.
Presentation transcript:

WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.

Reference Book CLASS XI By Sumita Arora

CHAPTER 13 STRUCTURES

INTRODUCTION In C++ language, custom data types can be created to meet users requirements in 5 ways: class, structure, union, enumeration and typedef. Structures are one of the 2 important building blocks in the understanding of classes and objects. A structure is a collection of data and functions. In other words, we can say, a structure plus related functions make a class.

INTRODUCTION Technically,there is no difference between a structure and a class. In fact, a structure is a class declared with keyword struct and by default, all members are public in a structure whereas all members are private by default in the class.

STRUCTURES Sometimes, some logically related elements need to be treated under one unit. For instance, the elements storing a student ’ s information (e.g., roll no, name, class, marks, grade) need t be processed together under one roof. Similarly, elements keeping a date ’ s information (e.g., day, month, and year) need to be processed together. To handle and serve to such situation, C++ offers structures. Thus it can be said that, A C style structures is a collection of variables referenced under one name.

STRUCTURES To handle and serve to such situation, C++ offers structures. Thus it can be said that, A C style structures is a collection of variables referenced under one name.

STRUCTURES The following code fragment shows how to define a structure (say date). The keyword struct tells the compiler that a structure is being defined. Struct date { short day; short month; short year;};

REFRERENCING STRUTUERE ELEMENTS Once a structure variable has been defined, its member can be accessed through the use of (.) the dot operator. Ex. The code assigns 1740 t the year element of birth_date structure variable declared earlier: birth_date.year = 1740; the structure variable followed by the (.) & name references to that individual structure element.

REFRERENCING STRUTUERE ELEMENTS The structure members are just treated like other variables. Therefore to print year of birth_date we can write cout<<birth_date.year;

Initializing Structure Elements Structure can be initialized separately or jointly. Member of structure senior_student can be initialized as separately: senior_student.rolln=01; senior_student.class=12; senior_student.marks=50; senior_student.grade=A

Initializing Structure Elements Or jointly as: Stutype senior_student = { 01,12,50,A }; Joint structure can not be used befour the variables are defined.

Structure Assignment Objects of the same structure can be assign or passed as a function. Ex. The members of senior_student can be assign to junior_student.

Structure Assignment Two structure types are different ven they have same members. Struct one { int a ; }; Struct two{int a; }; one s1 ; two s2; cin >> s1.a; //read s1 s2=s1 //error :type mismatch The code will produce an error because both are of different type.

NESTED STRUCTURE A structure element may be either complex or simple.the simple elements are int, char, float double. Element of structure may contain structure in itself known as complex structure.

ACCESSING NESTED STRUCTURE MEMBER The member of structure can be accessed by using dot operator. To access the city member of address which is the element of other structure worker, we shall write: Worker.address.city

STRUCTURE AND ARRAYS Structure and arrays are both derived types. Arrays are the collection of analogous elements, structures assemble dissimilar elements under one roof. Both can be combined to form compels data objects.

ARRAYS OF STRUCTURE An array can contain similar elements,the combination having structures within an array is an array of structure.To declare an structure tou must define a structure and then declare an array variable of that type. To declare a 100 element array of structure of type addr men_addr [100] ; To access a specific structure ex. to print houseno of structure 8 write cout << mem_add [7].houseno ;

Passing structure to function Passing a local structure to a function can be done in two ways: 1.By passing individual structure element 2. By passing the entire structure.

Passing structure elements to function When an element of structure is passed to a function, actually a value of that element to that function is passing. It is just like passing the simple variable. Passing entire structure makes sense when structure is relatively compact. The entire function can be passed by value or by reference.

Returning structure from function Just like other types, function can return structure also. Then the type of the function is the same as that of structure returned.

User defined data type C++ allows you to define new type of data types name by using keyword typedef Typedef does not create new data class rather it define new name for an existing type. Ex typedef float amount

#Define Pre-Processor Directive Pre-processor commands are called DIRECTIVES and begins with a pound symbol.(#). Many things that can be done during pre-processor phase include: Inclusion of other files through #include directive. Definition of symbolic constants and macros through #define directive.

#Define Pre-Processor Directive The preprocessing phase of a c++ program occurs befour a program is compiled. The c++ peprocessor is a program that is executed befour the source code is compiled.

#Define Pre-Processor Directive The preprocessor allows us to define symbolic names and constants. Ex. 1. #define I #define MAX 70 Macros are built on #define preprocessor A micro define would be #define SQUARE (x) x*x

#Define Pre-Processor Directive The difference is of constant and expression. #include #define square (x) x*x Void main() {int value=3; cout << square (value); } After preprocessing the code would become Void main() {int value =3; Cout <<value*value}

#Define Pre-Processor Directive A few things that must be known about macros A macro without argument is treated like symbolic constant. A micro substitutes text only ; it does not check for data type. While defining macros,make sure you use parenthesis. #define CIRLE_AREA(X) PI*X*X area =CIRLE_AREA(C+2); IT WOULD BE EXPANDED AS area = *C+2*C+2;

THANK YOU