• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 3 pages
Exam (elaborations)

DynamicString.cpp Study Guide Exam Questions And Answers2024.

Document preview thumbnail
Preview 1 out of 3 pages

Default Constructor - correct answer DynamicString::DynamicString(){ cstr = new char[1]; *(cstr) = '0'; size = 0; } C-String Constructor Creates a copy of the provided c-string. - correct answer DynamicString::DynamicString(const char* str){ size = 0; //Initializing a counter for(int i = 0; str[i] != '0'; i++) { //Counting the number of elements in char array{ size++; } if(size 0) { throw out_of_range("Out of Range"); //Checking if the str is out of range } cstr = new char [size+1]; //Allocate memory for new cstr char array for(int i = 0; i size; i++){ //Copying str to new cstr cstr[i]=str[i]; } cstr[size] ='0'; //Putting a null terminator at the end of the array } Copy-constructor. Performs a deep-copy. - correct answer DynamicString::DynamicString(const DynamicString& other){ cstr = new char[+1]; //create a new array for copy constructor for(int i = 0; i +1; i++) { *(cstr+i) = *(+i); } } Assignment operator. Performs a deep-copy. Returns itself, now containing a deep copy - correct answer DynamicString& DynamicString::operator=(const DynamicString& other){ if(this != &other) { deleteArray(); //Deletes cstr to deal with possible overlapping memory cstr = new char[+1]; //Creates new cstr char array for assignment operator for(int i = 0; i ity(); i++) { *(cstr+i) = *(+i); } } return *this; } De-constructor. Releases memory resources + Method to call delete operator - correct answer DynamicString::~DynamicString(){ deleteArray(); } void DynamicString::deleteArray() //Tests for cstr incase it is already empty, then deletes contents of array if not empty { if(cstr != nullptr) { delete[] cstr; } cstr = nullptr; size = 0; //Reassigns size back to 0; }


Document information

Uploaded on
April 29, 2024
Number of pages
3
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers
$12.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Rechga
5.0
(10)
Sold
20
Followers
2
Items
2424
Last sold
2 months ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions

Whoops! We can’t load your doc right now. Try again or contact support.