Provide an implementation of the mymaximum function

Assignment Help Basic Computer Science
Reference no: EM13767286

Exercise 1: Finding the maximum value

int mymaximum(int a[], int numberOfElements);

Provide an implementation of the mymaximum function whose declaration is shown above. The first argument of the function is an array of int and the second argument is the number of ints that are in the array. The function returns the largest int that is in the array.

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 2: Appending integers

void append(vector<int> & v, int n);

Provide an implementation of the function whose declaration is shown above. The first argument of the function is a vector of int and the second argument is the number of consecutive integers to append to the vector starting from 0 and ending at n - 1. The function appends onto the vector v the values 0, 1, 2, ..., n - 1. (Hint: use the push_back function of vector to append these values to v.)

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 3: Appending vectors

void appendVector(vector<int> & v, const vector<int> & w);

Provide an implementation of the appendvector function whose declaration is shown above. Both arguments of the function are vectors of int. The function should modify vector v by appending to it all the elements of w. For example, if v = (4, 2, 5) and w = (11, 3), then v will become (4, 2, 5, 11, 3) as a result of calling the function. Hint: the vector class has a function called push_back that appends values passed into it.

Exercise 4: Vector insertion

Suppose a vector v contains a sequence of integers ordered from lowest to highest. For example, v might contain the values 3, 6, 7, 12.

Write a function called insert that takes this vector v as a first argument and an integer k as the second argument. The function inserts k into the vector so that it preserves the order of elements. For example, if v were (3, 6, 7, 12) and k were 8, then after calling the function, v would be (3, 6, 7, 8, 12). In your implementation of insert, do not use the insert function of the vector class (v.insert).
Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 5: Counting occurrences

int countOccurrences(const vector<int> & v, int k);
Implement the function countoccurrences whose declaration appears above. The first argument of the function is a vector v of integers and the second argument is an integer k. The function returns the number of times k occurs in v.

Exercise 6: Two-dimensional arrays

bool isAllZeros(int a[50][100]);

Implement the function isAllZeros that uses a loop nested inside another loop to determine whether a 2-dimensional array contains only zeros. A declaration of the function is shown above. The array passed into the function will have 50 rows and 100 columns.

Exercise 7: Identical Vectors

bool areIdentical(const vector<int> & a, const vector<int> & b);

Write a predicate function that checks whether two vectors are identical (contain exactly the same elements in the same order). A declaration of the function is shown above. The function returns true if the two vectors are identical; otherwise it returns false.

Exercise 8: Unlucky Vectors

bool isUnlucky(vector<int> & v);

Implement a function that determines if the unlucky number 13 appears in a vector. The function returns true if 13 appears in the vector at least once; otherwise it returns false. Write test code that tesets every statement in the function. Use assertions in your test code.

Exercise 9: Ordered Vectors

bool isStrictlyIncreasing(const vector<int> & v);

Write a predicate function called isStrictlylncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order; otherwise it returns false. For example, it will return true for v = (2, 4, 5, 6, 8) and it will return false for (3, 4, 6, 6, 9).

Exercise 10: Flatten

vector<int> flatten(int a[100][200]);

Write a function named flatten that takes a 2-dimensional array of integers with 100 rows and 200 columns and returns a vector that contains all of the array's elements. Copy the values a row at a time. In other words, first copy row 0 into the vector, then row 1, then row 2, and so on. The declaration of flatten is given above.

Reference no: EM13767286

Questions Cloud

What is the difference between art and entertainment : What is the difference between art and entertainment? How has the commercial music industry affected the artistic integrity of popular musicians?
What is the bar''s angular acceleration : The 0.4kg slender bar and 1 kg disk released from rest in the position shown. if the disk roll, what is the bar's angular acceleration at the instant of release?
Reported about a sexual offender who continued offending : The Miami Herald reported about a sexual offender who continued offending, because the system continues to fail. Discusses this topic and in specific, the use of chemical castration as a sentencing method for convicted sex offenders
How mindfulness and other buddhism related approaches : Topic: How mindfulness and other Buddhism related approaches in psychology can be beneficial for children?
Provide an implementation of the mymaximum function : Provide an implementation of the mymaximum function whose declaration is shown above. The first argument of the function is an array of int and the second argument is the number of ints that are in the array. The function returns the largest int t..
How fast in rpm must a centrifuge rotate : How fast in rpm must a centrifuge rotate if a particle 7.0 cm from the axis of rotation is to experience an acceleration of 125,000 G's
What role ethnicity play in politics of a asian pacific : What role does ethnicity play in the politics of a given Asian Pacific country? How does film, fiction, or art represent economic, political, or social trends in a given Asian Pacific country?
What application does the ucc have here : What do you think about this situation? Should parties to a sales contract be able to rescind a contract because of mutual mistake of fact? Why or why not? Did either party act unethically in this case? Why or why not? What application does the UC..
Are the aircraft moving at a constant velocity : A 1000 kg aircraft going 25 m/s collides with a 1500 kg aircraft that is parked and they stick together after the collision and are going 10 m/s after the collision. If they skid for 8.2seconds before stopping, how far did they skid?  Hint: Are the a..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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