Ask Computer Engineering Expert

Lab Assignment

For this lab you may work with a partner, or you may choose to work alone. If you choose to work with a partner, you are still responsible for the lab in its entirety, even if you partner is abducted by aliens and mind melded with a two-toed sloth.

For this lab, you should still only have one file. As with Lab 1, your file should start with comments including your name(s), etc., followed by your included files, and then your function declarations in the order in which the functions are written in the lab.
Your main should follow, calling each of the functions and, if needed or helpful, initializing variables before function calls and printing out values and arrays.

Following the main should be each of your functions in the order in which they are specified below.
Make sure your code is formatted and commented.

Functions:

Note that for functions 1 through 7, you only need one test case.

1. Write a function that takes no input parameters and returns nothing (void). Inside the function, create a variable of type int, and give that variable a value (I'm not picky here). Print out both the value and the address of the variable.

2. Write a function that takes as an input parameter an integer and returns nothing (void). Add 4 to that integer inside the function.Inside the function, print out both the value and the address of that variable.

In main, create an integer variable, and give it a value (your choice). Print out both the value and the address of that variable. In your comments, note what this type of function call this is.

3. Write a function that takes no input parameters and returns an integer. Inside the function, create an integer variable, and set the variable to be a random number between 0 and 50 (excluding 50). Print out the value and the address of this variable. Return this value from the function.

Now in your main function, set an integer variable to this returned value. Print out both the value and the address of this integer.

4. Write a function that takes as an input parameter an address of an integer and returns nothing (void). Inside the function, take the value at the address in the parameter and cube it. Print out the value at the address, the address in the parameter, and the address of the parameter.

In main, create an integer variable (and give it a relatively small number for testing purposes). Print out both the value and the address of that variable. Then call the function. Repeat the process of printing out the value and the address of this variable. In your comments note what type of function call this is.

5. Write a function that takes as an input parameter an alias for an integer and returns nothing (void). Inside the function, create a variable and set its value to a random number between 0 and 10. Add that random number to the input parameter. Print out the random number, the new value, and the address of the input parameter.

In main, create an integer variable (and give it a relatively small number for testing purposes). Print out both the value and the address of that variable. Then call the function. Repeat the process of printing out the value and the address of this variable. In your comments note what type of function call this is.

6. Write a function that uses call by pointer with 2 int addresses as parameters, with the function returning nothing (void). In the function, create a variable that is of type int address. Set the variable to the address in the first parameter, and change the value at that address to 32 using the local variable (the one created inside the function). Then change the address in the variable so it holds the address in the second parameter. Change the value at that address to 42 using the local variable.

In main, create 2 integer variables, setting the first to 10 and the second to 20. Call the function using the address of the 2 integers. Print out the values in the 2 variables after you call the function.

7. In your main, create a bunch of character variables and use them to print out a word (like we did in class with "google"). Now write a function that uses call by value, call by reference, and call by pointer (it doesn't have to be in that order) to modify the characters to new characters. Back in main, print out your new word (like "cold"). Note that "google" and "cold" have already been used and thus can't be used for this assignment.

8. Write a function that takes as input parameters an integer, and an address of an integer (a pointer to an integer). Inside the function, create an array the length of the first integer. Fill in the array with random numbers between 0 and 500. Print out the array. Modify the second parameter so that it points to the largest value in the array you just created.

In your main, create an integer variable and set it to -1. Create a second integer variable and set it to 15.

Call the function with the second integer as the length, and the address of the first integer.

In Main print out the first variable.

Call the function again, with the second integer as the length and the first variable.

In Main, print out the first variable

Call the function a third time, with the second integer as the length and the first variable.

In Main, print out the first variable. The value printed out should be the largest random number generated in all three calls to the function.

Note: for readability, to print out an array, you could do this:

cout<

And then when the loop is done (outside the loop) you could do

cout<

Your array will look something like this:

32, 41, 253, 439, 19, 273, 384, 212, 97, 116, 193, 269, 321, 449, 182

Note 2: We haven't seen how to pass arrays and return arrays yet. However, if you want to give it a shot and write 2 separate helper functions, you may. One would take as input an array and fill that array with random numbers, and the other helper function would print out the values in an array. If, however, you prefer to do all this within one function, that is fine for this lab.

9. Write a function that takes as input parameters a length parameter (an int), and two more int parameters that will be modified using pass by reference. When the function is called the second and third parameters are initialized to -1 (before the function call). The function should should generate a random array the length of the length parameter, with the numbers between 100 and 300. The function should print the array, and then locate the smallest value in the array, modifying the third parameter to be the smallest value and the fourth to be the index location of the smallest value. Make sure you print these values after you've returned from the function.

10. Write a function that takes an input parameter an int and returns nothing. It then generates an array of random numbers the length of the int parameter. It fills the array with random numbers between 0 and 50. It then prints out the array.

Without creating a new array, the function then reverses the array and prints out the reversed array.

So if the first array was:
22,10,8,5,3,18
The reversed array would be:
18,3,5,8,10,22

11. Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49.

The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number in the array with the second parameter +1 (so in our above example, it would be 51. ) Continue to do this until every number in the original array is printed out in order.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92704989

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As