- Write a function middle that takes three
integer parameters and returns the middle value of the three. For
example, the line:
cout << middle(12, 14, 10) << endl;
will print out 12.
- Write a function printInvoice that takes
a single call-by-reference ifstream parameter that has already
been opened to a file containing invoice data. Each line of the file
contains four pieces of information: an item number (integer), an item
name (string), quantity ordered (integer), and the item unit cost
(double). Your function should read in each line and print to cout
the item number, the item name, and the extended cost, which is
computed by multiplying the quantity and the unit cost.
Once the entire file has been processed, your function should print to
cout the total quantity of all items processed, the total extended
cost, the shipping charge, and grand total. The shipping charge
should be 10% of the total extended cost if that cost is under $100.00
and 5% if it is $100.00 or more. The grand total is the total
extended cost plus shipping.
- Write a function inputOctal that asks
the user for a positive integer value in the range 0 to 7 or in the
range 10 to 17. Return the value entered as the value of the
function. Do not return from the function until the user has entered
a value in one of those ranges, unless a negative value is
entered. In that case, terminate the program.
- The following function is intended to read a stream of characters
from the istream object input and output each one to the
ostream object output. In addition, it is supposed to return
the number of characters read. However, it doesn't work. Please find
and correct the errors in it by either rewriting it so that it works
or by identifying every one of the errors.
void printFile(istream input, ostream output);
{
int count;
input.get(c);
while (inputFile.eof());
{
output.put(c);
count--;
input.get(c);
}
return count;
}
- Write a function secondLargest that takes
two parameters, an integer array and its length, and returns the value
of the second largest value in the array. You may assume
that the values in the array are distinct.
- Write a function firstFactor that
returns the first factor of an integer n, ie, the smallest
number greater than 1 that divides n. Then, write a program
that tests the function by continuously prompting the user for a
number and printing its first factor. The program should stop when
the user types in any value less than or equal to 0 for the number.
Submit the entire program as your answer.
- Write a function upperCount that takes a
single parameter, an ifstream object that has been opened to a
textfile, and counts and returns as its value the number of upper case
letters in the file. Then, write a program whose main function calls
a function to ask the user for the name of a textfile, opens the file,
calls the function upperCount, and prints its value.
Submit the entire program as your answer.