Structures and Functions Ghulam Nasir Khan. Important /\/otes Programming is a fundamental course of IT as well as BICSE, so it will be very difficult.

Slides:



Advertisements
Similar presentations
Pointers.
Advertisements

Chapter 7: Arrays In this chapter, you will learn about
C Language.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Structure.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Pointers| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: September 2006 Slide 1 Pointers by Jumail Bin Taliba Faculty of Computer.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
What are Pointers? Different from other normal variables which can store values. pointers are special variables that can hold the address of a variable.
CIS Computer Programming Logic
Object Oriented Programming (OOPs) Class Object Data Hiding Abstraction Encapsulation Polymorphism Inheritance Difference between Procedural and OOPs programming.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
Data Structure and Algorithm: CIT231 Lecture 4: ADT and Introduction to Object Oriented Programming (OOP) DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
1 Principles of Programming I Note Set #12. 2 Semester Overview Functions Character File I/O Arrays Pointers and Dynamic Memory Allocation Characters.
ARRAY Prepared by MMD, Edited by MSY1.  Introduction to arrays  Declaring arrays  Initializing arrays  Examples using arrays  Relationship with pointers.
UNIT II. -set of homogeneous data items. Eg: int arrays can hold only integers and char arrays can only hold characters. Arrays have a type, name, and.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Array, Structure and Union
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
+ 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.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 07 classes 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
DATA STRUCTURE & ALGORITHMS Pointers & Structure.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 06 FUNCTIONS 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
CHAPTER 7: Arrays CSEB113 PRINCIPLES of PROGRAMMING CSEB134 PROGRAMMING I by Badariah Solemon 1BS (Feb 2012)
Prepared by MMD, Edited by MSY1 CHAPTER 4 ARRAY. Prepared by MMD, Edited by MSY2 Arrays  Introduction to arrays  Declaring arrays  Initializing arrays.
Programming Fundamentals. Today’s Lecture Multidimensional Arrays Arrays as Class Member Data Arrays of Objects C-Strings.
1.1 Data Structure and Algorithm Lecture 1 Array Record Sequential Search Binary Search Bubble Sort Recursion Complexity Topics.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Pointers. The memory of your computer can be imagined as a succession of memory cells, each one of the minimal size that computers manage (one byte).
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Functions Dr. Sajib Datta Functions A function is a self-contained unit of program code designed to accomplish a particular task. Some functions.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Windows Programming Lecture 03. Pointers and Arrays.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 10-1: Structure.
Structures and Unions.
Revision Lecture
Introduction to C++.
Programming Structures.
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Functions Dr. Ashish Sasankar. In programming, a function is a segment that groups code to perform a specific task. A C program has at least one function.
DATA HANDLING.
Buy book Online -
Lecture 9 Structure 1. Concepts of structure Pointers of structures
S. Kiran, PGT (CS) KV, Malleswaram
Structure ការណែនាំអំពី Structure
Lecture 12 Oct 16, 02.
Pointer to Structures Lesson xx
Introduction To Programming Information Technology , 1’st Semester
Chapter 7: User-Defined Functions II
Introduction to C Programming
C Programming Lecture-8 Pointers and Memory Management
C Programming Lecture-13 Structures
Structures In C Programming By Rajanikanth B.
C Data Types and Variable
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
Presentation transcript:

Structures and Functions Ghulam Nasir Khan

Important /\/otes Programming is a fundamental course of IT as well as BICSE, so it will be very difficult to proceed without programming. You will be thought different courses on programming throughout your course of study such as OOP using C++, Data Structures, Algorithms, Assembly Language, Web Designing so there is no way out. The key point is try to develop interest in programming and try to practice as much as you can.

Important /\/otes Try to clear all of your concepts and practice as much as possible you that can make a good understanding of programming Do not let the instructor proceed, even if you have a small confusion in mind. Try to learn as much programming as you can in this semester so that you do not have to cry over spilt milk. BEST OF LUCK

An Overview of Structures

What is Structure Structure is used to store data of same or different type. It is used to group data that may be of the same or different types. Basically it is used to store data that has a logical relation e.g. record of a student etc. It can also be said that structure is used to create a new data type comprising of the existing data types.

Composition of Structures Structures are composed of Data Members Data Members Member Functions Member Functions Data Members are memory locations that are used to store data e.g. variables, arrays etc. Member Functions are used to manipulate the Data Members.

Memory !!!! How much memory is occupied by Structures? 1 Byte? 1 Byte? 4 Bytes? 4 Bytes? 8 Bytes? 8 Bytes? N Bytes? (Specify the value of N) N Bytes? (Specify the value of N) The answer is Zero Bytes Zero Bytes

Structure Variable The representation of Structure is memory is called Structure Variable or Structure Object or simply Object. Object occupies space in the memory and object actually stores the data.

Memory !!!! How much memory is occupied by Structure Object? 0 Byte? 0 Byte? 1 Byte? 1 Byte? 4 Bytes? 4 Bytes? 8 Bytes? 8 Bytes? 16 Bytes? 16 Bytes? N Bytes? (Specify the value of N) N Bytes? (Specify the value of N)

Memory !!!! The answer is The sum of memory occupied by all the data members of a structure. The sum of memory occupied by all the data members of a structure. For Example, all the objects of a structure having two integer, one float and one character data member will occupy 4 * = = 13 Bytes

Declaring a Structure struct StructureName { DataType variable 1; DataType variable 1; DataType variable 2; DataType variable 2;.. DataType variable n; DataType variable n;};

Creating Structure Object struct StructureName objname; StructureName objname; Here objname is a user defined name of the object. It must follow Variable Naming Rules.

/* Program Name: struct.cpp Program Name: struct.cpp Author: Nasir */#include<iostream.h> struct emp { int empno; float salary; };

void main() { emp e; cout<<"Enter employee number:”; cin>>e.empno; cout<<”Enter salary:”; cin>>e.salary; cout<<”You have entered:”<<endl; cout<<”Employee #”<<e.empno<<endl; cout<<”Salary:”<<e.salary;}

Today’s Lecture Structures and Functions

Passing Structures (Objects) To Functions Like ordinary variables and arrays, structure object can also be passed to functions. The syntax for passing Structure Objects to functions is the same as ordinary variable. The only difference is that the DataType in that case is replaced by The StructureName.

Passing Structures (Objects) To Functions Syntax (in case of ordinary variables): ReturnType FunctionName(int a,int b) {} Syntax (in case of structure objects): ReturnType FunctionName(st a, st b) {}Note: Here st is the name of the structure whose object is being passed to the function. Structure Objects are passed by value.

/* Program Name: struct.cpp Program Name: struct.cpp Author: Nasir */#include<iostream.h> struct emp { int empno; float salary; };

void show(emp t); void main() { emp e; cout<<"Enter employee number:”; cin>>e.empno; cout<<”Enter salary:”; cin>>e.salary; cout<<”You have entered:”<<endl; show(e);}

void show(emp t) { cout<<”Employee #” << t.empno; cout<<endl; cout<<”Salary:”<<t.salary;}

Returning Structure Variables (Objects) Syntax (in case of ordinary variables): ReturnType FunctionName(int a) { return variablename; } Syntax (in case of structure objects): st FunctionName(st a, int b) { return objname; }Note: Here st is the name of the structure whose object is being passed to the function. Here objname is the name of the object of structure st

/* Program Name: struct.cpp Program Name: struct.cpp Author: Nasir */#include<iostream.h> struct emp { int empno; float salary; };

emp input(emp t); void main() { emp e; e=input(e); cout<<”You have entered:”<<endl; cout<<”Employee #” << e.empno; cout<<endl; cout<<”Salary:”<<e.salary;}

emp input(emp t) { cout<<"Enter employee number:”; cin>>t.empno; cout<<”Enter salary:”; cin>>t.salary; return t; }

Questions ?????