object oriented programming using c n.
Skip this Video
Download Presentation
Object-Oriented Programming Using C++

Loading in 2 Seconds...

play fullscreen
1 / 27

Object-Oriented Programming Using C++ - PowerPoint PPT Presentation

  • Uploaded on

Object-Oriented Programming Using C++. CLASS 1. Review of Syllabus Catalog Description

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Object-Oriented Programming Using C++' - miracle

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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.
Review of Syllabus
    • Textbook Data Abstraction & Problem Solving with C++ by Frank Carrano, 5th edition
    • InstructorKamran KhanOffice Hours kkhan@engr.smu.edu
Review of Syllabus
    • Catalog Description
    • Course Requirements and Method of Evaluation
      • Test #1 125
      • Test #2 125
      • Test #3 125
      • Homework 10 each
      • Programs 30 each
      • Pop Quizzes 15 each
      • Project 100
Grading Example
    • 1200 possible points
    • Highest score of 1150
    • You collected 920






80 B




  • Grading Example
    • 1200 possible points
    • Highest score of 1150
    • You collected 920
Course Competencies
    • Use the C++ preprocessor
    • Explain the use of overloading operators
    • Design and code an inheritance hierarchy
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
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

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) filesExecutable (.out) file

H: Homework due at the beginning of class lecture, Thursday, can be hand-written

late assignments
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.

explanation of transmission of assignments
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 assignmentsATTENDANCE IS MANDATORY
scholastic dishonesty policy
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
introduction to c classes
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
c classes
C++ Classes

Figure 3-10

An object’s data and methods are encapsulated

c classes vs java classes
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
c classes the header file
C++ Classes: The header file

/** @file Sphere.h */

const double PI = 3.14159;

class Sphere


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;

c classes the header file1
C++ Classes: The header file

double getVolume() const;

void displayStatistics() const;


double theRadius;

// data members should be private

}; // end Sphere interface file

c classes constructors
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
c classes constructors1
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
c classes destructors
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
c classes the implementation file
C++ Classes: The implementation file

/** @file Sphere.cpp */

#include <iostream>

#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;


theRadius = 1.0;

} // end constructor

c classes the implementation file1
C++ Classes: The implementation file

void Sphere::setRadius(double newwRadius)


if (newRadius > 0)

theRadius = newRadius;


theRadius = 1.0;

} // end setRadius

  • The constructor could call setRadius
c classes the implementation file2
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

. . .

c classes using the class sphere
C++ Classes: Using the class Sphere

#include <iostream>

#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 <iostream>

usingnamespace std;

c classes using the class sphere1
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