Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ A pointer is a variable that contains as its value the _______ of another va

ID: 675407 • Letter: C

Question

c++

A pointer is a variable that contains as its value the _______ of another variable.

T / F A pointer that is declared to be of type void can be dereferenced.

Declare p to be a pointer variable that can hold one pointer that points to a variable of type double.

What operator is used to dereference the pointer variable? Give an example.

Pointer variable p1 can contain a pointer to variables v1. Write the C++ code that will allows you to do this.

Define the new operator.

Define freestore (heap).

What is the delete operator used for?

Write the C++ code to delete a pointer.

What is a dangling pointer?

What unfortunate misinterpretation can occur with the following declaration?

int* intptr1, intptr2;

Create a dynamic allocated array with ten array elements of type double.

Write the C++ code to delete the dynamic allocated array a.

T / F The “this” pointer is a predefined pointer that points to the calling object.

Define copy constructor.

What is a destructor?

What must the name of a destructor be?

When is a destructor called?

What does a destructor actually do?

What should a destructor do?

If a class is named MyClass and it has a constructor. What is the constructor named? If MyClass has a destructor, what is the destructor named?

Explain carefully why no overloaded assignment operator is needed when the only data consists of built in types. What about a copy constructor? A Destructor?

The following is the first line of the copy constructor definition for the class PFArrayD. The identifier PFArrayD occurs three times and means something slightly different each time. What does it mean for each of the three cases?

PFArrayD::PFArrayD(const PFArrayD& pfaObject);

What are the three instances when a copy constructor is called automatically?

What is the difference between a shallow copy and a deep copy?

Input & Output in C++ occurs as ___________ o f bytes.

Member function ___________ can be used to set and reset format state.

Most C++ programs should include the ________ header file that contains the declaration required for all stream I/O operations.

When using parameterized manipulators, the header file __________ must be included.

Input operations are supported by _____________.

Output operations are supported by _____________.

The symbol for the stream-insertion operator is ____________.

The symbol for the stream-extraction operator is _____________.

The stream manipulators _______, __________, and ________ specify that integers should be displayed in octal, hexadecimal, and decimal formats, respectively.

When used, the _____ stream manipulator causes positive numbers to display with a plus sign.

T / F Every input and every output file used by your program has two names.

Write the C++ statements that will allow you to read from a file, myfile.txt.

Write the C++ code to close the file describe in #37.

Write the C++ code to append to the file, myfile2.text.

A programmer has read half of the lines in a file. What must the programmer do to the file to enable reading the first line a second time?

What member function does every input file stream have that can be used to test for reaching the end of the input file?

What is the type of the stream cin?

What is the type of the stream cout?

Member functions __________ and _________ of istream and ostream set the file position pointer to a specified location in an input or output stream, respectively.

A _______ is a flow of characters.

A _______ is a group of related records.

When your program takes input from a file, it is said to be ________ from the file.

When your program sends output to a file, it is said to be _______ to a file.

Define derived class.

The stream manipulators that format justification are _________ and ___________.

Explanation / Answer

c++

A pointer is a variable that contains as its value the address of another variable.

A pointer that is declared to be of type void can be dereferenced. F

Declare p to be a pointer variable that can hold one pointer that points to a variable of type double.

Ans – double *p;

     Where variable p hold pointer to a variable of type double.

What operator is used to dereference the pointer variable? Give an example.

Ans This is the * operator not to be confused with the multiplication operator). It is used to get the variable pointed to by a pointer.

               *f_ptr = 42;

Example-

int main()

{

int m;

int * p = &m;

m = 3;

std::cout<<*p<<std::endl;

  return 0;

}

Pointer variable p1 can contain a pointer to variables v1. Write the C++ code that will allows you to do this.

Ans - - This code—

v1 = 0; p1 = &v1; p1 = 42;

cout << v1 << “ “ << p1 << endl;

output: 42 42

Define the new operator.

Ans- some time, we are not aware in advance how much memory you will need to store information in a defined variable and the size of required memory can be determined at run time.Hence we can allocate memory at run time within the heap for the variable of a given type using a special operator in C++ which returns the address of the space allocated.This operator is called new operator. As simple new is a language create that dynamically allocates memory from free store and initialises the memory using the constructor

The syntax for new is:

p_var = new type_name;

For example define a pointer to type double and then request that the memory be allocated at execution time.

double* pvalue = NULL; // Pointer initialized with null

pvalue = new double;   // Request memory for the variable

Define freestore (heap).

Ans -


Dynamic allocations with new/delete are said to take place on the free-store,

What is the delete operator used for?

Ans - The delete operator destroys the object created with new by deallocating the memory associated with the object.Hence Memory allocated by new must be deallocated using delete operator.

Write the C++ code to delete a pointer.

{

int *p = new int;

int *pA = new int[10];

delete p;

delete [] pA;

{

    delete ppArr[indx];

}

delete [] ppArr;

What is a dangling pointer?

Ans – it is define as a pointer is a pointer that points to invalid data or to data which is not valid anymore, for example:

Class *obj = new Class();

Class *obj2 = obj;

delete obj;

obj = nullptr;

Obj *method()

{

Obj obj;

return &obj;

}

Obj *obj2 = method();

// object2 points to an object which has been removed from stack after exiting the function

What unfortunate misinterpretation can occur with the following declaration?

int* intptr1, intptr2;

Ans –

Create a dynamic allocated array with ten array elements of type double.

Ans- given are the code;

int main( )

{ IntP p;

int a[10];

int index;

for (index = 0; index < 10; index++)

a[index] = index;

p = a;

for (index = 0; index < 10; index++)

cout << p[index] << " ";

cout << endl;

for (index = 0; index < 10; index++)

p[index] = p[index] + 1;

for (index = 0; index < 10; index++)

cout << a[index] << " ";

cout << endl; return 0;

}

Write the C++ code to delete the dynamic allocated array a.

using namespace std;

int main ()

{

   double* pval = NULL; // Pointer initialized with null

   pval = new double;   // Request memory for the variable

   *pval = 29494.99;     // Store value at allocated address

   cout << "Value of pval: " << *pval << endl;

   delete pval;         // free up the memory.

   return 0;

}

T / F The “this” pointer is a predefined pointer that points to the calling object.

Ans -true

Define copy constructor.

Ans- The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously.it is also a member function which initializes an object using another object of the same class.

A copy constructor has the following general function prototype:

classname (const classname &obj) {

   // body of constructor

}

What is a destructor?

Ans- A destructor is a special member function of a class which is executed when an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.

A destructor will have exact same name as the class prefixed having tilde (~) and it can neither return a value nor can it take any parameters.

class A

{

public:

~A();

};

What must the name of a destructor be?

Ans- The name of the destructor must be same as the class name.

When is a destructor called?

Ans - In C++ , when u call the destructor yourself when you no longer need the class, just like any other function. Like a constructor, you do not need to have a destructor. If your class has no resources to clean-up after there is no need for a destructor.

What does a destructor actually do?

Ans- In simple way if a constructor acquires resources, a destructor should release them; if a constructor establishes a relationship between entities then the destructor should terminate that relationship.

What should a destructor do?

Ans-A class's destructor automatically destroys all base classes and members also.Wheever Destructor destroys the object used to call it. It does not destroy all instances of a particular class at once, but it is invoked every time an object of that class is destroyed.

If a class is named MyClass and it has a constructor. What is the constructor named? If MyClass has a destructor, what is the destructor named?

Ans- its is same as name MyClass for both constructor and destructor.

Explain carefully why no overloaded assignment operator is needed when the only data consists of built in types. What about a copy constructor? A Destructor?

Ans-

The following is the first line of the copy constructor definition for the class PFArrayD. The identifier PFArrayD occurs three times and means something slightly different each time. What does it mean for each of the three cases?

PFArrayD::PFArrayD(const PFArrayD& pfaObject);

Ans-

What are the three instances when a copy constructor is called automatically?

Ans – the copy constructor having three instances which are:

1.       When instantiating one object and initializing it with values from another object (as in the example above).

2.       When passing an object by value.

3. When an object is returned from a function by value.

What is the difference between a shallow copy and a deep copy?

Ans In simple , shallow Copies the member values from one object into another It is a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.

Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated Copies the member values from one object into another. Any pointer objects are duplicated and Deep Copied.

Input & Output in C++ occurs as ____SEQUENCE_______ o f bytes.

Member function _FLAG__________ can be used to set and reset format state.

Most C++ programs should include the ___IOSTREAM_____ header file that contains the declaration required for all stream I/O operations.

When using parameterized manipulators, the header file _____ iomanip_____ must be included.

Input operations are supported by ___ keyboards and mouses __________.

Output operations are supported by ___ printers __________.

The symbol for the stream-insertion operator is ____ << ________.

The symbol for the stream-extraction operator is __>>___________.

The stream manipulators _______, __________, and ________ specify that integers should be displayed in octal, hexadecimal, and decimal formats, respectively.

When used, the _____ stream manipulator causes positive numbers to display with a plus sign.

T / F Every input and every output file used by your program has two names.y

Write the C++ statements that will allow you to read from a file, myfile.txt.

Write the C++ code to close the file describe in #37.

Write the C++ code to append to the file, myfile2.text.

Ans- for append

#include <fstream>

int main() {

std::ofstream outfile;

outfile.open("test.txt", std::ios_base::app);

outfile << "Data";

return 0;

}

A programmer has read half of the lines in a file. What must the programmer do to the file to enable reading the first line a second time?

What member function does every input file stream have that can be used to test for reaching the end of the input file?

Ans – here get function is used for every input .

What is the type of the stream cin?

What is the type of the stream cout?

Ans

Member functions __________ and _________ of istream and ostream set the file position pointer to a specified location in an input or output stream, respectively.

A _______ is a flow of characters.

A ___table/file____ is a group of related records.

When your program takes input from a file, it is said to be reading________ from the file.

When your program sends output to a file, it is said to be _writing______ to a file.

Define derived class.

ANS- A derived class is a class that inherits the properties from its super class.

EXAMPLE

class vehicle
{
     int fuel;
       public:
            drive();
};

class car : public class vehicle
{
       public:
       roll();
};

class bike : public class vehicle
{
       public:
       kick();
};

The stream manipulators that format justification are __left_______ and ___right________.


Dynamic allocations with new/delete are said to take place on the free-store,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote