Question

1. Write TWO different but equivalent statements to do the same thing: use a for statement...

1. Write TWO different but equivalent statements to do the same thing: use a for statement to print the elements of array numbers by using pointer ptr.

2. Write an expression that uses ptr to copy element 1 (zero-based) of the array to element 3. Do not use numbers in the array in

Here is the start of a class declaration:
class foo
{
public:
void x(foo f);
void y(const foo f);
void z(foo f) const;
...
3. Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function?

a. All of the functions can alter the private member variables of the object that activates the function.

b. Only z can alter the private member variables of the object that activates the function.

c. Only x can alter the private member variables of the object that activates the function.

d. Only y can alter the private member variables of the object that activates the function.

Two of the functions can alter the private member variables of the object that activates the function.

your answer.

PLEASE HELP!!! THESE ARE SEPERATE QUESTIONS! DON"T POST OLD ANSWERS

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

1)
answer:
statement1:
for(int i=0;i<n;i++)//assuming length of the array is n
cout<<*(ptr+i);
statement2:
for(int i=0;i<n;i++)//assuming length of the array is n
cout<<ptr[i];

2)
answer:
ptr[2]=ptr[0];//copying element1 of array to element3

3)
Answer:
functions x and y can alter the private member variables of the object that activates the function.

Add a comment
Know the answer?
Add Answer to:
1. Write TWO different but equivalent statements to do the same thing: use a for statement...
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
  • Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of...

    Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function? A. Only x can alter the private member variables of the object that activates the function. B. Only y can alter the private member variables...

  • Data Structures using C++ Here is the start of a class declaration: class ClassA { public:...

    Data Structures using C++ Here is the start of a class declaration: class ClassA { public:        void func1(const ClassA& a);        void func2(const ClassA& a) const;        void func3(ClassA a) const;        ... Which of the three member functions can alter the private member variables of the ClassA object that activates the function? A. None of the three functions. B. Only func1.       C. Only func2.       D. Only func3. E. Only two of the three functions.

  • C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object...

    C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object from another of the same type. II. Copy an object to pass it as argument to a function. III. Copy an object to return it from a function. Read the following program and answer questions (20 points) #include <iostream> using namespace std; class Line public: int getLength( void); Line( int len // simple constructor Line( const Line &obj) 1/ copy constructor Line (); //...

  • In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to...

    In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to make the displayAnimal function anim parameter as an object variable, not a reference variable. Run the code and examine the output. What has changed? Polymorphic behavior is not possible when an object is passed by value. Even though printClassName is declared virtual, static binding still takes place because anim is not a reference variable or a pointer. Alternatively we could have used an Animal...

  • Your will write a class named Gasket that can be used to build Gasket objects (that...

    Your will write a class named Gasket that can be used to build Gasket objects (that represent Sierpinski gaskets) that you can display graphically.  Your Gasket class is defined in the provided file Gasket.h.   DO NOT CHANGE the file Gasket.h.  The attributes and methods defined for class Gasket are described below.     ·sideLength            an int that holds the length of each side of the Gasket.  The length of the side is measured as a number of pixels ·xLocation              an int that holds the x coordinate (in pixels)...

  • you will write a templated array class. Called MyArray with member variables ptr and array_size. This...

    you will write a templated array class. Called MyArray with member variables ptr and array_size. This array must use dynamic memory--see program shell, names should remain unchanged. The following is a list of required member functions of the array class along with a rubric: (1pts) program compiles (2pts) default constructor (2pts) parametered constructor which feeds MyArray a size. (10pts) copy constructor 8pts for performing a *deep* copy 2pts for correct syntax (10pts) overloaded = operator 7pts for functioning properly 3pts...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • Goals: Write your own class. Instantiate an object of your class. Interact with the object's public...

    Goals: Write your own class. Instantiate an object of your class. Interact with the object's public interface. Requirements: Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically allocate the array to hold that many numbers. The destructor should free the memory held by the array. In addition, there should be member functions to perform the following operations: Store a number in any element of the array - accepts an integer...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

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