1 / 16

COP3502: Introduction to Computer Science

COP3502: Introduction to Computer Science. Object oriented programming. Yashas Shankar. Object oriented programming. Programming style such that you view data, functions, etc as objects. Human. Right_hand. Left_hand. Right_leg. Left_leg. Body. Object oriented programming. Human.

hills
Download Presentation

COP3502: Introduction to Computer Science

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP3502: Introduction to Computer Science Object oriented programming Yashas Shankar

  2. Object oriented programming • Programming style such that you view data, functions, etc as objects Human Right_hand Left_hand Right_leg Left_leg Body

  3. Object oriented programming Human Right_hand Left_hand Right_leg Left_leg Body Left_hand move hand, move finger, swing, etc Left_leg Move forward, kick, etc

  4. Object oriented programming Human Right_hand Left_hand Right_leg Left_leg Body Left_hand move hand, move finger, swing, etc Left_leg Move forward, kick, etc Void Walk() { Left_leg.move_forward; Right_leg.move_forward } Human walk, etc

  5. Objects • An object contains both data and functions • Functions are usually public data where other function can call • Data are usually kept private • Other functions cannot access that data • Only functions in this object and access the data Class football_team{ Public: void touch_down(); Private: int score; }; Increase the score by six points

  6. Objects Class football_team{ Public: void touch_down(); Private: int score; }; Int main() { football_team FSU; FSU.touch_down(); }

  7. Objects Class football_team{ Public: void touch_down(); Private: int score; }; Int main() { football_team FSU; FSU.touch_down(); } void football_team::touch_down{ score = score + 6; }

  8. Last class Object Football_team public private score Get_score Touchdown Extrapoint Fieldgoal

  9. This class Object Football_match Object Object Football_team Football_team

  10. This class Object Football_match private public Football_team Fucntion#1 Fucntion#2 Football_team … Fucntion#n

  11. This class Object Football_match private public Football_teamhome_team Fucntion#1 Fucntion#2 Football_teamaway_team … score Get_score Touchdown Fucntion#n Extrapoint Fieldgoal

  12. This class Object Football_match private public Football_teamhome_team Football_teamaway_team Fucntion#1 Fucntion#2 name … score Get_score Touchdown Fucntion#n Set_name Extrapoint Fieldgoal Get_name

  13. football_team object #include <string> class football_team { public: int get_score(); void touch_down(); void extra_point(); void field_goal(); void set_score(int a); void set_name(string a); string get_name(); private: int score; string name; }; void football_team::set_name(string a) { name = a; } string football_team::get_name() { return name; }

  14. Object Football_match private public Set_name Football_teamhome_team Set_score Print_score Football_teamaway_team Fucntion#1 Home_touchdown name Fucntion#2 Away_touchdown Home_extrapoint … score Get_score Away_extrapoint Touchdown Fucntion#n Set_name Home_fieldgoal Extrapoint Get_name Fieldgoal Away_fieldgoal

  15. How to access elements in an object Football_match public Assume public Private Set_name Football_teamaway_team Set_score score Touchdown Main() { Football_match match1; match1.Set_name(..); match1.Set_score(..); match1.away_team.Touchdown(); match1.away_team.Set_name(..); match1.away_team.score = 7; match1.away_team.name = “Miami”; } Set_name name Access Denied

  16. private public Football_match Football_teamhome_team home_touchdown Football_teamaway_team set_score int football_match::home_touchdown() { home_team.touch_down(); } name int football_match::set_score(int a, int b) { home_team.set_score(a); away_team.set_score(b); } Set_name score Get_score Get_name Main() { Football_match match1; set_score(0,0); home_touchdown(); { Touch_down Extrapoint Fieldgoal

More Related