<ul><li>Arrays can be used to represent a group of data items that belong to the same type, such as  int  or  float  . </l...
<ul><li>struct  struct_name </li></ul><ul><li>{ </li></ul><ul><li>data_type member1; </li></ul><ul><li>data_type member2; ...
<ul><li>//header  files </li></ul><ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>//Struct...
<ul><li>void main () </li></ul><ul><li>{ </li></ul><ul><li>struct student  S1; // Structure variable  </li></ul><ul><li>pr...
<ul><li>Input the name of student  abc </li></ul><ul><li>Input the Roll number of student  1 </li></ul><ul><li>name = abc ...
rollno name 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9 20 21
<ul><li>Unions are a concept borrowed from structures and therefore follow the same syntax as structures . </li></ul><ul><...
<ul><li>union union_name </li></ul><ul><li>{  </li></ul><ul><li>data_type member1; </li></ul><ul><li>data_type member2; </...
<ul><li>//header  files </li></ul><ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>//Union ...
void main () { union student  S1; // Union variable  printf( “Input the name of student “ ); scanf( “%d” ,&S1.name); print...
<ul><li>Input the name of student  abc </li></ul><ul><li>Input the Roll number of student  1 </li></ul><ul><li>name = abc ...
name rollno 10 11 12 13 14 15 16 17 18 19 0 1 2 3 4 5 6 7 8 9
<ul><li>Classes are same as structure but with a small difference  ie. Structure are having data only(int or float) but cl...
<ul><li>A class definition begin with the keyword  class. </li></ul><ul><li>The body of the class is contained with in the...
<ul><li>class  <name of class> </li></ul><ul><li>{ </li></ul><ul><li>private: </li></ul><ul><li>declaration of variables ;...
<ul><li>// Header files </li></ul><ul><li>#include<iostream.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>class...
<ul><li>// defining member function inside the class definition   </li></ul><ul><li>void display() </li></ul><ul><li>{ </l...
<ul><li>//  defining member functions outside the class definition </li></ul><ul><li>void student :: getdata() </li></ul><...
<ul><li>main() </li></ul><ul><li>{ </li></ul><ul><li>cout<< “We are in main function “ ; </li></ul><ul><li>student S1;  //...
<ul><li>Input the name of student abc </li></ul><ul><li>Input the roll number 1 </li></ul><ul><li>Name = abc  </li></ul><u...
 
 
Upcoming SlideShare
Loading in...5
×

Presentation on structure,functions and classes

889

Published on

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

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

No notes for slide

Presentation on structure,functions and classes

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

    Clipping is a handy way to collect important slides you want to go back to later.

×