















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Chanky Rathin at Object Oriented Programming and Data Structures at Anna University of Technology. It includes: C, C , , Object, Oriented, Programming, Classes, Fields, Methods, Representation, Variant, Binary
Typology: Slides
1 / 55
This page cannot be seen from the preview
Don't miss anything!
















































Day 4: Object-oriented programming in C++ Eunsuk Kang and Jean Yang
Why objects? Object-oriented programming (OOP) in C++ � classes � fields & methods � objects � representation invariant 2
computers just manipulate 0’s and 1’s Figure by MIT OpenCourseWare.
5
High-level languages � simpler to write & understand � more library support, data structures Low-level languages � closer to hardware � more efficient (but also dangerous!) What about C++? 7
Objects model elements of the problem contextEach object has: � characteristics � responsibilities (or required behaviors) 8
Problem Computation modeling in biology Write a program that simulates the growth of viruspopulation in humans over time. Each virus cellreproduces itself at some time interval. Patients mayundergo drug treatment to inhibit the reproductionprocess, and clear the virus cells from their body.However, some of the cells are resistant to drugs andmay survive. 10
Write a program that simulates the growth of viruspopulation in humans over time. Each virus cellreproduces itself at some time interval. Patients mayundergo drug treatment to inhibit the reproductionprocess, and clear the virus cells from their body.However, some of the cells are resistant to drugs andmay survive. What are objects?Characteristics?Responsibilities? 11
Patient characteristics � virus population � immunity to virus (%) responsibilities � take drugs Virus characteristics � reproduction rate (%) � resistance
responsibilities � reproduce � survive 13
Why didn’t we model an object named Doctor?Surely, most hospitals have doctors, right? 14
A class is like a cookie cutter; it defines the shape ofobjectsObjects are like cookies; they are instances of the class 17 Photograph courtesy of Guillaume Brialon on Flickr.
class Virus { float reproductionRate; // rate of reproduction, in % float resistance; // resistance against drugs, in % static const float defaultReproductionRate = 0.1; public: Virus(float newResistance); Virus(float newReproductionRate, float newResistance); Virus* reproduce(float immunity); bool survive(float immunity); }; 20