structures and functions n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Structures and Functions PowerPoint Presentation
Download Presentation
Structures and Functions

Loading in 2 Seconds...

play fullscreen
1 / 25

Structures and Functions - PowerPoint PPT Presentation


  • 52 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Structures and Functions' - neron


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
structures and functions

Structures and Functions

Ghulam Nasir Khan

important otes
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 otes1
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

what is structure
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
Composition of Structures
  • Structures are composed of
    • Data Members
    • 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
Memory !!!!
  • How much memory is occupied by Structures?
    • 1 Byte?
    • 4 Bytes?
    • 8 Bytes?
    • N Bytes? (Specify the value of N)
  • The answer is
    • Zero Bytes
structure variable
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.
memory1
Memory !!!!
  • How much memory is occupied by Structure Object?
    • 0 Byte?
    • 1 Byte?
    • 4 Bytes?
    • 8 Bytes?
    • 16 Bytes?
    • N Bytes? (Specify the value of N)
memory2
Memory !!!!
  • The answer is
    • 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 * 2 + 4 + 1 = 8 + 4 + 1 = 13 Bytes
declaring a structure
Declaring a Structure

struct StructureName

{

DataType variable 1;

DataType variable 2;

.

.

DataType variable n;

};

creating structure object
Creating Structure Object
  • struct StructureName objname;
  • StructureName objname;
  • Here objname is a user defined name of the object. It must follow Variable Naming Rules.
slide13
/*

Program Name: struct.cpp

Author: Nasir

*/

#include<iostream.h>

struct emp

{

int empno;

float salary;

};

slide14
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

Today’s Lecture

Structures and Functions

passing structures objects to 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 functions1
Passing Structures (Objects) To Functions
  • Syntax (in case of ordinary variables):

ReturnTypeFunctionName(inta,int b)

{

}

  • Syntax (in case of structure objects):

ReturnTypeFunctionName(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.
slide18
/*

Program Name: struct.cpp

Author: Nasir

*/

#include<iostream.h>

struct emp

{

int empno;

float salary;

};

slide19
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);

}

slide20
void show(emp t)

{

cout<<”Employee #” << t.empno; cout<<endl;

cout<<”Salary:”<<t.salary;

}

returning structure variables objects
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
slide22
/*

Program Name: struct.cpp

Author: Nasir

*/

#include<iostream.h>

struct emp

{

int empno;

float salary;

};

slide23
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;

}

slide24
emp input(emp t)

{

cout<<"Enter employee number:”;

cin>>t.empno;

cout<<”Enter salary:”;

cin>>t.salary;

return t;

}