THIS IS SOURCE CODE THAT YOU HAVE TO USE. THEN THIS IS THE TASK C++ PLS FINISH FOLLOWING TASK AND DON'T FORGET TAKE SCRE

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

THIS IS SOURCE CODE THAT YOU HAVE TO USE. THEN THIS IS THE TASK C++ PLS FINISH FOLLOWING TASK AND DON'T FORGET TAKE SCRE

Post by answerhappygod »

THIS IS SOURCE CODE THAT YOU HAVE TO USE.
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 1
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 1 (160.2 KiB) Viewed 48 times
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 2
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 2 (79.7 KiB) Viewed 48 times
THEN THIS IS THE TASK
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 3
This Is Source Code That You Have To Use Then This Is The Task C Pls Finish Following Task And Don T Forget Take Scre 3 (80.1 KiB) Viewed 48 times
C++ PLS FINISH FOLLOWING TASK AND DON'T FORGET TAKE SCREENSHOT
Program 11-8 Contents of NumberArray2.h 1 #include <iostream> 2 using namespace std; 3 4 class NumberArray 5 { 6 private: 7 double *aPtr; 8 int arraySize; 9 public: 10 NumberArray (NumberArray &); 11 NumberArray (int size, double value); (program continues) Copy Constructors 701 Program 11-8 (continued) 12 -NumberArray() { if (arraySize > 0) delete [] aptr; } 13 void print(); 14 void setValue( double value); 15 }; * * * * ********** ********* Contents of NumberArray2.cpp 1 #include <iostream> 2 #include "NumberArray2.h" 3 using namespace std; 4 5 //********* 6 //Copy constructor allocates a new 7 //array and copies into it the entries 8 l/of the array in the other object. 9 //********* 10 NumberArray:: NumberArray (NumberArray &obj) 11 { 12 arraySize = obj.arraySize; 13 aPtr = new double[ arraySize]; 14 for(int index = 0; index < arraySize; index++) 15 aPtr[index] = obj.aPtr[index]; 16 } 17 18 //********* 19 //Constructor allocates an array of the 20 //given size and sets all its entries to the 21 1/given value. 22 //********* 23 NumberArray: : NumberArray(int size, double value) 24 { 25 arraySize = size; 26 aPtr = new doubleſ arraySize]; 27 setValue(value); 28 } 29 30 // ****************************************************** 31 //Sets all the entries of the array to the same value. 32 //******** 33 void NumberArray::setValue(double value) 34 { 35 for(int index = 0; index < arraySize; index++) 36 aPtr[index] = value; 37 } 38 39 //********* 40 1/Prints all the entries of the array. 41 //********* 42 void NumberArray: :print() 43 { 44 for(int index = 0; index < arraySize; index++) 45 cout << aPtr[index] << " "; 46 } ****** * ***** * ***** (program continua

Program 11-8 (continued) Contents of Pri1-8.cpp 1 // This program demonstrates the use of copy constructors. 2. #include <iostream> 3 #include <iomanip> 4 #include "NumberArray2.h" 5 6 using namespace std; 7 8 int main() 9 { 10 NumberArray first(3, 10.5); 11 12 1/Make second a copy of first object. 13 NumberArray second = first; 14 15 // Display the values of the two objects. 16 cout << setprecision(2) « fixed « showpoint; 17 cout << "Value stored in first object is "; 18 first.print(); 19 cout << "\nValue stored in second object is "; 20 second.print(); 21 cout << "\nOnly the value in second object will" 22 "be changed. \n"; 23 24 //Now change value stored in second object. 25 second.setValue(20.5); 26 27 // Display the values stored in the two objects. 28 cout << "Value stored in first object is "; 29 first.print(); 30 cout << endl << "Value stored in second object is "; 31 second.print(); 32 return 0; << 33 }

3.2 Task One: Program 11-8 (Page 700-702). (40 marks) (1)Input source code and compile it. Run the program and capture screenshots of output. (20 marks) (2)Change NumberArray to CharArray . Do not forget change code in main function. (20 marks) //Contents of CharArray.h #include <iostream> using namespace std; class CharArray 3 { private: char *aPtr; int arraySize; public: CharArray(CharArray &); CharArray(int size, char value); -CharArray() { if (arraysize > 0) delete [] aptr; } void print(); void setValue(char value); Example running result is shown as below(you can change test data): Value stored in first object is z z z Value stored in second object is z 2 z Only the value in second object will be changed. Value stored in first object is z zz Value stored in second object is a a a
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply