- This time, I would be expecting that you will have programs in *.cpp files and optional *.h files in your zipped folders (not *.txt or *.docx).
Below are what are needed for the Assignment 2c:- two programs in C++ files (saved as *.cpp or *.h) for Module 4.1 activities
- two programs in C++ files (saved as *.cpp and/or *.h) for Module 4.2 activities
Please send in the "Assessment 2c - Submission" and attach it as a zip file. Please use the naming convention MIS501_T2_ Asessement_2c.zip like MIS501_T2_Infante_William_Asessement_2c.zip
activities 4,1 4.2 need to be done attached below
7/30/2019 Laureate International Universities https://laureate-au.blackboard.com/webapps/blackboard/content/listContent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 1/6 MODULE 4 - OBJECT-ORIENTEDMODULE 4 - OBJECT-ORIENTED PROGRAMMINGPROGRAMMING 4.1 Objects, Classes and Methods You should start by reviewing the following video: The video introduces you to the four principles of object orientation: encapsulation – we group data and functions together into an object; abstraction – the details and complexity of the object is hidden; inheritance – redundant code does not need to be re- implemented; and polymorphism – a word that means ‘many forms’ and allows the programmer to work with inherited code to simplify program execution. Each of the principles of object-oriented programming tends to focus on programming e�ciency by helping to solve some of the problems that procedural programming brought with it. Procedural programming that features functions at its core can lead to complicated code since changes in any one of the functions may need to be correlated and updated in other functions. However, with object-oriented programming, functions will tend to have fewer arguments, can have the same names and result in fewer lines of code. Therefore, object-oriented programming aims to reduce complexity in programming code and allow you to focus on greater capabilities in your programming outputs. This opening video gracefully introduces the ideas behind object- oriented programming and sets the scene for the remainder of our discussion in the �rst half of this module. At this early stage, however, you might still be wondering what an object actually is. With object- oriented programming our terminology changes slightly and we no longer refer to capturing data in terms of variables but instead as ‘members’ and object functions as ‘methods.’ Like in the video, we can 7/30/2019 Laureate International Universities https://laureate-au.blackboard.com/webapps/blackboard/content/listContent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 2/6 imagine an example object such as a car. A car will have the following members (and several others): colour; brand; fuel tank capacity; and odometer reading. Apart from this, it may also have the following methods: start(); accelerate(); brake(); and stop(). The car can be thought of as an object since it has characteristics (members) such as its colour and it can perform operations (methods) on itself such as accelerating and braking. In this analogy, it can be easily seen that a car object is self-contained or encapsulated. The mechanical details of how the car performs its operations does not matter to the driver since they are using the car to travel from their point of origin to their point of destination; therefore, we can see that the details have been abstracted or hidden away. Up until now we have discussed a car as a single object. But, as we know, there can be several cars, even several red cars of the same make and model. Therefore, the object-oriented paradigm includes a mechanism to specify what all of those cars would look and behave like. That mechanism is called a class and is a central concept in object-oriented programming. A class is said to be the template for all objects in that family of objects. In your programming you will implement the members and methods in the above two lists in a class. When you later initialise a car object, the object is an instance of a class. You would specify a class in the following way: class Car { string strColour; string strBrand; float fltFuelTankCapacity; int intOdometerReading; public: void start(); void accelerate(); 7/30/2019 Laureate International Universities https://laureate-au.blackboard.com/webapps/blackboard/content/listContent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 3/6 void brake(); void stop(); }; Like the convention we have already established in this subject, a class must �rst be declared before we can refer to it later in the code. Noticing that the declaration has a semicolon that follows it, the next lines of code would be the implementations of the class methods. This is shown below. void Car::start() { return; } void Car::accelerate() { return; } void Car::brake() { return; } void Car::stop() { return; } At present these methods do not actually do anything. However, the �rst thing to notice here is that the functions must have the scope or the class to which they belong. The compiler then knows that you are implementing the start() method of the Car class (and so on). So far we have demonstrated that object-oriented programming allows the grouping of members and methods so it facilitates encapsulation. The example above allows direct access to an object’s members, which is not a good idea. Therefore, a slight adjustment is needed here to ‘hide’ or abstract the details and this is demonstrated in the following example code segment. #include
#include using namespace std; class Car { private: string strColour; string strBrand; float fltFuelTankCapacity; int intOdometerReading; public: void start(); void accelerate(); void brake(); void stop(); void setColour(string); void setBrand (string); void setFuelTankCapacity(float); 7/30/2019 Laureate International Universities https://laureate-au.blackboard.com/webapps/blackboard/content/listContent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 4/6 void setOdometerReading(int); string getColour(); string getBrand(); float getFuelTankCapacity(); int getOdometerReading(); }; void Car::start() { return; } void Car::accelerate() { return; } void Car::brake() { return; } void Car::stop() { return; } void Car::setColour(string strTempColour) { strColour = strTempColour; return; } void Car::setBrand(string strTempBrand) { strBrand = strTempBrand; return; } void Car::setFuelTankCapacity(float fltTempCapacity) { fltFuelTankCapacity = fltTempCapacity; return; } void Car::setOdometerReading(int intTempOdometerReading) { intOdometerReading = intTempOdometerReading; return; } string Car::getColour() { return strColour; } string Car::getBrand() { return strBrand; } float Car::getFuelTankCapacity() { return fltFuelTankCapacity; } int Car::getOdometerReading() { return intOdometerReading; } The code segment above includes the class members and methods and then implements the methods immediately following the declaration of the class. Since the members are labelled ‘private’ we are saying to the compiler that we only want the object to be able to access its own private parts; anybody who programs with the object should not be allowed to directly access the private members. To facilitate this privacy, 7/30/2019 Laureate International Universities https://laureate-au.blackboard.com/webapps/blackboard/content/listContent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 5/6 however, we have set up methods that speci�cally allow controlled access to those class members. The methods that set or initialise those private class members are sometimes called ‘mutator’ or ‘setter’ methods and the methods that allow you to read the values are sometimes called ‘accessor’ or ‘getter’ methods. These are the interfaces provided by the class that allow indirect access. Now that we have de�ned the class we are ready to use it in our main() function as below. int main() { Car myCar; myCar.setColour(“Red”); myCar.setBrand(“Ferrari”); myCar.setFuelTankCapacity(70.0); myCar.setOdometerReading(47876); myCar.start(); myCar.accelerate(); myCar.brake(); myCar.stop(); cout < “colour:="" “="">< mycar.getcolour()="">< endl;="" cout="">< “brand:="" “="">< mycar.getbrand()="">< endl;="" cout="">< “tank:="" “="">< mycar.getfueltankcapacity()="">< endl="" cout="">< “odometer:="" “="">< mycar.getodometerreading()="">< en return 0; } the code in the above segment demonstrates the simplicity in using objects in programming. there is some initial setting up that must be done before the classes and objects can be used in the program, but, once that is done the �rst time, the classes can be used and reused across many programs. indeed, a way in which you can reuse your classes is to save them in a separate �le, say ‘car.h’ (‘h’ is for header) and then include the �le in your main program just like you have been including library �les, as in the following: #include “car.h” your ‘car.h’ �le would need to be saved in the same directory or folder that your main() function is located in or otherwise you will need to specify the path in the include compiler directive. once this is done, you are able to use the car class again and again, without needing to reimplement it each time it is needed. you should now make your way through the activities. in the next half of the module we will focus on constructors and inheritance. 7/30/2019 laureate international universities https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 6/6 4.1 readings 1. mosh 2018 ‘object-oriented programming in 7 minutes’ programming with mosh [online] https://www.youtube.com/watch?v=ptb0eilxuc8, accessed 13 october 2018. 4.1 activities there are a number of activities in this module and you are expected to complete all of these in the labs or in class or in your own time. the �rst of these is to reproduce any and all of the worked examples in the module content and to review the readings and videos. then, work your way through these exercises: 1. taking the in-class example of the car, continue coding this example but include one or more additional variables for the speed of the car. include mutator and accessor methods for the car’s speed and use them in the start(), accelerate(), brake() and stop() methods to extend their functionality. when the car starts, initialise its speed to 0. allow the accelerator method to increase the speed by a given increment and the brake method to decrease by a given decrement. print the current speed to the screen. 2. race time: take the same example and separate the class into a header �le. write another program that instantiates two car objects, one small and the other large (if you don’t know cars, look up examples for brands of cars and their fuel tank capacities). in your code, start each car and then accelerate each car at di�erent rates. do this in a loop three times for each car and then reverse the rates for braking. print the name of the car that comes to a complete stop �rst and declare the other car the winner. click here to return to module top https://www.youtube.com/watch?v=ptb0eilxuc8 7/30/2019 laureate international universities https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 1/7 module 4 - object-orientedmodule 4 - object-oriented programmingprogramming 4.2 constructors and inheritance in the �rst half of the module we introduced the notion of object- oriented programming. we brie�y touched on the some of the shortcomings of the dominant procedural paradigm that had dominated programming practice until object-oriented programming became common practice in the 1980s and we introduced the bene�ts of object orientation: encapsulation – we group en="" return="" 0;="" }="" the="" code="" in="" the="" above="" segment="" demonstrates="" the="" simplicity="" in="" using="" objects="" in="" programming.="" there="" is="" some="" initial="" setting="" up="" that="" must="" be="" done="" before="" the="" classes="" and="" objects="" can="" be="" used="" in="" the="" program,="" but,="" once="" that="" is="" done="" the="" �rst="" time,="" the="" classes="" can="" be="" used="" and="" reused="" across="" many="" programs.="" indeed,="" a="" way="" in="" which="" you="" can="" reuse="" your="" classes="" is="" to="" save="" them="" in="" a="" separate="" �le,="" say="" ‘car.h’="" (‘h’="" is="" for="" header)="" and="" then="" include="" the="" �le="" in="" your="" main="" program="" just="" like="" you="" have="" been="" including="" library="" �les,="" as="" in="" the="" following:="" #include="" “car.h”="" your="" ‘car.h’="" �le="" would="" need="" to="" be="" saved="" in="" the="" same="" directory="" or="" folder="" that="" your="" main()="" function="" is="" located="" in="" or="" otherwise="" you="" will="" need="" to="" specify="" the="" path="" in="" the="" include="" compiler="" directive.="" once="" this="" is="" done,="" you="" are="" able="" to="" use="" the="" car="" class="" again="" and="" again,="" without="" needing="" to="" reimplement="" it="" each="" time="" it="" is="" needed.="" you="" should="" now="" make="" your="" way="" through="" the="" activities.="" in="" the="" next="" half="" of="" the="" module="" we="" will="" focus="" on="" constructors="" and="" inheritance.="" 7/30/2019="" laureate="" international="" universities="" https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id="_75722_1&content_id=_7771614_1&mode=reset" 6/6="" 4.1="" readings="" 1.="" mosh="" 2018="" ‘object-oriented="" programming="" in="" 7="" minutes’="" programming="" with="" mosh="" [online]="" https://www.youtube.com/watch?v="pTB0EiLXUC8," accessed="" 13="" october="" 2018.="" 4.1="" activities="" there="" are="" a="" number="" of="" activities="" in="" this="" module="" and="" you="" are="" expected="" to="" complete="" all="" of="" these="" in="" the="" labs="" or="" in="" class="" or="" in="" your="" own="" time.="" the="" �rst="" of="" these="" is="" to="" reproduce="" any="" and="" all="" of="" the="" worked="" examples="" in="" the="" module="" content="" and="" to="" review="" the="" readings="" and="" videos.="" then,="" work="" your="" way="" through="" these="" exercises:="" 1.="" taking="" the="" in-class="" example="" of="" the="" car,="" continue="" coding="" this="" example="" but="" include="" one="" or="" more="" additional="" variables="" for="" the="" speed="" of="" the="" car.="" include="" mutator="" and="" accessor="" methods="" for="" the="" car’s="" speed="" and="" use="" them="" in="" the="" start(),="" accelerate(),="" brake()="" and="" stop()="" methods="" to="" extend="" their="" functionality.="" when="" the="" car="" starts,="" initialise="" its="" speed="" to="" 0.="" allow="" the="" accelerator="" method="" to="" increase="" the="" speed="" by="" a="" given="" increment="" and="" the="" brake="" method="" to="" decrease="" by="" a="" given="" decrement.="" print="" the="" current="" speed="" to="" the="" screen.="" 2.="" race="" time:="" take="" the="" same="" example="" and="" separate="" the="" class="" into="" a="" header="" �le.="" write="" another="" program="" that="" instantiates="" two="" car="" objects,="" one="" small="" and="" the="" other="" large="" (if="" you="" don’t="" know="" cars,="" look="" up="" examples="" for="" brands="" of="" cars="" and="" their="" fuel="" tank="" capacities).="" in="" your="" code,="" start="" each="" car="" and="" then="" accelerate="" each="" car="" at="" di�erent="" rates.="" do="" this="" in="" a="" loop="" three="" times="" for="" each="" car="" and="" then="" reverse="" the="" rates="" for="" braking.="" print="" the="" name="" of="" the="" car="" that="" comes="" to="" a="" complete="" stop="" �rst="" and="" declare="" the="" other="" car="" the="" winner.="" ="" click="" here="" to="" return="" to="" module="" top="" https://www.youtube.com/watch?v="pTB0EiLXUC8" 7/30/2019="" laureate="" international="" universities="" https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id="_75722_1&content_id=_7771614_1&mode=reset" 1/7="" module="" 4="" -="" object-orientedmodule="" 4="" -="" object-oriented="" programmingprogramming="" 4.2="" constructors="" and="" inheritance="" in="" the="" �rst="" half="" of="" the="" module="" we="" introduced="" the="" notion="" of="" object-="" oriented="" programming.="" we="" brie�y="" touched="" on="" the="" some="" of="" the="" shortcomings="" of="" the="" dominant="" procedural="" paradigm="" that="" had="" dominated="" programming="" practice="" until="" object-oriented="" programming="" became="" common="" practice="" in="" the="" 1980s="" and="" we="" introduced="" the="" bene�ts="" of="" object="" orientation:="" encapsulation="" –="" we=""> en return 0; } the code in the above segment demonstrates the simplicity in using objects in programming. there is some initial setting up that must be done before the classes and objects can be used in the program, but, once that is done the �rst time, the classes can be used and reused across many programs. indeed, a way in which you can reuse your classes is to save them in a separate �le, say ‘car.h’ (‘h’ is for header) and then include the �le in your main program just like you have been including library �les, as in the following: #include “car.h” your ‘car.h’ �le would need to be saved in the same directory or folder that your main() function is located in or otherwise you will need to specify the path in the include compiler directive. once this is done, you are able to use the car class again and again, without needing to reimplement it each time it is needed. you should now make your way through the activities. in the next half of the module we will focus on constructors and inheritance. 7/30/2019 laureate international universities https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 6/6 4.1 readings 1. mosh 2018 ‘object-oriented programming in 7 minutes’ programming with mosh [online] https://www.youtube.com/watch?v=ptb0eilxuc8, accessed 13 october 2018. 4.1 activities there are a number of activities in this module and you are expected to complete all of these in the labs or in class or in your own time. the �rst of these is to reproduce any and all of the worked examples in the module content and to review the readings and videos. then, work your way through these exercises: 1. taking the in-class example of the car, continue coding this example but include one or more additional variables for the speed of the car. include mutator and accessor methods for the car’s speed and use them in the start(), accelerate(), brake() and stop() methods to extend their functionality. when the car starts, initialise its speed to 0. allow the accelerator method to increase the speed by a given increment and the brake method to decrease by a given decrement. print the current speed to the screen. 2. race time: take the same example and separate the class into a header �le. write another program that instantiates two car objects, one small and the other large (if you don’t know cars, look up examples for brands of cars and their fuel tank capacities). in your code, start each car and then accelerate each car at di�erent rates. do this in a loop three times for each car and then reverse the rates for braking. print the name of the car that comes to a complete stop �rst and declare the other car the winner. click here to return to module top https://www.youtube.com/watch?v=ptb0eilxuc8 7/30/2019 laureate international universities https://laureate-au.blackboard.com/webapps/blackboard/content/listcontent.jsp?course_id=_75722_1&content_id=_7771614_1&mode=reset 1/7 module 4 - object-orientedmodule 4 - object-oriented programmingprogramming 4.2 constructors and inheritance in the �rst half of the module we introduced the notion of object- oriented programming. we brie�y touched on the some of the shortcomings of the dominant procedural paradigm that had dominated programming practice until object-oriented programming became common practice in the 1980s and we introduced the bene�ts of object orientation: encapsulation – we group>