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

1-A data type is simple if variables of that type can hold only one value at a t

ID: 3768922 • Letter: 1

Question

1-A data type is simple if variables of that type can hold only one value at a time.

True or False

2-An array is a structured data type with a fixed number of components. Every component is of the same type, and components are accessed using their relative positions in the array.

True or False

3-Arrays can be passed as parameters to a function either by value or by reference.

True or False

4-A function can return a value of type array.

True or False

5-The size of an array is determined at compile time.

True or False

6-Given the declaration: int list[ 10]; the statement: list[ 5] = list[ 3] + list[ 2]; updates the content of the fifth component of the array list.

True or False

7-Identify error( s), if any, in the following array declarations. If a statement is incorrect, provide the correct statement.  If a statement is correct, type the statement.

double[ 50] salaries;

Answer

8-Write C++ statements to do the following:

a. Declare an array beta of 20 components of type double.

b. Initialize each component of the array beta to 0.

Answer

9-The array beta is defined as following:

double beta[20];

Set the value of the ninth component of the array beta to 70.50.

Answer

10-What is the output of the following program segment?

double temp[ 5];

for ( int i = 0; i < 5; i++)

temp[ i] = pow( i, 2.0) + 2;

for ( int i = 0; i < 5; i++)

cout << temp[ i] << " ";

Answer

11-What is the output of the following C++ code ?

int list[ 10];

list[ 0] = 2; list[ 1] = 3;

for ( int i = 2; i < 10; i++){

list[ i] = list[ i - 1] + list[ i - 2];

if ( i > 7)

list[ i] = 2 * list[ i] - list[ i - 2]; }

cout<<list[0]+list[5]+list[8]+list[9]<<endl;

12-Write C++ statements to define and initialize the following arrays.

a. Array named heights of 10 components of type double. Initialize this array to the following values: 5.2, 6.3, 5.8, 4.9, 5.2, 5.7, 6.7, 7.1, 5.10, 6.0.

Answer

13-Is the following array declaration are valid.

int list[ 7] = { 12, 13, , 14, 16, , 8};

True or False

14-Consider the following declaration:

int list[] = { 3, 8, 10, 13, 6, 11};

Write a C++ code that will output the value stored in each component of list.

Answer

15-What is the output of the following C++ code?

# include < iostream>

using namespace std;

int main() {

int beta[ 7] = { 3, 5};

for ( int i = 2; i < 7; i++) {

beta[ i] = 3 * i + 2;

beta[ i - 1] = beta[ i - 1] + beta[ i];

beta[ i - 2] = beta[ i - 2] + beta [ i - 1]; }

for ( int i = 0; i < 7; i++)

cout << beta[ i] << " ";

return 0; }

Answer

16-What is the output of the follwoing code?

int n[] = {2,3,4,5,6,7,8,9,10};

for(int i = 2; i < 10; i++)

cout<<n[i]<<" ";

a. 4-10

b. 2-10

c. 3-10

d. 5-10

17-What is the output of the following program?

int num[] = {25,8,10,15,3,5,20,1};

int s = 3;

Answer

18-Write the code to initialize all elements of array list to 3.6;

double list[] = {3,4,6,8,12,14,15};

for(int i = 1; i < 6; i++)   

if(num[i] % 5 == 0)

s += num[i];

cout<<s;

Answer

Explanation / Answer

1. True ..because if use int a = 10 it hold only one value
2. True
3. True
4. True ...
C programming does not allow to return an entire array as an argument to a function. However, you can return a pointer to an array by specifying the array's name without an index.
5. True
6. True
7. Correct ..
we can declare array like also..
double[50] salaries;
8. Answer :
// Declare Array beta of 20
    double beta[20];
   // Initialise beta elements to 0
   for (int i =0; i <20;i++)
       beta[i] = 0.0

9. Answer :
   // Because Array Index start from 0 so 9th place means 8 index
   beta[8] = 70.50;
     
10 Answer is:
   2 3 6 11 18
  
11. Answer is:
   After Completing the all the computation result is: 510
  
12 Answer is:
// Declare hight array of 10 elements
double height[]= {5.2, 6.3, 5.8, 4.9, 5.2, 5.7, 6.7, 7.1, 5.10, 6.0};

13. Answer is False..It is not right way of declare array element it will give the complie time errors

14. Answer is below:

int list[] = { 3, 8, 10, 13, 6, 11};

//Print the list elements
for(int i = 0; i< 6;i++)
   cout<<list[i]<<" ";

15. Answer is:
   16 32 44 56 68 37 20
  
16. Answer is index elements from 3 to 10..
4 5 6 7 8 9 10 9

17. Answer is: 15

18. Question is mismatch..

   double list[] = {3.6, 3.6, 3.6, 3.6, 3.6, 3.6}
  
Update the code part to very clear..