Question 1: Given a two-dimensional array declaration, describe two different me
ID: 3557743 • Letter: Q
Question
Question 1: Given a two-dimensional array declaration, describe two different methods on how the all the array elements could be initialized. For example, write the declaration for a two-dimensional array of type integer and set all elements of the array equal to a value of 0.
Question 2: Explain what constructors do and when they are executed. Explain the two types of constructors. Provide an example class that includes both types of constructor functions and demonstrate how an object would be instantiated using both types of constructors.
Question 3: Describe in detail what is contained in each of three areas of a Unified Modeling Language (UML) diagram of a class.
Question 1: Given a two-dimensional array declaration, describe two different methods on how the all the array elements could be initialized. For example, write the declaration for a two-dimensional array of type integer and set all elements of the array equal to a value of 0.
Explanation / Answer
1) Delcaring all int array elements to 0's.in C++ we have following ways to initialize arrays.
1st way: declaring all elements to 0 by using as follows
int arr[3] = {0};
above declaration gives that the all 3 elements of arr array is declared as 0 i.e.
arr[0] = 0;
arr[1] = 0;
arr[2] = 0;
As we know that indexs are start from 0.
2nd Way:
int arr[] = {0,0,0};
this is also same as above and all array elements will be initialized to 0's
// following is the example of declaring array elements to 0's
#include <iostream>
using namespace std;
int main()
{
int arr[3] = {0};
cout<<arr[0]<<arr[1]<<arr[2]<<endl;
int arr2[] = {0,0,0,0};
cout<<arr2[0]<<arr2[1]<<arr2[2]<<arr2[3]<<endl;
return 0;
}
OutPut:
0 0 0
0 0 0 0
2)
A class constructor is a special member function of a class that is executed whenever we create new objects of that class.
After Creation of Object compulsory we should perform initialization then only that object in a position to provide service to others.
At the time of Object Creation some peace of code will execute automatically to perform initialization that peace of code is nothing but
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.