Upload
melissa-hart
View
234
Download
0
Embed Size (px)
Citation preview
CS 210 DATA STRUCTURES AND ALGORITHIMS
Fall 2006
CS 210
Instructor Mrs. Sarab Almuhaideb.
Office: W357 Phone: 4535189 Ext.# 711 Email: [email protected]
Office Hours: SUN 12:00 – 1:00,MON 9:00 – 10:50, (or by appointment)
CS 210
CS 210 CS 210 : Data Structures and Algorithms. Credit Hours: 3. Prerequisite: CS 102. Course Home Page:
Visit http://www.geocities.com/pscw_cs210 to find course announcements, notes, important dates ,assignments, grades and more.
CS 210
Abstract Data Types
ADT: is the study of classes of objects whose logical behavior is defined by a set
of values and a set of operations.
CS 210
Data Structures
The term Data Structures refers to the study of data and how to present objects
within a program; that is, the implementation of the structured
relationships.
We are now interested in the study of the abstract properties of classes of data objects in addition to how the objects might be represented in a program.
CS 210
It is well known that data structures have a profound effect on the performance of programs and applications. The main purpose of this course is to introduce the main types of data structures and illustrate their use throughout simple examples and applications. In the process, some guidelines and principles for good programming and application development are given.
Course Objectives
CS 210
Text Book
ADT, Data Structures and ADT, Data Structures and Problem Solving with C++, 2Problem Solving with C++, 2ndnd Edition. Edition.
By Larry Nyhoff, By Larry Nyhoff,
Prentice Hall, 2004. Prentice Hall, 2004.
CS 210
Evaluation
Grading: Major 1 20%. Major 2 20%. Assignments 15%. Quizzes 10%. Final 35%.
No make-up exams.
CS 210
Important Dates Major I Exam:
Monday November 8, 2006 [8-10]. Major II Exam:
Monday December 11, 2006 [8-10]. Quizzes:
Quiz 1: Sunday October 1, 2006.Quiz 2: Sunday November 19, 2006.Quiz 3: Sunday December 3, 2006.
Final Exam: During the period Jan 20 – 30, 2007.
CS 210
Course Policy1. There will be weekly tutorial problems as well as bi-weekly programming
projects.2. Students are encouraged to solve the tutorial problems before we do them
together in class, but are NOT required to submit their solutions.3. 15% of your grade will be assigned to PROGRAMMING projects.4. Homework assignments must be done individually( or in pairs as stated in
the project’s requirements). 5. We do not expect to see two programming projects that look identical. In this
case, BOTH projects will be rejected.6. Please note the due date for your programming project.7. Late projects will be grade-penalizes or might not be accepted at all.8. This course adopts the drop-the-lowest policy for assignments and quizzes.9. All source files must be compiled and fully tested by the student before
submission.10. A program that does not compile is not accepted for any reason.11. Also, a program with no output is not accepted. 12. A program must be submitted in both electronic copy (the .cpp file) and hard
copy. 13. Make sure the floppy is labeled with your name and the assignment number.14. If a student was absent in any lecture, then she is expected to read the lecture
material and is welcomed for any specific question she may has.
CS 210
Data Structures
Revision: Classes and Abstract Data Types
Please read notes page for details.Please read notes page for details.
CS 210
Abstraction
Captures essential qualities of an object and names the object.
Ignores implementation details
Is necessary for managing large, complex software projects.
CS 210
Data Hiding
Hides implementation details from user
Prevents user from accessing implementation directly
User must interact with object through an interface.
CS 210
Hierarchical Design- an Example
CIS
Carnet Lab Scheduling Radiology
CT Scan
Patient Registration
X-Ray MRI UltrasoundOrder
Lab Order
Radiology Order
Appointment
Documen-tation
Gen. Lab AP Micro BB
CS 210
Classes in C++
A class is a means of abstraction in C++
A class is a specification of a group of objects that all have the same essential properties and behaviors.
FOR EXAMPLE . . .
CS 210
A class exampleclass
Student
Properties (data members)name, graduation year, list of courses, number of courses
Operations (methods)List CoursesList Student InformationAdd a CourseSet Graduation Date
CS 210
C++ Data Type class represents an ADT
2 kinds of class members: Data members and function members
Class members are private by default
Data members are generally private
Function members are generally declared public
Private class members can be accessed only by the class member functions (and friend functions), not by client code.
CS 210
class type declarationThe class declaration creates a data type
and names the members of the class.
It does not allocate memory for any variables of that type!
Client code still needs to declare class variables.
CS 210
An object is an instance of a class
For example:object
studentAName: Andrea StudentGraduation Year: 2005List of Courses: CSCI262, MATH331Number of courses: 6
CS 210
2 separate files generally used for class type
// SPECIFICATION FILE ( student .h ) // Specifies the data and function members. class Student { public: . . .
private: . . . } ;
// IMPLEMENTATION FILE (student.cpp ) // Implements the Student member functions. . . .
CS 210
Class Student Specification// SPECIFICATION FILE ( student.h )typedef char string9[10];
class Student // declares a class data type{ // does not allocate memory
public : // 5 public function membersvoid AddCourse(string9 CourseName);void ListCourses(void) const;void ListInfo(void) const;void SetGradDate(int year);Student(); // Constructor Function
private : // 4 private data memberschar studentName[30];string9 courses[6];int numCourses;int gradDate;
} ;
CS 210
Implementation file for Student
// IMPLEMENTATION FILE ( student.cpp ) // Implements the Student member functions.
#include “ student.h” // also must appear in client code
#include <iostream.h> . . .
void Student :: SetGradDate (int year ) { gradDate = year; }
. . .
CS 210
Class Constructors initialize Data Members
// In the file student.cppStudent :: Student () { //Default Constructor
numCourses = 0;gradDate = 0;strcpy(studentName, “John Doe”);
}
// This is invoked in client code at time of object declaration:// Student newStudent(“Mary Contrary”, 2010);Student :: Student(char name[ ], int year) { //Constructor with
parameters//We will fill this out in class!
}
CS 210
Use of C++ data type class
Facilitates re-use of C++ code for an ADT.
Software that uses the class is called a client.
Variables of the class type are called objects or instances of the class.
Client code uses public member functions to handle its class objects.
Private members cannot be directly accessed by client code. It can only be accessed by member functions.
CS 210
#include “student.h” // includes specification of the class#include <iostream.h>int main ( void ){
int newYear;string9 newCourse;Student newStudent; // create new Student object
cout << “Enter graduation year: “;cin >> newYear;newStudent.SetGradDate(newYear); // set Graduation datecout << “Enter course to be added: “;cin >> newCourse;newStudent.AddCourse(newCourse); // Add a course
newStudent.ListInfo(); // List Student informationnewStudent.ListCourses(); // List courses
} // end of main
Client Code Using Student