Concept explainers
Give the definitions for the member function addValue, the copy constructor, the overloaded assignment operator, and the destructor for the following class. This class is intended to be a class for a partially filled array. The member variable numberUsed contains the number of array positions currently filled. The other constructor definition is given to help you get started.
#include <iostream> #include <cstdlib> using namespace std; class PartFilledArray { public: PartFilledArray(int arraySize); PartFilledArray(const PartFilledArray& object); ~PartFilledArray(); void operator =(const PartFilledArray& rightSide); void addValue(double newEntry); //There would probably be more member functions //but they are irrelevant to this exercise. protected: double *a; int maxNumber; int numberUsed; }; PartFilledArray::PartFilledArray(int arraySize) : maxNumber(arraySize), numberUsed(0) { a = new double[maxNumber]; } |
(Many authorities would say that the member variables should be private rather than protected. We tend to agree. However, using protected makes for a better practice assignment, and you should have some experience with protected variables because some programmers do use them.)
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting out with Visual C# (4th Edition)
Absolute Java (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Artificial Intelligence: A Modern Approach
- User-defined Class:You will design and implement your own data class. The class will store data that has been read asuser input from the keyboard (see Getting Input below), and provide necessary operations. As thedata stored relates to monetary change, the class should be named Change. The class requires atleast 2 instance variables for the name of a person and the coin change amount to be given to thatperson. You may also wish to use 4 instance variables to represent amounts for each of the 4 coindenominations (see Client Class below). There should be no need for more than these instancevariables. However, if you wish to use more instance variables, you must provide legitimatejustification for their usage in the internal and external documentation.Your class will need to have at least a default constructor, and a constructor with two parameters:one parameter being a name and the other a coin amount. Your class should also provide appropriateget and set methods for client usage. Other…arrow_forwardPart (1) Create a class named Item, that includes two private members: Type (String), and Price(double). The Item class should also include: one set method, two get methods and default constructor to initialize Type to “None” and Price to 0.0. Part (2) Write a static method named findAvg that takes as parameter an array of type Item. The method should find and output the average price of all items in the array. The method prototype is: public static void findAvg (Item [] list) Write the main method to do the following: Declare an array of type Item of size 5; Ask the user to enter type and price for each item in the array Call the findAvg method to output the average price of all items.arrow_forward1- A complex number has the form a+bi , can be expressed as theordered pair of real numbers (a,b). The class represents the real andimaginary parts as double precision values.Provide a constructor that enables an object of this class to beinitialized when it is instantiated. The constructor should containdefault values.Provide Public member functions for each of the followingarithmetic’s functions (addition – subtraction – multiplication –division), a complex absolute value operation, printing the number inthe form (a,b), printing the real part , printing the imaginary part andfinal overload the == operator to allow comparisons of two complexnumbers.Include any additional operations that you think would be useful fora complex number class.Design, implement, and test your class.arrow_forward
- In a course, a teacher gives the following tests and assignments:• A lab activity that is observed by the teacher and assigned a numeric score.• A pass/fail exam that has 10 questions. The minimum passing score is 70.• An essay that is assigned a numeric score.• A final exam that has 50 questionsWrite a class named CourseGrades . The class should have a member named gradesthat is an array of GradedActivity pointers. The grades array should have four ele-ments, one for each of the assignments previously described. The class should have thefollowing member functions:setLab : This function should accept the address of a GradedActivityobject as its argument. This object should already hold the stu-dent’s score for the lab activity. Element 0 of the grades arrayshould reference this object.setPassFailExam : This function should accept the address of a PassFailExamobject as its argument. This object should already hold the stu-dent’s score for the pass/fail exam. Element 1 of the grades…arrow_forwardCreate a class called ADDITION has one integer and one float data member. Use pointer to data member to find their su m and print it from main method and also use the concept of dynamic constructor.arrow_forwardObjects and Pointers Write code to instantiate/create two Bicycle objects: a default object (my_bike) and a non-default object (sister_bike). For the non-default object you may hard-code (or make up) the required parameters (brand, price and wheel size). No console input is needed.arrow_forward
- Rectangle Class Observe the Rectangle class in rectangle.h, and you'll see it has two member variables: length_ and width_. These member variables can be modified with the "Setter functions" SetLength and SetWidth (aka mutator functions) and can be retrieved with the "getter functions" GetLength and GetWidth (aka accessor functions). You will be implementing two member functions of the Rectangle class: Area, and Perimeter. Notice that if a function belongs to a class, when we define the function outside of the class, we indicate that it is a member function of a class using the :: operator. For example, because Area() belongs to the Rectangle class, when we define the function in rectangle.cc, it is written as: int Rectangle::Area() { ... } After implementing these two member functions, you will implement a function, LargestRectangleByArea that compares two input Rectangle objects and returns which of the two is larger, based on its area. Implement the member function Area that…arrow_forwardThis is an object oriented programming question The code should be in c++ language Create a class Employee having a private data members E_ID, E_Name, E_Age and E_Salary. Now create a public member function void getData() and void ShowData() to take and display an employee data. In the main(), function create an array of Employee class, size of the array should be taken from user at run time and call all the functions defined in the class. Sample Output: Enter details of Employee 1 Enter Employee Id: 101 Enter Employee Name: Usman Enter Employee Age: 29 Enter Employee Salary: 45000 Enter details of Employee 2 Enter Employee Id: 102 Enter Employee Name: Sana Enter Employee Age: 31 Enter Employee Salary: 51000 Enter details of Employee 3…arrow_forwardUser-defined Class: You will design and implement your own data class. The class will store data that has been read as user input from the keyboard (see Getting Input below), and provide necessary operations. As the data stored relates to monetary change, the class should be named MoneyChange. The class requires at least 2 instance variables for the name of a person and the coin change amount to be given to that person. You may also wish to use 6 instance variables to represent amounts for each of the 6 coin denominations (see Client Class below). There should be no need for more than these instance variables. However, if you wish to use more instance variables, you must provide a legitimate justification for their usage in the internal and external documentation.Your class will need to have at least a default constructor, and a constructor with two parameters:one parameter being a name and the other a coin amount. Your class should also provide appropriate get and set methods for…arrow_forward
- Pointer and classImplement a class called Team as specified:data members:name - the name of the Team (defined as a dynamic variable)members - a dynamic array of stringsize - number of members in the team.functions:Course(): default constructor set name to “TBD”, and size to 0, members toempty listCourse(string): one argument constructor set name, and size to 0, members toempty listaccessor - an accessor for the name and size variablemutator - an mutator for the name variableUse following main() to test your class.int main() {Team a,b("Mets");cout<<a.getName()<<endl; // print TBDa.setName("Yankee");cout<<a.getName()<<endl; // print Yankeecout<<b.getName()<<endl; // print Metscout<<a.getSize()<<endl; // print 0return 0;}arrow_forwardFor a non-constant member function of class Test, the this pointer has type: Select one: O a. const Test * const O b. Test * const O . Test const * O d. const Test *arrow_forwardCreate a class called ADDITION has one integer and one float data member. Use pointer to da a member to find their sum and print it from main method and also use the concept of dynamic constructor.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning