1 / 27

Computer Science

Computer Science. Data Types. Fundamental Data Types int float double char l ong void. Data Types. Derived Data Types f unctions a rrays p ointers r eferences. Data Types. User Defined Data Types enumerator s tructures c lasses union. Fundamental Data types .

emlyn
Download Presentation

Computer Science

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science

  2. Data Types Fundamental Data Types int float double char long void

  3. Data Types Derived Data Types functions arrays pointers references

  4. Data Types User Defined Data Types enumerator structures classes union

  5. Fundamental Data types Which are already predefined to C++ compiler Examples : int /*Example Start*/ intx; /*Example End*/ x is data element which holds integer values only and 2 bytes of memory has been allocated to it.

  6. Fundamental Data types Which are already predefined to C++ compiler Examples : float /*Example Start*/ float x; /*Example End*/ x is data element which can hold floating point values(real number) and 4 bytes of memory has been allocated to it. Note: x can hold all integer values also

  7. Fundamental Data types Which are already predefined to C++ compiler Examples : float /*Example Start*/ char x; /*Example End*/ x is data element which holds character value and 1 byte of memory has been allocated to it. Note : x can hold ASCII integer value of characters.Eg. x=65; // similar to x=‘A’;

  8. Derived Data types Data types which are comprised of fundamental data types Examples : functions /*Example Start*/ void example(int , int); /*Example End*/ Above function prototype tells that it is non returning function named example and have exactly two arguments of integer type. Note : Returning function should have returning type as ‘ int ‘int example(int , int);

  9. Derived Data types Data types which are comprised of fundamental data types Examples : arrays /*Example Start*/ intarr[10]; /*Example End*/ Note :Above declaration declares 10 integer variables of same name ‘arr’ and allocated memory of 20 bytes(one integer allocated 2 byte)

  10. Derived Data types Data types which are comprised of fundamental data types Examples : pointers /*Example Start*/ int *ptr; /*Example End*/ Note :Above declaration declares pointer named ‘ptr’ which can point to integer variable and has been allocated same memory as integer variable

  11. Derived Data types Data types which are comprised of fundamental data types Examples : references /*Example Start*/ int &ref; /*Example End*/ Note :Above declaration declares reference variable named ‘ref’ which can refer to integer variable and has been allocated same memory as integer variable

  12. User Defined Data types Data types which are comprised of derived and fundamental data types Examples : enumerator /*Example Start*/ enum{first,second,third}; /*Example End*/ Note :Compiler declares each argument as integer constant given value starts from 0.Eg. first is given value 0, second is given value 1, third is given value 2

  13. User Defined Data types Data types which are comprised of derived and fundamental data types Examples : structure /*Example Start*/ struct student { public: introll_no; int marks; }; /*Example End*/ Note : A user defined data type ‘student ’ which having structure of roll_no and marks of student.

  14. User Defined Data types class /*Example Start*/ class student { private: introll_no; int marks; public: void getdata(){ --------- } void display(){ --------- } }; /*Example End*/ Note : A user defined data type ‘student ’ which having structure of roll_no and marks of student along with two functions getdata and display which can operate on these data members

  15. User Defined Data types Data types which are comprised of derived and fundamental data types Remember : Class and Structure are the collection of non-homogeneous data types.We avoid to use functions in structures because they do not possess a data security(which can be given by OOP’s concepts) Whereas we always use functions inside the class to possess data security as class can implement OOP’s concepts. In structures by default means ‘public’ region Keep in mind : we always use data members as public only and avoid functions to use. In classes by default means private Keep in mind : Data members in classes should always be private and functions be public.

  16. Structures A data structure is a group of data elements grouped together under one name. These data elements, known as datamembers, can have different types and different lengths.

  17. Structures Syntax : struct student { int roll; int marks; };

  18. Structures #include<iostream.h> #include<conio.h> struct Student { int roll; int marks; }; void main() { Clrscr(); Student stud; cout<<“Enter the roll no. : \n”; cin>>stud.roll; cout<<“\nEnter the marks : \n”; cin>>stud.marks; cout<<“\nStuden Information :”; cout<<“Roll No. : ”<<stud.roll; cout<<“Marks : ”<<stud.marks; getch(); }

  19. Structures Keep in mind : Private data members are not allowed to be used outside the structure, only public data members are allowed to be used outside the structure. Data members(public) are accessible outside the structure through the object ‘stud’ only. Each data member is accessible outside the structure by object ‘stud’ using dot(.) operator only. All input, output and manipulations are done by using dot(.) operator only

  20. Classes Classes are an expanded concept of data structures: like data structures, they can contain data members, but they can also contain functions as members.Note : Anobject is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

  21. Classes Syntax : class student { private: int roll; int marks; public: void getdata() { } void display() { } };

  22. Classes #include<iostream.h> #include<conio.h> class student { private: int roll; int marks; public: void getdata() { } void display() { } };

  23. Classes void main() { clrscr(); student stud; cout<<“\nInput Student Informations :”; stud.getdata(); cout<<“\nDisplay Student Informations :”; stud.display(); getch(); }

  24. Classes Keep in mind : Private membersare not allowed to be used outside the structure, only public members are allowed to be used outside the structure. Private members are accessible by other members inside the class such as public. Each member inside the class is accessible by another member. Data members(public) are accessible outside the class through the object ‘stud’ only. Each data member is accessible outside the class by object ‘stud’ using dot(.) operator only. All input, output and manipulations are done by using dot(.) operator only. Functions are there to perform all information security purposes or operations over data members.

  25. Classes Most of the time we put one function named ‘ getdata ‘ to input all data members and ‘ display ‘ functions to print all data members values. And other functions to search, append, delete or modify something(will see later on).

  26. Student’s View Student’s should assume class as an unit entity known by object which has all control of class through which we can define class and store data into it or display it and more. Class is more than structure because it possesses OOP’s concept. Dennis Ritchie was who proposed ‘c language’ ended at structures. BjarneStroustrup was who proposed ‘c++ language’(also named as c with classes) extended structure to make classes and gave OOP’s concept in classes.

  27. Dennis Ritchie BjarneStroustrup

More Related