ADT Specification Example TYPE Student DOMAIN Each student

  • Slides: 11
Download presentation
ADT Specification Example TYPE Student DOMAIN Each student can be represented by first name,

ADT Specification Example TYPE Student DOMAIN Each student can be represented by first name, last name, id and credit hour. OPERATIONS Set each data member get the real part calculation tuition due print out the students information 1

Representations of student String fname; String last. Name; int id; in credit_hour; 2

Representations of student String fname; String last. Name; int id; in credit_hour; 2

class Student Specification // SPECIFICATION FILE class Student // declares a class data type

class Student Specification // SPECIFICATION FILE class Student // declares a class data type { // does not allocate memory public : // public function members void setlname ( string l ) ; void setfname( string f); void setid(int d); void setcredithour( h); string getfname(); string getlname(); int getid(); int getcredithour(); float calculate_tuition(); void print(); private : string lname; string fname; int id; int credit_hour; // private data members }; 3 3

Use of C++ data Type class l software that uses the class is called

Use of C++ data Type class l software that uses the class is called a client l variables of the class type are called class objects or class instances l client code uses public member functions to handle its class objects 4

Client Code Using Complex #include “student. h” // includes specification of the class int

Client Code Using Complex #include “student. h” // includes specification of the class int main ( ) { student st; cout<<“Enter first name, last name, id and the credit hourn”; cin>>f>>l>>id>>h; st. setlname(l); st. setfname(f); st. setid(id); st. setcredithour(h); float tuition = st. calculate_tuition(); st. print(); cout<< “the tuition due “<< tuition<<endl; } return 0; 5 5

Implementation of set function l Void Student: : setlname(string l) l{ lname = l;

Implementation of set function l Void Student: : setlname(string l) l{ lname = l; l} l // you complete implementations for setid, setfname, setcredithour l 6

Implementation of print function l Void Student: : print() const l{ l l cout<<“First

Implementation of print function l Void Student: : print() const l{ l l cout<<“First Name: “<<fname <<“n. Last Name: “<<lname <<“n. ID: ”<<id <<“n. Credit Hour: “<<credit_hour; l} 7

Implementation of get functions l int Student: : get. ID() l{ l return id;

Implementation of get functions l int Student: : get. ID() l{ l return id; } l // you complete the getlname, getfname, getcredithour l 8

Specification of Student Class Constructors class Complex { public : // Complex. h //

Specification of Student Class Constructors class Complex { public : // Complex. h // function members Student( string f, string l, int d, int h); // constructor Student( ) ; private : string fname; string lname; int id; int credit_hour; }; // default constructor // 2 data members 9 9

Implementation of Complex Default Constructor Complex : : Complex ( ) { fname=“”; lname

Implementation of Complex Default Constructor Complex : : Complex ( ) { fname=“”; lname = “”; id = 0; credit_hour = 0; } 10 10

Implementation of calculate_tuition l Go to CUNY website to find the tuition policy for

Implementation of calculate_tuition l Go to CUNY website to find the tuition policy for undergraduate student who is NY resident l Write the calculation in the function l We will complete in class 11