<<<<<<<<<<<<<<<<<<<<<<<<< C++ >>>>>>>>>>>>>>>>>>>>>>>>> #include<iostream> using
ID: 3920071 • Letter: #
Question
<<<<<<<<<<<<<<<<<<<<<<<<< C++ >>>>>>>>>>>>>>>>>>>>>>>>>
#include<iostream>
using namespace std;
// total template
template <class T>
T total(T number)
{
T value = 0; // User input
T total = 0; // Accumulator
// Get a series of numbers and accumulate their total.
for (int i = 0; i < number; i++)
{
cout << "Enter a value: ";
cin >> value;
total += value;
}
// Return the total.
return total;
}
// main function
int main()
{
int intVals, intTotal;
double doubleVals, doubleTotal;
// Get the number of integers to sum.
cout << " How many integer values do you wish to total? ";
cin >> intVals;
// Get the sum of that many integers.
intTotal = Blank 1 A. Add code in this box
// Display the sum.
cout << "The total is " Blank 2 B. Add code in this box
// Get the number of doubles to sum.
cout << " How many double values do you wish to total? ";
cin >> doubleVals;
// Get the sum of that many doubles.
Blank 3 C. Add code in this line
// Display their sum.
cout << "The total is " Blank 4 D. Add code in this line
return 0;
}
Explanation / Answer
#include using namespace std; // total template template T total(T number) { T value = 0; // User input T total = 0; // Accumulator // Get a series of numbers and accumulate their total. for (int i = 0; i value; total += value; } // Return the total. return total; } // main function int main() { int intVals, intTotal; double doubleVals, doubleTotal; // Get the number of integers to sum. cout > intVals; // Get the sum of that many integers. intTotal = total(intVals); // Display the sum. coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.