Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using.

Similar presentations


Presentation on theme: "1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using."— Presentation transcript:

1 1 Object-Oriented Programming Using C++ CLASS 1

2 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using C++ programming language. Topics covered will include classes, both single and multiple inheritance, templates, polymorphism, exception handling and file processing.

3 3 Review of Syllabus Textbook Data Abstraction & Problem Solving with C++ by Frank Carrano, 5 th edition Instructor Kamran Khan Office Hours kkhan@engr.smu.edu@engr.smu.edu

4 4 Review of Syllabus Catalog Description Course Requirements and Method of Evaluation –Test #1125 –Test #2125 –Test #3125 –Homework 10 each –Programs 30 each – Pop Quizzes 15 each –Project100

5 5 Grading Example 1200 possible points Highest score of 1150 You collected 920

6 6 Grading Example 1200 possible points Highest score of 1150 You collected 920 920 1150 x 100 = 1150 92000 9200 80 B

7 7 Course Competencies Use the C++ preprocessor Explain the use of overloading operators Design and code an inheritance hierarchy

8 8 Course Competencies Explain the use of overloading of function names Create a library of functions which can process data as objects Understand memory management and dynamic allocation Use a virtual function to demonstrate polymorphism

9 9 Course Competencies Demonstrate a knowledge of an “is a” and “has a” relationship between classes Write a C++ program using sequential and random file processing Use exception handling techniques Write a class template and a driver to use it

10 10 Assignments L: Programs due Monday 10pm of the week assigned, uploaded into your Blackboard folder the following files: All source (.cpp) files UML files All header (.h) files Executable (.out) file H:Homework due at the beginning of class lecture, Thursday, can be hand-written

11 11 Late Assignments Homework assignments will not be accepted late Labs (programs) can be turned in the 48 hours late, by special permission/request for a late folder approved by instructor; 10 late points will be deducted.

12 12 Explanation of Transmission of Assignments Programming assignments will be submitted via Blackboard Next week’s lab will take you through the requirements for Blackboard, Unix logins, Unix executable files, and other information related to your programming assignments ATTENDANCE IS MANDATORY

13 13 Scholastic Dishonesty Policy Outside assistance other than from your ta, instructor, or university tutoring service is considered scholastic dishonesty Looking at/copying from another student’s work is considered scholastic dishonesty A single incident results in a zero for that work for yourself and the person you copied from; multiple incidents results in an F in the class and a report to the Honors Council

14 14 Introduction to C++ Classes Encapsulation combines an ADT’s data with its operations to form an object An object is an instance of a class A class defines a new data type A class contains data members and methods (member functions) By default, all members in a class are private –But you can specify them as public Encapsulation hides implementation details

15 15 C++ Classes Figure 3-10 An object’s data and methods are encapsulated

16 16 C++ Classes vs Java classes Each class definition is placed in a header file Classname.h The implementation of a class’s methods are placed in an implementation file Classname.cpp

17 17 C++ Classes: The header file /** @file Sphere.h */ const double PI = 3.14159; class Sphere {public: Sphere(); // Default constructor Sphere(double initialRadius); // Constructor void setRadius(double newRadius); double getRadius() const; // can’t change data members double getDiameter() const; double getCircumference() const; double getArea() const;

18 18 C++ Classes: The header file double getVolume() const; void displayStatistics() const; private: double theRadius; // data members should be private }; // end Sphere interface file

19 19 C++ Classes: Constructors Constructors Create and initialize new instances of a class –Invoked when you declare an instance of the class Have the same name as the class Have no return type, not even void A class can have several constructors A default constructor has no arguments The compiler will generate a default constructor if you do not define any constructors

20 20 C++ Classes: Constructors The implementation of a method qualifies its name with the scope resolution operator :: The implementation of a constructor Sets data members to initial values –Can use an initializer Sphere::Sphere() : theRadius(1.0) { } // end default constructor Cannot use return to return a value

21 21 C++ Classes: Destructors Destructor Destroys an instance of an object when the object’s lifetime ends Each class has one destructor For many classes, you can omit the destructor The compiler will generate a destructor if you do not define one –For now, we will use the compiler’s destructor

22 22 C++ Classes: The implementation file /** @file Sphere.cpp */ #include #include "Sphere.h" // header file using namespace std; Sphere::Sphere() : theRadius(1.0) { } // end default constructor Sphere::Sphere(double initialRadius) { if (initialRadius > 0) theRadius = initialRadius; else theRadius = 1.0; } // end constructor

23 23 C++ Classes: The implementation file void Sphere::setRadius(double newwRadius) { if (newRadius > 0) theRadius = newRadius; else theRadius = 1.0; } // end setRadius The constructor could call setRadius

24 24 C++ Classes: The implementation file double Sphere::getRadius() const { return theRadius; } // end getRadius... double Sphere::getArea() const { return 4.0 * PI * theRadius * theRadius; } // end getArea...

25 25 C++ Classes: Using the class Sphere #include #include "Sphere.h" // header file using namespace std; A mechanism for logically grouping declarations and definitions into a common declarative region Items declared in the C++ Standard Library are declared in the std namespace You include files for several functions declared in the std namespace To include input and output functions from the C++ library, write #include using namespace std;

26 26 C++ Classes: Using the class Sphere int main() // the client { Sphere unitSphere; Sphere mySphere(5.1); cout << mySphere.getDiameter() << endl; // C++’s version of screen output // more on cout later } // end main

27 27 Q & A


Download ppt "1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using."

Similar presentations


Ads by Google