ComputerProgrammingandBasicSoftwareEngineering5.ObjectsandClassesinC++.Ratherthan givingyour customer theStatic Libraryexecutable codes,you can givehima(static) library.Inside a library, it does not contain theexecutable codes, butthe object codesHeader-machine code waiting for linkinglibrarySince object codes cannot be readdirectly,your customer cannot modifyyour codes.To enable your customertoknow howto useyour class,give also yourcustomer a header file that containsthe definition of your class
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ Static Library • Rather than giving your customer the executable codes, you can give him a (static) library. • Inside a library, it does not contain the executable codes, but the object codes – machine code waiting for linking. • Since object codes cannot be read directly, your customer cannot modify your codes. • To enable your customer to know how to use your class, give also your customer a header file that contains the definition of your class. Header library
ComputerProgrammingandBasicSoftwareEngineering5.Objects and Classes in C++Explain whyCatClass.hpublicand privatemain(oftheCustomerclassCATMain ProgramShow that theYMainProject.cppclassCAT has a#include"CatClass.h"public:public functionint GetAgeO;called GetAge()void maino)1Itwillreturn an;integer.CATFrisky,Age=Frisky.GetAge;Library10202d355f4323Containthe4323...implementationofGetAge(),however, theWhenthecustomerbuildsthemain(),itsource code226flinkswithCatclass.handthe library....2144dd23cannot be seen bythe customer
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ Main Program main() of the Customer #include "CatClass.h" void main() { CAT Frisky; Age = Frisky.GetAge(); } MainProject.cpp : : { public: int GetAge(); }; CatClass.h : : class CAT Library 10 20 2d 35 5f 43 23 43 23 . . 22 6f . 21 44 dd 23 Contain the implementation of GetAge(), however, the source code cannot be seen by the customer. Show that the class CAT has a public function called GetAge() It will return an integer. : Explain why public and private When the customer builds the main(), it links with CatClass.h and the library
ComputerProgrammingand BasicSoftwareEngineering5.ObjectsandClassesinC++ModularProgramDesignBesides doing business with classes, the use of static libraryalso facilitates modular program design.The system analyst analyses the requirement of a programand divides itinto a number of modules.The specifications of each module, such as its functions, thecalling methods, the parameters returned, are well defined.Based on the specifications,thedevelopment of eachmodule will be done by differentprogrammers.Very useful forteamwork
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ Modular Program Design • Besides doing business with classes, the use of static library also facilitates modular program design. • The system analyst analyses the requirement of a program and divides it into a number of modules. • The specifications of each module, such as its functions, the calling methods, the parameters returned, are well defined. • Based on the specifications, the development of each module will be done by different programmers. Very useful for team work
ComputerProgrammingandBasicSoftwareEngineering5.Objects and Classes in C++Example-step1:obtaintherequirementsThe system analyst talks with the customer and obtains thefollowingprogram requirements:Aprogramis to bedesigned to showazoothatcontains differentkind of animals, including dog, cat,sheep,and horse.At the beginning of the program, all animals aredrawn on the screen.When user clicks on an animal, the sound ofit isplayed
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ Example – step 1: obtain the requirements • A program is to be designed to show a zoo that contains different kind of animals, including dog, cat, sheep, and horse. • At the beginning of the program, all animals are drawn on the screen. • When user clicks on an animal, the sound of it is played. • The system analyst talks with the customer and obtains the following program requirements:
ComputerProgrammingandBasicSoftwareEngineering5.ObjectsandClassesinC++Example-step2:designtheprogramflowStartBased on therequirements,thesystem analystDrawanimaldesigns theprogram flowNoAllanimaldrawn?using, forexample,aflowYesBchart.NoUserclickonanimal?YesA
Computer Programming and Basic Software Engineering 5. Objects and Classes in C++ Example – step 2: design the program flow • Based on the requirements, the system analyst designs the program flow using, for example, a flow chart. Start All animal drawn? User click on animal? No Yes A No Yes B Draw animal