Question

C++ computer science Given the partial class HardDrive implementation below, implement all of the following: 1:...

C++ computer science

Given the partial class HardDrive implementation below, implement all of the following:

1: default constructor that initialized the attributes with proper default data of your choice.

2: destructor() method, that releases all the dynamically allocated memory.

3: copy constructor() method: That properly manages the dynamic array when the object is passed by value to a function as a parameter.

4: overload the assignment operator: To properly handle copying the dynamic array when one object is assigned to another object.

Hint: Rule of three.

5: getters and setters (methods) for each class member: for accessing and updating the values of the fields.

Hint: final assignment.

class HardDrive       {

     private:

           string serialNo;

           double CapacityInGBs;

           string Brand;

           int RotationalSpeedRperMin;  // revolutions per minute

           int numberOfExtraFeatures;

           string* otherFeatures;

          

public:

HardDrive(string _serialNo_, double _CapacityInGBs_, string _Brand_, int _RotationalSpeedRperMin_, int numberOfExtraFeatures_) {

           serialNo = _serialNo_;

           CapacityInGBs = _CapacityInGBs_;

           Brand = _Brand_;

           RotationalSpeedRperMin = _RotationalSpeedRperMin_;

           numberOfExtraFeatures = numberOfExtraFeatures_;

           otherFeatures = new string[numberOfExtraFeatures];

     }

  

      // Your implementations

} // end of class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

HardDrive::HardDrive() {

seriaNo = "1234";

CapacityInGBs = 512;

Brand = "Dell";

RotationalSpeedRperMin = 7200;

numberOfExtraFeatures = 0;

otherFeatures = {};

}

2)

HardDrive:: ~HardDrive() {

delete[] otherFeatures;

}

3)

HardDrive::HardDrive (const HardDrive &hd) {

this->serialNo = hd.getSerialNo();

this->CapacityInGBs = hd.getCapacityInGBs();

this->Brand = hd.getBrand();

this->RotationalSpeedRperMin = hd.getRotationalSpeedRperMin();

this->numberOfExtraFeatures = hd.getNumberOfExtraFeatures();

this->otherFeatures = new string[this->numberOfExtraFeatures];

for (int i=0; i<this->numberOfExtraFeatures; i++ ) {

this->otherFeatures[i] = hd->getOtherFeatures()[i];

}

}

NOTE: As per HOMEWORKLIB POLICY I am allowed to answer specific number of questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

Add a comment
Know the answer?
Add Answer to:
C++ computer science Given the partial class HardDrive implementation below, implement all of the following: 1:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students...

    Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students in a class. The class has the following member variables: int numStudents // holds the number of students in the class double* grades // to point to a dynamically allocated array of grades The class has the following public functions: +default constructors //set numStudents = 0; and grades = nullptr; +parameterized constructors //accepts numStudents and creates an array with size = numStudents; +AcceptGrades //...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following...

    In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

  • C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test...

    C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test it) :- -You may need getters and setters also. 1. Declare and define an animal base class: animal stores an age (int), a unique long ID (a boolean that is true if it is alive, and a location (a pair of double). animal requires a default constructor and a 3 parameter constructor. Both constructors should set the unique ID automatically. They should also set...

  • In this assignment, you are asked to: 1. create a Matrix class that stores and operate...

    In this assignment, you are asked to: 1. create a Matrix class that stores and operate on a dynamic two-dimensional array. The class has the following structure: Private member variables: - int ** mat; - int rows; - int cols; Public member functions: +Default constructor: sets both rows and cols to 3 and creates 3x3 matrix dynamically +Parameterized constructor: sets the rows and cols to the values passed to the constructor and create a matrix with the given dimensions. +Destructor:...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT