[solved] – Question 79701

I am trying to figure out how to write these functions:

Create another function to write the first 10 lines in the container to a file called topTen.txt.
Create another function that will accept an integer line number in the parameter list and string return value. When the function is called in main, a line number must be passed to the function. The function should then return the line from the container that corresponds to that line number. You must pull the line from the container, not from the file. Because you are required to pull the line from the container, you must include the container in the parameter list of this function and pass the container to this function when it is called by main. The main function should then display the string that is returned by the function.

Expert Answer


[solved] – Question 79792

What does g(31415927)return for the following definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)

Expert Answer


[solved] – Question 79793

What is the value of h(231,8)for the function below?
def h(m,n):
ans = 0
while (m >= n):
(ans,m) = (ans+1,m-n)
return(ans)

Expert Answer


[solved] – Question 79794

What is the value of h(231,8) for the function below?
def h(m,n):
ans = 0
while (m >= n):
(ans,m) = (ans+1,m-n)
return(ans)

Expert Answer


[solved] – Question 79795

Consider the following function h.
def h(n):
f = 0
for i in range(1,n+1):
if n%i == 0:
f = f + 1
return(f%2 == 1)
The function h(n) given above returns True for a positive number n whenever:
n is a multiple of 2
n is a composite number
n is a prime number
n is a perfect square

Expert Answer


[solved] – Question 79813

4Insert a VLOOKUP function in cell C5 to display the ring cost for the first student.

Expert Answer


[solved] – Question 79815

Given the following Array class definition, write a new overloaded operator function for the ‘%’ (modulus) operator (i.e., return an array object that contains the remainders of divide operations between corresponding values in two array objects.) Write the code that would be required in the Array.cpp file. This new function must check for divide by 0.

E.g., array3 = array1 % array2;

class Array
{
public:
Array( int = 10 );
~Array( );
int getSize( ) const;
const Array &operator= ( const Array & );
bool operator==( const Array & ) const;
int &operator[ ]( int );
private:
int size; // Size of the array (number of elements)
int *ptr; // Pointer to the first element of the array
}

Expert Answer


[solved] – Question 79817

Using the class “string” from the C++ standard library, write the statements to perform the following tasks.
(Do not write an entire C++ program.) Assume that there are two string variables containing words separated by one or more blanks with no special characters. Numbers within the strings are valid.

Compare string1 to string2 to determine if they have the same number of vowels (a,e,i,o,u).
Hint: Use the string method “find_first_of” in a loop for each string.
Make a copy of the longest word from the string1 and insert it into string2 after the first word. (Maintain blanks between all words in string2.)
Hint: Use the string methods “find” and “insert”.

Expert Answer


[solved] – Question 79818

The following code defines a multimap associative container and inserts some initial values. Add code for a second multimap associative container and algorithm statements that search for duplicates in the original container and move those duplicate keys and values to the new container (deleting the entries from the original container).

#include <map>
using namespace std;

int main()
{
multimap< int, int, less< int > > container8;

container8.insert( make_pair ( 7, 24 ) );
container8.insert( make_pair ( 7, 16 ) );
container8.insert( make_pair ( 4, 56 ) );
container8.insert( make_pair ( 4, 72 ) );
container8.insert( make_pair ( 3, 17 ) );
container8.insert( make_pair ( 7, 41 ) );
container8.insert( make_pair ( 2, 12 ) );
container8.insert( make_pair ( 5, 67 ) );
}

Expert Answer


[solved] – Question 79825

What does g(31415927)return for the following definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)

Expert Answer