Programing Assignment Arrays
Programing Assignment Arrays
1. True/False
a. True
b. True
c. False (Arrays are passed by pointer, not by value or reference directly)
d. False
e. True
f. False (No aggregate operations allowed)
g. False (Updates the sixth component)
h. False
i. True
j. False (Array size is 16)
k. False (Invalid declaration)
l. False
2. Array Declaration
a. salary
b. 10
c. double
d. 0 to 9
3. Errors in Declarations
a. Valid
b. Error: constint → const int; SIZE undefined
c. Error: Use int numList[10];
d. Valid (if using namespace std;)
e. Error: Syntax → double scores[50];
4. Valid Declarations
a. Invalid (Not an array)
b. Invalid (Size not constant)
c. Invalid (Negative size)
d. Invalid (Non-integer size)
cpp
Copy
Download
7. Program Output
Copy
Download
-3 -1 1 3 5
5 -1 8 3 -1
8. Final Array
[2, 7, 6, 11, 10]
9. Final Array
[5, 6, 9, 19, 23, 37]
cpp
Copy
Download
int myList[10];
for (int i = 0; i < 10; i++) cin >> myList[i];
for (int i = 0; i < 10; i++) cout << myList[i] << " ";
cpp
Copy
Download
cout << i << " and " << (i + 1) << " are out of order." << endl;
16. Output
Copy
Download
0 -2
16
2 -12
31
4 13
19. Output
Copy
Download
1 25000.00 750.00
2 36500.00 1095.00
3 85000.00 2550.00
4 62500.00 1875.00
5 97000.00 2910.00
cpp
Copy
Download
total += cars[i];
maxCars = cars[i];
maxIndex = i + 1;
}
}
cout << "Total: " << total << "\nSalesperson " << maxIndex << " sold " << maxCars << endl;
21. Output
11 16 21 26 30
22. Output
5 15 25 35 45 28 33 38 43 48
23. Output
Each line shows cylinder number, radius, height, and lateral surface area.
cpp
Copy
Download
else
31. 2D Array
cpp
Copy
Download
cpp
Copy
Download
alpha[i][j] = 0;
cpp
Copy
Download
alpha[i][j] = 2;
d. Columns as multiples:
cpp
Copy
Download
alpha[i][0] = 5;
alpha[i][j] = 2 * alpha[i][j-1];
e. Print row-wise:
cpp
Copy
Download
f. Print column-wise:
cpp
Copy
Download
cpp
Copy
Download
b. Calls:
cpp
Copy
Download
print(times, 30);
print(speed, 15);
print(trees, 100);
print(students, 50);