Computer Science Homework Solutions
Problem
#133047

C++ array

Consider the C++ array

int arr[] = (-15, 5, 35, -19, -12, 17, -4);

int arrSize = sizeof(arr)/sizeof(int);

(a) Declare the list object intList that holds the integers from the array arr.
(b) Declare the iterator iter for an integer list.
(c) Initialize the iterator iter to the beginning of the list intList.
(d) Assume iter is set to the start of the list.

iter++;
iter++; // what value does iter point at?
cout << *iter; // what is the output?
iter = intList.end();
iter--;
iter--; // what value does iter point at?
cout << *iter; // what is the output?
iter = intList.end();
iter++; // what value does iter point at?
cout << *iter; // what is the output?

(e) Use the iterator to write a code segment that scans the list elements and replaces each negative value by the corresponding positive number.

Please provide a complete program if it makes sense.


Solution Summary

Create a list based on an array, and scan the elements using iterator.

Solution
What is this?
By OTA - Overall OTA Rating
Yanfang Li, PhD - 4.9/5
Purchase Cost Now
$2.19 CAD (was ~$11.97)
Included in Download
  • Plain text response
  • Attached file(s):
    • list1.txt
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Java - What does the following program do? - SomeClass.java - // Exercise 15.13 Solution: SomeClass.java public class SomeClass { public String someMethod( int array2[], int x, String output ) { if ( x < array2.length ) ...
  • Data Structures C++ - 10. What is the output of the following program segment? (Assume that screen is an ostream iterator initialized to the standard output device to output elements of the type int.) int list[5] = {2, ...
  • Data Structures C++ - 4. Write a statement that declares and stores the elements of the following array into a vector object: char vowels[5] = {‘a’, ‘e’, ‘i’, ‘o’, ‘u’}; 8. What is the output of the following pro ...
  • C++ STL Heap - See attached file for full problem description. Answer question #17. - Heaps, Binary Files, and Bit Sets
  • Java Method - Write a method, removeAll, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete all occurrences of removeItem ...
Browse