Your SlideShare is downloading. ×
Presentation on structure,functions and classes
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Presentation on structure,functions and classes

853

Published on

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
853
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
77
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.  
  • 2.
    • Arrays can be used to represent a group of data items that belong to the same type, such as int or float .
    • If we want to represent a collection of data items of different types using a single name then we cannot use an array.
    • The data type which we use is known as structure.
    • Structure is user defined data type.
  • 3.
    • struct struct_name
    • {
    • data_type member1;
    • data_type member2;
    • … …
    • };
  • 4.
    • //header files
    • #include<stdio.h>
    • #include<conio.h>
    • //Structure declaration
    • struct student
    • {
    • // data types & members
    • int rollno;
    • char name[20];
    • };
  • 5.
    • void main ()
    • {
    • struct student S1; // Structure variable
    • printf( “Input the name of student “ );
    • scanf( “%d” ,&S1.name);
    • printf( “Input the Roll number of student “ );
    • scanf( “%d” ,&S1.rollno);
    • printf( “name =%d“ S1.name);
    • printf( “Roll number=%d“ S1.rollno);
    • getch();
    • }
  • 6.
    • Input the name of student abc
    • Input the Roll number of student 1
    • name = abc
    • Roll number = 1
  • 7. rollno name 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 20 21
  • 8.
    • Unions are a concept borrowed from structures and therefore follow the same syntax as structures .
    • There is a major difference between them in terms of storage .
    • A union may contain many members of different types ,it can handle only one member at a time.
  • 9.
    • union union_name
    • {
    • data_type member1;
    • data_type member2;
    • … …
    • };
  • 10.
    • //header files
    • #include<stdio.h>
    • #include<conio.h>
    • //Union declaration
    • union student
    • {
    • // data types & members
    • int rollno;
    • char name[20];
    • };
  • 11. void main () { union student S1; // Union variable printf( “Input the name of student “ ); scanf( “%d” ,&S1.name); printf( “Input the Roll number of student “ ); scanf( “%d” ,&S1.rollno); printf( “name =%d“ S1.name); printf( “Roll number=%d“ S1.rollno); getch(); }
  • 12.
    • Input the name of student abc
    • Input the Roll number of student 1
    • name = abc
    • Roll number = 1
  • 13. name rollno 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9
  • 14.
    • Classes are same as structure but with a small difference ie. Structure are having data only(int or float) but classes are having data and functions together.
    • The class has a mechanism to prevent direct access to its members ,which is the central idea of object-oriented programming.
    • Classes are user defined data types.
    • In short structure + functions = classes.
  • 15.
    • A class definition begin with the keyword class.
    • The body of the class is contained with in the brace { };
    Class Data Functions
  • 16.
    • class <name of class>
    • {
    • private:
    • declaration of variables ;
    • declaration of functions ;
    • public:
    • declaration of variables ;
    • declaration of functions;
    • };
  • 17.
    • // Header files
    • #include<iostream.h>
    • #include<conio.h>
    • class student // class declaration
    • {
    • private:
    • int rollno; // data members
    • char name[20];
    • public:
    • void getdata(); // functions
  • 18.
    • // defining member function inside the class definition
    • void display()
    • {
    • cout<< “Name=“ <<name<<endl;
    • cout<< “Roll number=“ <<rollno<<endl;
    • }
    • };
  • 19.
    • // defining member functions outside the class definition
    • void student :: getdata()
    • {
    • cout<< “Input the name of student” ;
    • cin>>name;
    • cout<< “Input the roll number” ;
    • cin>>rollno;
    • }
  • 20.
    • main()
    • {
    • cout<< “We are in main function “ ;
    • student S1; // creat object S1
    • S1.getdata(); // call member function
    • S1.display(); // call member function
    • getch();
    • }
  • 21.
    • Input the name of student abc
    • Input the roll number 1
    • Name = abc
    • Roll number = 1
  • 22.  
  • 23.  

×