Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DGraMmarly Tell me what you want to do e Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

DGraMmarly Tell me what you want to do e Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. Enable E diting PolymorphPtr Minilab Introduction This Minilab has two mainlines: PolymorphismMinilabDriver for Partl and PolymorphMinilabDriver2 for Part2. You should be becoming familiar with the basic concepts of Object-Oriented Program (classes, methods, constructors, instances of the class, toString0, public/private/protected, inheritance). There is a very brief summary of how they are used together . The idea that data and operations (methods) are put together in the same class is called encapsulation. Classes define data and also the methods to operate on their data. Users of the classes should only "see" what is necessary for them. This is called information . hiding and is implemented by defining classes or data as either public, private, or protected .If you define a data structure that holds a certain class, users can put in instances of that class or instances of any subelass. Since the top of the Class hierarch is Object, if you define a data structure that holds Objects, you can put in anything (since everything is a subclass). However, you have to typecast it when taking it out of the data structure. This is because Java generates code at compile time based on the fact that the data structure was defined to hold Objects. This is called "compile-time binding." or "static binding" You will be using a virtual function and pointers . "static" data are data that only needs to exist in one place (instead of every instance lhaving a different value for it). So it goes with the class instead of each individual instance. "static" methods are methods that also go with the class - you ask the class to do something (like Math sqt...) What is Polymorphism'? B MinilbPolymorphPtr Protected View - Saved to this PC Layout References Mailings Review View Help Grammarly OTell me what you want to do the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View Enable Editing What is Polymorphism? Polymorphism is the idea that a number of classes/subclasses may have virtual functions with the same name. If you put instances of these classes/subclasses into a data structure and then "tell" them all to exccute that virtual function, they will all use their own method. C++ waits until run-time to actually look at what is stored in the data structure (and thercfore what function is called). This is called '"run- time binding," or "dynamic binding." C++ can only do late-binding by using pointers to various elasses with "virtual functions. Using pointers, we can store a list of pointers in an array of the base-class and C++ will use the correct virtual" derived function from the subclass. If needed, we can determine the derived class. This Minilab: The idea of this minilab is to simulate a High School "crowd," complete with cliques and stereotypical behavior. More specifically, this probably simulates a sitcom that simulates a High School. But it is a good exercise for creating different classes, subclasses, instances, methods, and polymorphism. Follow the directions closely for this Minilab Partl: mlPolymorphPtr Project 1. There is a class called Student, which describes a High School student. Open the class and make sure you understand the data it has and also the functions. Then add a new function Partl: mlPolymorphPtr Project There is a class called Student, which describes a High School student. Open the class and make sure you understand the data it has and also the functions. Then add a new function 1. called getlDO to the Student class. It should just return the ID. Make sure the fiunction is also visible to everyone Open the Course class and study it -it describes a High School course. and an array of Students that are enrolled. Through its functions, it knows how to add a new Student, take attendance, and return its String representation. The Course class also has a static field called numinstances. This is a count of how many Course instances have been created Since this information only needs to be stored in one place (with the Course class rather than with each different object instance), it is defined as static. In the Course class, define another public method called how Many0 which just retums how marsy Courses have been ereated. Users will ask the Course class how many have been created (see the PolymorphismMinilabDriver), so 2. Its data include a name make it static. ll UNIE yau need to edit, it's safer to stay in Protected Virw Enable Editing 3. Open Polymorphism Minilab Driver and study it. It is the "driver" through which the program creates a Course instance, tells it to add some Students, prints it, and tells it to take attendance. Compile and run it. Make sure you understand the results. If you have added the two finctions specified above, PolymorphismMinilabDriver should now run. Part2: mlPolymorph2 Project You will need to right-click on the PolymorphismMinilabDriver, select Properties, and change its "Exclude from Build" setting to "Yes". Similarly, change PolymorphismMinilabDriver2's Exclude from Build" setting to "No". Now Driver2 will be your mainline Now include a parameterized Course constructor (one that can receive some arguments). This constructor should accept a string and an int and use them to set the name and maxCount. Be sure it does the other things that the default constructor does. 3. Look at the following classes: PolymorphismMinilabDriver2 (this one contains a call to your new constructor) BrownNose 4. To get Polymorphism MinilabDriver2 to compile cleanly, you need to fix BrownNose to successfully inherit the data from its superclass, Student. Change the visibility of the Shudent data so that it can be ilerted by its subclasses. It should not be inheritable by everyone, however. Then recompile Student, BrownNose, and PolymorphismMinilabDriver2 The addStudent0 method of the Course class will accept a Student instance and put it into its array of Students. Since BrownNose is a subclass of Student, we can pass in an instance of BrownNose and it will successfully put it into the anay of Students. 4. Run PolymorphismMinilab Driver. Both Students and Brown Noses are put into the Course UlL Unless you need to edit, it's safer to stay in Protected View. Enable Editing 4. To get PolymorphismMinilabDriver2 to compile cleanly, you need to fix BrownNose to successfully inherit the data from its superclass, Student. Change the visibility of the Student data so that it can be inherited by its subclasses. It should not be inheritable by everyone, however. Then recompile Student, BrownNose, and PolymorphismMinilabDriver2. The addStudent0 method of the Course class will accept a Student instance and put it into its aray of Students. Since BrownNose is a subelass of Student, we can pass in an instance of BrownNose and it will successfully put it into the array of Students. 4. Run Polymorphism Minilab Driver2. Both Students and BrownNoses are put into the Course instance. When it "takesAttendance." the BrownNose instance should "answer" differently Make sure you understand all the results. ote that the driver (Polymorphism MinilabDriver2) now tells the Course instance to add a Student times. Since the array was created with size S, the last two cannot be entered. So, two error messages should print out DGraMmarly Tell me what you want to do e Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. Enable E diting PolymorphPtr Minilab Introduction This Minilab has two mainlines: PolymorphismMinilabDriver for Partl and PolymorphMinilabDriver2 for Part2. You should be becoming familiar with the basic concepts of Object-Oriented Program (classes, methods, constructors, instances of the class, toString0, public/private/protected, inheritance). There is a very brief summary of how they are used together . The idea that data and operations (methods) are put together in the same class is called encapsulation. Classes define data and also the methods to operate on their data. Users of the classes should only "see" what is necessary for them. This is called information . hiding and is implemented by defining classes or data as either public, private, or protected .If you define a data structure that holds a certain class, users can put in instances of that class or instances of any subelass. Since the top of the Class hierarch is Object, if you define a data structure that holds Objects, you can put in anything (since everything is a subclass). However, you have to typecast it when taking it out of the data structure. This is because Java generates code at compile time based on the fact that the data structure was defined to hold Objects. This is called "compile-time binding." or "static binding" You will be using a virtual function and pointers . "static" data are data that only needs to exist in one place (instead of every instance lhaving a different value for it). So it goes with the class instead of each individual instance. "static" methods are methods that also go with the class - you ask the class to do something (like Math sqt...) What is Polymorphism'? B MinilbPolymorphPtr Protected View - Saved to this PC Layout References Mailings Review View Help Grammarly OTell me what you want to do the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View Enable Editing What is Polymorphism? Polymorphism is the idea that a number of classes/subclasses may have virtual functions with the same name. If you put instances of these classes/subclasses into a data structure and then "tell" them all to exccute that virtual function, they will all use their own method. C++ waits until run-time to actually look at what is stored in the data structure (and thercfore what function is called). This is called '"run- time binding," or "dynamic binding." C++ can only do late-binding by using pointers to various elasses with "virtual functions. Using pointers, we can store a list of pointers in an array of the base-class and C++ will use the correct virtual" derived function from the subclass. If needed, we can determine the derived class. This Minilab: The idea of this minilab is to simulate a High School "crowd," complete with cliques and stereotypical behavior. More specifically, this probably simulates a sitcom that simulates a High School. But it is a good exercise for creating different classes, subclasses, instances, methods, and polymorphism. Follow the directions closely for this Minilab Partl: mlPolymorphPtr Project 1. There is a class called Student, which describes a High School student. Open the class and make sure you understand the data it has and also the functions. Then add a new function Partl: mlPolymorphPtr Project There is a class called Student, which describes a High School student. Open the class and make sure you understand the data it has and also the functions. Then add a new function 1. called getlDO to the Student class. It should just return the ID. Make sure the fiunction is also visible to everyone Open the Course class and study it -it describes a High School course. and an array of Students that are enrolled. Through its functions, it knows how to add a new Student, take attendance, and return its String representation. The Course class also has a static field called numinstances. This is a count of how many Course instances have been created Since this information only needs to be stored in one place (with the Course class rather than with each different object instance), it is defined as static. In the Course class, define another public method called how Many0 which just retums how marsy Courses have been ereated. Users will ask the Course class how many have been created (see the PolymorphismMinilabDriver), so 2. Its data include a name make it static. ll UNIE yau need to edit, it's safer to stay in Protected Virw Enable Editing 3. Open Polymorphism Minilab Driver and study it. It is the "driver" through which the program creates a Course instance, tells it to add some Students, prints it, and tells it to take attendance. Compile and run it. Make sure you understand the results. If you have added the two finctions specified above, PolymorphismMinilabDriver should now run. Part2: mlPolymorph2 Project You will need to right-click on the PolymorphismMinilabDriver, select Properties, and change its "Exclude from Build" setting to "Yes". Similarly, change PolymorphismMinilabDriver2's Exclude from Build" setting to "No". Now Driver2 will be your mainline Now include a parameterized Course constructor (one that can receive some arguments). This constructor should accept a string and an int and use them to set the name and maxCount. Be sure it does the other things that the default constructor does. 3. Look at the following classes: PolymorphismMinilabDriver2 (this one contains a call to your new constructor) BrownNose 4. To get Polymorphism MinilabDriver2 to compile cleanly, you need to fix BrownNose to successfully inherit the data from its superclass, Student. Change the visibility of the Shudent data so that it can be ilerted by its subclasses. It should not be inheritable by everyone, however. Then recompile Student, BrownNose, and PolymorphismMinilabDriver2 The addStudent0 method of the Course class will accept a Student instance and put it into its array of Students. Since BrownNose is a subclass of Student, we can pass in an instance of BrownNose and it will successfully put it into the anay of Students. 4. Run PolymorphismMinilab Driver. Both Students and Brown Noses are put into the Course UlL Unless you need to edit, it's safer to stay in Protected View. Enable Editing 4. To get PolymorphismMinilabDriver2 to compile cleanly, you need to fix BrownNose to successfully inherit the data from its superclass, Student. Change the visibility of the Student data so that it can be inherited by its subclasses. It should not be inheritable by everyone, however. Then recompile Student, BrownNose, and PolymorphismMinilabDriver2. The addStudent0 method of the Course class will accept a Student instance and put it into its aray of Students. Since BrownNose is a subelass of Student, we can pass in an instance of BrownNose and it will successfully put it into the array of Students. 4. Run Polymorphism Minilab Driver2. Both Students and BrownNoses are put into the Course instance. When it "takesAttendance." the BrownNose instance should "answer" differently Make sure you understand all the results. ote that the driver (Polymorphism MinilabDriver2) now tells the Course instance to add a Student times. Since the array was created with size S, the last two cannot be entered. So, two error messages should print out

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

=+c) What is/are the response(s)?

Answered: 1 week ago