ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 9.00

Create two integer variables named x and y

I need an assignment completed, here are the details: 

 

  1. Create two integer variables named x and y
  2. Create an int pointer named p1
  3. Store the address of x in p1
  4. Use only p1 (not x) to set the value of x to 99
  5. Using cout and x (not p1), display the value of x
  6. Using cout and the pointer p1 (not x), display the value of x
  7. Store the address of y into p1
  8. Use only p1 (not y) to set the value of y to -300
  9. Create two new variables: an int named temp, and an int pointer named p2. Make p2 point to x.
  10. Use only temp, p1, and p2 (not x or y) to swap the values in x and y (this will take a few statements. Don't use a swap function)
  11. Write a function with the following signature: void noNegatives(int *x). The function should accept the address of an int variable. If the value of this integer is negative then it should set it to zero
  12. Invoke the function twice: once with the address of x as the argument, and once with the address of y. Use x or y for the argument (not p1 or p2)
  13. Use p2 to display the values in x and y (this will require both assignment statements and cout statements). You can use x and y in assignment statements, but not in your cout statement. this should produce the output
    x is: 0
    y is: 99
        
  14. Create an int array named 'a' with two elements. Make p2 point to the first element of a.
  15. Use only p2 and x (not a) to initialize the first element of a with the value of x.
  16. Use only p2 and y (not a) to initialize the second element of a with the value of y
  17. Using cout and p2 only, display the address of the first element in a
  18. Using cout and p2 only, display the address of the second element in a
  19. Use p1, p2, and temp to swap the values in the two elements of array 'a'. (first point p1 at a[0], then point p2 at a[1], then do not use "a" again. After this the swapping steps should look very similar to step 10. Don't use a swap function.)
  20. Display the values of the two elements. (The first element should be 99, the second 0).
  21. Write a function named 'swap' that accepts two pointers to integers as arguments, and then swaps the contents of the two integers. Do not use any reference parameters.
  22. Invoke your swap function with the addresses of x and y (using the address-of operator), then print their values. (x should be 99, y should be 0).
  23. Invoke your swap function with the address of the two elements in array 'a', then print their values. (a[0] should be 0, a[1] should be 99)

Answers

(11)
Status NEW Posted 08 May 2017 02:05 AM My Price 9.00

-----------

Not Rated(0)