The multi-purpose sorting program that function pointers

Assignment Help C/C++ Programming
Reference no: EM13890722

1.  Consider the following code:int nums[10] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

int *pInt;
pInt = &nums[7];
pInt -= 2;
*pInt = 15;

What will be the resulting array when this code is completed? Explain.

2.  Consider the following code:

int i;
int smallest;

int nums[10] = {4, 20, 18, 7, 2, 19, 50, 6, 74, 37};

smallest = nums[0];
for (i = 1; i < 10; i++) {
if (nums[i] < smallest) smallest = nums[i];
}
cout << smallest;

a. Rewrite the code using pointers. Specifically, instead of i and smallest, use

int* pInt;
int* pSmallest;

b. Which version of the code do you find easier to read?

3.  Take the multi-purpose sorting program that uses function pointers. Create a new auxiliary function such that the routine will sort numbers in ascending order, but all zeros will be placed at the end of the list. For example, an array with 3, 0, -5, 9, 22, 0, 14, 7 would be set to -5, 3, 7, 9, 22, 0, 0.

4. Create a BaseballBatter class that records the batting statistics for an individual player. It should have "get" and "set" methods for the following values: at-bats, singles, doubles, triples, and home runs. The "set" methods should check that only non-negative values are set. In addition, the class should have the following methods:

a. A validData method that returns true if the number of at-bats is greater than the number of hits.
b. A battingAverage method that returns the batting average.
c. A sluggingPercentage method that returns the slugging percentage (google the term if you are unfamiliar with it).

Create a simple main function to test your class and split the program into three files as before.

Reference no: EM13890722

Questions Cloud

Calculate the individual costs and wacc : Calculate the individual costs and wacc. Dillon Labs has asked its financial manager to measure the cost of each specific type of capital as well as the weighted average cost of capital. The weighted average cost is to be measured by using the follow..
The following three separate situations require adjusting : 1.The following three separate situations require adjusting journal entries to prepare financial statements.
Case study : forensic evaluation : Write a set of cross-examination questions you might anticipate being asked, explain what your responses might be, and explain how you would prepare to testify in response to these questions.
Staged investment-the option to expand : Consider an investment opportunity with an option to grow that requires a $10m investment today. In one year we will find out whether the project is successful or not. The probability that the project will generate $1M per year in perpetuity is 50%. ..
The multi-purpose sorting program that function pointers : 3.  Take the multi-purpose sorting program that uses function pointers. Create a new auxiliary function such that the routine will sort numbers in ascending order, but all zeros will be placed at the end of the list. For example, an array with 3, 0, ..
Methods help the investment : Which of the following methods help the investment?
Reply to both of the given posts : Directions: In 200-300 words each you must reply to both of the classmates post below. Be sure to label each reply so that I know which one you are addressing. Please note that "I like what you said," "That's a good point," and "I disagree with yo..
Missing amounts in each of these four separate situations : 1.Determine the missing amounts in each of these four separate situations a throughd.
What determines stocks fundamental value : What determines a stock's fundamental value? How has the Federal Reserve System affected the value of stock? Explain.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Mark the following statements as true or false

Mark the following statements as true or false.

  Find out if damjibhai can win

Once a jewel type is removed from the necklace, all other instances of the same jewel type is treated as polished by the person who removed the jewel

  Calculate the modified value of the first character of input

To calculate the modified value of the first character of input we add its mapped value to the mapped value from the first character of the encryption string.

  Explain about the hierarchical model

Explain about the Hierarchical Model, Network Model, Relational Model and Object-Oriented Model

  Programming sum of the squares

Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the user enters a positive integer.

  Implement uniform random number generator

Implement Uniform Random Number generator and Generate 1000 Random number between 0 an 10000. Try to use insertion sort to sort them. Compare the running time of two versions of the insertion sort.

  Compare run times using an array

Write a iterative and recursive versions of binary search and compare their run times using the array a[i]=i, i=0,...,n-1 and the subsequent test method:

  Write a c program that declares an array alpha of 50

write a c program that declares an array alpha of 50 components of the type double. initialize that array so that the

  Write a function named concatenate

If the function discovers that the number of cells in the large array is not large enough to hold all the numbers to be copied into it, then the function should return 0 to indicate failure.

  Give a complete pseudo-code description of the recursive

Give a complete pseudo-code description of the recursive merge-sort algorithm that takes an array as its input and output.

  Function declare that it can throw an ioexception

Every C++ function that performs file I/O will thus need to either declare that it can throw an IOException, or contain a try-catch-finally block to deal with it. Response?

  What does the following display

Given the subsequent array definition: double rainfall[] = {1.4, 1.2, 3.4, 1.8, 1.6}; what does the following display?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd