For each of the following, write C++ statements that perform the specified task. Assume that double-precision, floating-point numbers are stored in eight bytes and that the starting address of the array is at location 1002500 in memory. Each part of the exercise should use the results of previous parts where appropriate.
a) Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2, ..., 9.9. Assume that the symbolic constant SIZE has been defined as 10.
b) Declare a pointer nPtr that points to a variable of type double.
c) Use a for statement to print the elements of array numbers using array subscript notation. Print each number with one position of precision to the right of the decimal point.
d) Write two separate statements that each assign the starting address of array numbers to the pointer variable nPtr.
e) Use a for statement to print the elements of array numbers using pointer/offset notation with pointer nPtr.
f) Use a for statement to print the elements of array numbers using pointer/offset notation with the array name as the pointer.
g) Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr.
h) Refer to the fourth element of array numbers using array subscript notation, pointer/off-set notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr.
i) Assuming that nPtr points to the beginning of array numbers, what address is referenced by nPtr + 8? What value is stored at that location?
j) Assuming that nPtr points to numbers[ 5 ], what address is referenced by nPtr after nPtr -= 4 is executed? What is the value stored at that location?
a) ```
double numbers[ SIZE ] =
{ 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
```
b) ```
cout << fixed << showpoint << setprecision( 1 );
for ( int i = 0; i < SIZE; i++ )
cout << numbers[ i ] << ' ';
```
d) ```
nPtr = numbers;
nPtr = &numbers[ 0 ];
```
e) ```
cout << fixed << showpoint << setprecision( 1 );
for ( int j = 0; j < SIZE; j++ )
cout << *( nPtr + j ) << ' ';
```
f) ```
cout << fixed << showpoint << setprecision( 1 );
for ( int k = 0; k < SIZE; k++ )
cout << *( numbers + k ) << ' ';
```
g) ```
cout << fixed << showpoint << setprecision( 1 );
for ( int m = 0; m < SIZE; m++ )
cout << nPtr[ m ] << ' ';
```
h) ```
and pointer/offset notation with nPtr. ANS: numbers[ 3 ]
*( numbers + 3 )
nPtr[ 3 ]
*( nPtr + 3 )
```
i) The address is 1002500 + 8 * 8 = 1002564. The value is 8.8.
j) The address of numbers[ 5 ] is 1002500 + 5 * 8 = 1002540.
The address of nPtr -= 4 is 1002540 - 4 * 8 = 1002508.
The value at that location is 1.1.
You might also like to view...
What is the output of the following code fragment?
{ int x=13; cout << x <<","; } cout << x << endl; a. 13,13 b. 0,13 c. 13,0 d. nothing, there is a syntax error.
Please provide the best answer for the following questions.
The passwords for switch S1 and Router R1 are as follows:
? Console password: ciscopress
? Privileged EXEC mode password: ciscopress
? Enable secret: ciscopress
1. Your first task is to configure the IP address for VLAN1. The IP address is provided in Table 1. Enable the VLAN1 interface. List the command sequence required to accomplish this task. Indicate both the prompts and the commands.
2. Next, configure the IP addresses for computers PC1 and PC2, server S1, and Router R1. After you have completed this task, verify that you have network connectivity from the switch SW1 to the computers and server. List the command sequence required to accomplish this task.
3. Next, use the command that displays the current VLAN interface information.
4. Which ports currently belong to the default VLAN?
5. How many VLANs are set up by default on the switch? List the VLANs.
6. In the next step, you are to create two VLANs, VLAN2 (Fina
A calculation for a group of data such as a total, an average, or a count
A) Group formula B) Calculated column C) Summary statistic
Any changes made in the source file will also be reflected in the file that contains the linked object
Indicate whether the statement is true or false