Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Please help with anbspfunctionnbspcodesymbol to convert

Please help with a function  codeSymbol , to convert each mark to a symbol (A, B, C, D, E, F) and a code (7,6,5,4,3,2,1) according to the table below. And call it in the main function. Use the table below to determine th ...

Kelly and jennifer are roommates kelly loves listening to

Kelly and Jennifer are roommates. Kelly loves listening to rock music and uses the radio in their common area to play it. Jennifer, on the other hand, prefers the peace and quiet around the common area. Answer the follow ...

Consider the following reactionpcl 5 g -----gt pcl 3 g cl2

Consider the following reaction PCl 5 (g) -----> PCl 3 (g) + Cl2 (g) Kc = .0420 The concentrations of the products at equilibrium are [PCl3] = 0.120 M and [Cl2] = 0.160 M. What is the concentration of the reactant, PCl5, ...

Once considered pure science fiction artificial

Once considered pure science fiction, artificial intelligence (AI) is being relied on more and more in today's world. Artificial intelligence deals with algorithms based on complex data sets. If you had to tell story rep ...

Question as you are reviewing the results of your various

Question : As you are reviewing the results of your various scans, what factors do you believe you would take into consideration when determining priority? The priority would be used to determine remediation efforts. So, ...

Suppose the sulfur content of a mineral sample is

Suppose the sulfur content of a mineral sample is determined by complete conversion to Ag2S(s). What mass of sample must be chosen, so that the number of grams of Ag2S(s) obtained is equal to one eighth of the percent su ...

In system analysisdiscuss and give suggestions or comments

In system analysis Discuss and give suggestions or comments for the following questions: 1. Discuss about the project plan (activities and scheduling) 2. What are the new tools and strategies used in project plan or mana ...

What is the various security architectures which provides

What is the various security architectures. Which provides the best balance between simplicity and security? Justify your answer.

Identify and evaluate at least three considerations that

Identify and evaluate at least three considerations that one must plan for when designing a database. Suggest at least two types of databases that would be useful for small businesses, two types for regional level organi ...

Case study 1 user interfacesearly user interfaces were

Case Study 1: User Interfaces Early user interfaces were designed with little or no consideration for the end user. This was largely due to technical and hardware limitations. The poor interface design required a specifi ...

  • 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