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.

Slides:



Advertisements
Similar presentations
PHP functions What are Functions? A function structure:
Advertisements

Engineering Problem Solving With C++ An Object Based Approach Additional Topics Chapter 10 Programming with Classes.
Operator overloading redefine the operations of operators
Starting Out with C++, 3 rd Edition 1 Chapter 11 – Structured Data Abstract data types (ADTs) are data types created by the programmer. ADTs have their.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
1 Chapter 11 Introducing the Class Pages ( )
Introduction to Programming Lecture 39. Copy Constructor.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
1 Abstract Data Types Chapter 1. 2 Objectives You will be able to: 1. Say what an abstract data type is. 2. Implement a simple abstract data type in C++
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Web Application Development Slides Credit Umair Javed LUMS.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
Using Classes to Store Data Computer Science 2 Gerb.
C++ Classes & Data Abstraction
1 Inheritance Concepts n Derive a new class (subclass) from an existing class (base class or superclass). n Inheritance creates a hierarchy of related.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Important Definitions Class: A structured data type that is used to represent an abstract data type (ADT) Class member: A components of a class. It can.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
ADT Specification Example
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
1 Lecture 29 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
1 Abstract Data Type (ADT) a data type whose properties (domain and operations) are specified (what) independently of any particular implementation (how)
1 Chapter 14-2 Object- Oriented Software Development Dale/Weems.
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
1 Chapter 14 Object- Oriented Software Development Dale/Weems.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
CS1201: Programming Language 2 Classes and objects By: Nouf Aljaffan Edited by : Nouf Almunyif.
CS 210 DATA STRUCTURES AND ALGORITHIMS Fall 2006.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Classes Structured Programming 256 Chapter 8 Classes - Part I OOP & Class Object Terminology File Management.
Lecture 06 Java and OOP Jaeki Song. Outlines Java and OOP –Class and Object – Inheritance – Polymorphism.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Class Student class Student { private: string id; string firstName, lastName; float gpa; public: void Read() void Write() string getGPA() void setGPA(
C++ Lecture 5 Monday, 18 July Chapter 7 Classes, continued l const objects and const member functions l Composition: objects as members of classes.
CSC241 Object-Oriented Programming (OOP) Lecture No. 5.
1 2/21/05CS250 Introduction to Computer Science II Destructors, Get and Set, and Default Memberwise Assignment.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
February 28, 2005 Introduction to Classes. Object Oriented Programming An object is a software bundle of related variables and methods. Software objects.
Classes in C++ And comparison to Java CS-1030 Dr. Mark L. Hornick.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
MANY-TO-MANY MAPPING. May 12, 2011  Implemented using a Set java collection  Mediator table is mandatory – Join table  Join table contains foreign.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Chapter 12 Classes and Abstraction
Andrew(amwallis) Classes!
Chapter 7: Introduction to Classes and Objects
COMPUTER 2430 Object Oriented Programming and Data Structures I
Anatomy of a class Part II
CS 1430: Programming in C++.
CS 1430: Programming in C++.
Classes and Data Abstraction
Classes & Objects: Examples
Domain Classes Chapter 9.
Constant Member Functions
Anatomy of a class Part II
CS148 Introduction to Programming II
Destructors, Copy Constructors & Copy Assignment Operators
Code Organization Classes
Destructors, Copy Constructors & Copy Assignment Operators
Chapter 11 Classes.
Chapter 5 Classes.
Presentation transcript:

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 Representations of student String fname; String lastName; int id; in credit_hour;

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 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 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 Implementation of set function Void Student::setlname(string l) { lname = l; } // you complete implementations for setid, setfname, setcredithour

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

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

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 Implementation of Complex Default Constructor Complex :: Complex ( ) { fname=“”; lname = “”; id = 0; credit_hour = 0; } 10

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