Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 15.2, Problem 9STE

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.)

Blurred answer
Students have asked these similar questions
Please help me C++ language
Please read the main function and define a class CStudent. (object array, static member, string) Please do not change the main function and complete the program given. 【Description】 Please read the main function and define  a class CStudent.  In the main funciton, two arrays of the ojbect of CStudent are define.  Please analyze the call of constructor and destructor in the process of creating and releasing objects. 1. CStudent has two private member variables:stirng name, int age.  2. CStudent has a static member count. It will be incremented by 1 when the object is created and decremented by 1 when the object is destroyed. 3. The constructor function should output "*** is contructing". The destructor function should output “*** is destructing”. "***" indicates the name of the current CStudent object.     【Input】 No input   【Output sample】 There are 0 students. noname is contructing noname is contructing noname is contructing noname is contructing noname is contructing name:noname…
Write a class result that has array of three integers as attribute. It has a member function to input and a member function to display average of elements. Create another class student that contains object of class result. It has additional attributes of roll number and name. It also has member functions to input and display data members

Chapter 15 Solutions

Problem Solving with C++ (9th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY