Question

In: Computer Science

We had plenty of new concepts to study for this week. List one concept and describe...

We had plenty of new concepts to study for this week. List one concept and describe it to the class. Do not duplicate concepts described by other students. I will start:

We learned about the Copy Constructor. The C++ supplies each class with a default copy constructor. This function is invoked when a new object is created and initialized or when an object is passed as a value parameter to a function. The default copy constructor performs a shallow copy, the values of the data fields in the exiting object is copied over to the newly created object. The default constructor is enough and works fine if the class has no pointer data field. A class that has a pointer data member that points to allocated memory will need a customized copy constructor (a deep copy) since the default constructor only copies the address the pointer is holding and not the allocated memory. The Course class with the student data member is a good example.

Solutions

Expert Solution

Code

#include<iostream>
#include<cstring>
using namespace std;
class DeepCopyExample
{
char *s_copy;
public:
DeepCopyExample (const char *str)
{
s_copy = new char[16]; //Dynamic memory alocation
strcpy(s_copy, str);
}
  
DeepCopyExample (const DeepCopyExample &str)
{
s_copy = new char[16]; //Dynamic memory alocation
strcpy(s_copy, str.s_copy);
}
  
~DeepCopyExample()
{
delete [] s_copy;
}

void display()
{
cout<<s_copy<<endl;
}
};
/* main function */
int main()
{
DeepCopyExample c1("JayJoshi");
//object created using the deep copy
   DeepCopyExample c2 = c1; //copy constructor

c1.display();
   cout<<"\nC2 object that is created using deep copy."<<endl;
c2.display();
  
return 0;
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

One of the key concepts we have discussed this semester is the concept of “Elasticity”. Generally...
One of the key concepts we have discussed this semester is the concept of “Elasticity”. Generally speaking, elasticity is simply a measure of how responsive one variable is to a change in another variable. While we have focused on the “own price elasticity of demand”, the “income elasticity of demand” and the “cross-price elasticity of demand” this concept can be extended to a number of different situations. (10 pts) The demand curve for a product is given by Qx=1,000-2Px+0.02Pz,  where Pz...
This week we read two articles (one very short, and one mid-sized) about the concept of...
This week we read two articles (one very short, and one mid-sized) about the concept of dignity, and a second about the provision of "false hope" in nursing practice. Please read the two articles, and then answer one of the two questions below in ~400 words: 1. Is providing false hope consistent with treating patients with maximum human dignity? Does it make a difference if a doctor or nurse is providing it? Why or why not? Refer to the articles...
This week, we consider how to conduct hypotheses test on one sample data. Discuss the concepts...
This week, we consider how to conduct hypotheses test on one sample data. Discuss the concepts associated with these tests. Consider the following: The difference between a one tail and a two tailed test. The importance of stating the null and alternative hypotheses before conducting the test. The importance of a type one error (p) in conducting the test   The relationship between the p value and our decision to accept or reject the null hypothesis
Last week, you explained the concept of a virtual machine. This week, we take it a...
Last week, you explained the concept of a virtual machine. This week, we take it a step further. Describe some of the configuration options when setting up Windows Operating System and Linux on a virtual machine? Which option do you think is most important and why?
After completing the reading this week, we reflect on a few key concepts this week: Organizational...
After completing the reading this week, we reflect on a few key concepts this week: Organizational performance is the fifth aspect of the model, reflect on the question, do certain leadership behaviors improve and sustain performance at the individual, group, and organizational level? Please explain your response. There were two types of innovation addressed this week (product and process innovation), please note your own personal definition of these concepts and offer an example of both. Please be sure to answer...
The concept of an asymptote is presented this week. In studying this topic we look at...
The concept of an asymptote is presented this week. In studying this topic we look at limits and study as a function gets closer and closer to a value. We are not concerned about what happens at that value but as we get closer and closer. For example, it is not important for hospital personnel to be in the room while a patient is having a stroke. At that point, it is too late. By the time that the hospital...
Describe the following concepts: a) Explain the concept of Pareto activity (graphs and equations) with the...
Describe the following concepts: a) Explain the concept of Pareto activity (graphs and equations) with the help and discuss the importance of the concept in economics. b) Lerner index (explain its description and formula). c) Normal profit (define and discuss its importance in economics)
Java Programming Assignment 6-1 We have covered the “Methods” this week. Apply the concepts that we...
Java Programming Assignment 6-1 We have covered the “Methods” this week. Apply the concepts that we have learnt in class and come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. You program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye”...
This week, we consider how to conduct hypotheses test on one sample data. Discuss the concepts associated with these tests. Consider the following:
  This week, we consider how to conduct hypotheses test on one sample data. Discuss the concepts associated with these tests. Consider the following: The difference between a one tail and a two tailed test. The importance of stating the null and alternative hypotheses before conducting the test. The importance of a type one error (p) in conducting the test   The relationship between the p value and our decision to accept or reject the null hypothesis
Take one component in the Metaparadigm of Nursing and identify the concept or concepts of Watson’s...
Take one component in the Metaparadigm of Nursing and identify the concept or concepts of Watson’s Theory of Caring that support that Watson wrote a theory of nursing.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT