Abstract Data Types "ADT" in C++ and Visual Studio.

Abstract
Data Types

Noun: "...an abstract data type is programmer-defined and composed of one or more primitive data types...It is defined by the operations that may be performed on it and mathematical constraints on the effects of those operations..."

In other words . . . it's a data type you create to do what you want.

It can hold both data & operations.


Cecklist

  1. Declare your ADT in the header (.h file)
  2. Use protected, private, and public accordingly
  3. Include the .h file
  4. Use your ADT with operators



1.Declare your ADT in the header (.h file):


2.  Use protected, private, and public accordingly



//------------------     in student.h file   --------------------------//

     class Student {
          public:
             void addGrade( int TestScore );

          private: 
             int studentID;
     }



3.  Include the .h file

#include
#include <"student.h">
#using namespace std;

int main()
{
     Student aStudent = new Student;
     
     system("pause");
     return 0;
}

4.  Use your ADT with operators

int main()
{
     Student aStudent = new Student;
     
     aStudent.addGrade(86);  
     system("pause");
     return 0;
}

tips:
1.  Use the dot operator (.)  to access public properties
example:  aStudent.addGrade(86);


2.  For a pointer that points to an instance of an ADT, use "->" to access data members.

example:
Student aStudent;
Student *sPointer;

sPointer = &aStudent;
sPointer->addGrade(50);

/*Note: this method merely uses pointers to accomplish the same task as aStudent.addGrade(86); */

content created from this youtube video.







No comments:

Post a Comment

2 ads