Question

In: Computer Science

in c++, please provide only a function. the function should be named "tally." it takes no...

in c++,

please provide only a function. the function should be named "tally." it takes no parameters but returns an int. the first int should be 0, next being 1, then 2, etc..

will rate if correct. again should only be 1 function.

Solutions

Expert Solution

#include <iostream>

using namespace std;

//function declaration

int tally();

int main()

{

cout<<"first call of tally function return value: "<<tally()<<endl;

cout<<"second call of tally function return value: "<<tally()<<endl;

cout<<"third call of tally function return value: "<<tally()<<endl;

cout<<"fourth call of tally function return value: "<<tally()<<endl;

}

//function definition

/*

Function name: tally

input: None

Output: returns integer

first call return 0, second call returns 1 and so on

*/

int tally()

{

static int ret=0;

return ret++;

}

==================================

//Output

first call of tally function return value: 0
second call of tally function return value: 1
third call of tally function return value: 2
fourth call of tally function return value: 3


Related Solutions

(C++ only please) Write a function called maximum that takes an array of double values as...
(C++ only please) Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.) Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The...
Please provide your answer in the following format Write a C++ function, smallestIndex, that takes as...
Please provide your answer in the following format Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Also, write a program to test your function. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID // Purpose...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
Write a recursive function in C++ named multiplyNumbers, which takes one int argument n as input...
Write a recursive function in C++ named multiplyNumbers, which takes one int argument n as input and returns the product of numbers from 1 to n.
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
write a function named as cubeCalculator that takes an integer pointer as function and return its...
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The name of the file, a pointer to an array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to file, and then close the file. Write another function named fileToArray. This function should accept 3 arguments: the name of the file, a pointer, to an int array, and the size of...
please solve by utilizing python Define a function named checkOut which takes two JSON strings, each...
please solve by utilizing python Define a function named checkOut which takes two JSON strings, each representing a dictionary. The first has the following structure, { "customer" : name , "cart" : [ item1, item2, ... ] } The second has the following structure, { item1 : price1, item2 : price2, ... } The function must return a JSON string representing the following dictionary: { "customer" : name, "amount_due" : x } where x is the sum of the prices...
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT