Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ADT Specification Example TYPE Student DOMAIN Each student can be represented by first name, last name, id and credit hour. OPERATIONS Set each data.

Similar presentations


Presentation on theme: "1 ADT Specification Example TYPE Student DOMAIN Each student can be represented by first name, last name, id and credit hour. OPERATIONS Set each data."— Presentation transcript:

1 1 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

2 2 Representations of student String fname; String lastName; int id; in credit_hour;

3 3 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 :// private data members string lname; string fname; int id; int credit_hour; } ; 3

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

5 5 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 hour\n”; 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

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

7 7 Implementation of print function Void Student::print() const { cout<<“First Name: “<<fname <<“\nLast Name: “<<lname <<“\nID: ”<<id <<“\nCredit Hour: “<<credit_hour; }

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

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

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

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


Download ppt "1 ADT Specification Example TYPE Student DOMAIN Each student can be represented by first name, last name, id and credit hour. OPERATIONS Set each data."

Similar presentations


Ads by Google