I need the coding as simple as they can be.
13.3 Homework Assignment
(Basic Pointers and Pointer Arithmetic) Write a program that will do the following:
• Create two integer variables x and y, and an integer array z[5]
• Set the variable x equal to 5, and the variable y equal to 10
• Save the following values in the array: 1, 2, 4, 8, 16
• Print to screen the address of each of the variables, x, y, and the start of the
array z
• Create a pointer named testPtr and point it to the variable x
• Print to screen the value stored in variable x using only your pointer testPtr
• Add six to the value stored in x using only your pointer testPtr
• Print to screen the value stored in variable x using only your pointer testPtr
• Test to see if the value stored in variable x is larger than y, using only the
variable y and the testPtr. If it is, print to screen “x > y”, otherwise print “y < x"
• Now, change testPtr to Point to the first entry of the array z
• Using only testPtr, use a counter and for loop to print all the value in the array
(do not use the array).
14
(Pointers and Functions)
Write a void function called swap that accepts as inputs two integer
variables and swaps their values. For example, if I had a variable
a = 5 and b = 10, after calling swap with variables a and b; a = 10
and b = 5. Note this will require writing the function such that it
uses pointers since we want to change the original variables and
return nothing (void).
15
13.3 Homework Assignment
(Basic Pointers and Pointer Arithmetic) Write a program that will do the following:
• Create two integer variables x and y, and an integer array z[5]
• Set the variable x equal to 5, and the variable y equal to 10
• Save the following values in the array: 1, 2, 4, 8, 16
• Print to screen the address of each of the variables, x, y, and the start of the
array z
• Create a pointer named testPtr and point it to the variable x
• Print to screen the value stored in variable x using only your pointer testPtr
• Add six to the value stored in x using only your pointer testPtr
• Print to screen the value stored in variable x using only your pointer testPtr
• Test to see if the value stored in variable x is larger than y, using only the
variable y and the testPtr. If it is, print to screen “x > y”, otherwise print “y < x"
• Now, change testPtr to Point to the first entry of the array z
• Using only testPtr, use a counter and for loop to print all the value in the array
(do not use the array).
14
(Pointers and Functions)
Write a void function called swap that accepts as inputs two integer
variables and swaps their values. For example, if I had a variable
a = 5 and b = 10, after calling swap with variables a and b; a = 10
and b = 5. Note this will require writing the function such that it
uses pointers since we want to change the original variables and
return nothing (void).
15
1. (Writing to a file). A damped sine wave is a sinusoidal function whose amplitude approaches zero as
time increases.
( ) ( ( ))
Write a program that will generate a data file containing 100 value points (Y(t)) from a damped sine
function. Make use of the math library functions for the exponent and sine calculations. Use the
following formula for time: t = (k-1)/10.0 where 1 ≤ k ≤100. Make sure that each record in your data file
contains the fields for time and its corresponding Y(t).
2. (Reading from a file). The data file power1.dat contains a power plant output in megawatts over a
period of 8 weeks. Each row of data contains 7 integers that represent 1 week’s data. Write a program
that will compute and print to a file and to the screen the average power output over this period of
time. Also print the number of days with greater-than-average power output.