STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 16, Problem 4PC

Sequence Accumulation

Write n function

T accum(vector <T> v)

that forms and returns the “sum” of all items in the vector v passed to it. For example, if T is a numeric type such as int or double, the numeric sum will be returned, and if T represents the STL string type, then the result of concatenation is returned.

NOTE: For any type T, the expression T() yields the value or object created by the default constructor. For example, T() yields the empty string object if T is the string class. If T represents a numeric type such as 1nt, then T() yields 0. Use this fact to initialize your “accumulator.”

Test your function with a driver program that asks the user to enter three integers, uses accum to compute the sum, and prints out the sum. The program than asks the user to enter three strings, uses accum ro concatenate the strings, and prints the result.

Blurred answer
Students have asked these similar questions
palindromes Write a function palindromes that accepts a sentence as an argument. The function then returns a list of all words in the sentence that are palindromes, that is they are the same forwards and backwards. Guidelines: • punctuation characters .,;!? should be ignored • the palindrome check should not depend on case Sample usage: >>> palindromes ("Hey Anna, would you prefer to ride in a kayak or a racecar?") ['Anna', 'a', 'kayak', 'a', 'racecar'] >>> palindromes ("Able was I ere I saw Elba.") ['I', 'ere', 'I'] >>> palindromes ("Otto, go see Tacocat at the Civic Center, their guitar solos are Wow!") ['Otto', 'Tacocat', 'Civic', 'solos', 'wow'] >>> palindromes ("Otto, go see Tacocat at the Civic Center, their guitar solos are wow!")==['Otto', 'Tacocat', 'Civic', 'solos', 'wow'] True
C++ Coding Write a program that asks a teacher to enter the student's and the grades received on her quarterly exams. The datatype for the student's name could be a string and the four grades should be entered in an array of data types int. Test scores are on the base of 100. The main() functions describe the average function with the following title line: double avg( int grades[] , int cap ): The program prints the student's name, her four grades, and her average grades. The main() function also uses the following print function: void print( int grades[], int cap);
C++ Coding Write a program that asks a teacher to enter the student's name and the grades received on her quarterly exams. The datatype for the student's name could be a string and the four grades should be entered in an array of data types int. Test scores are on the base of 100. REMINDER: sum and cap CANNOT be integers. The main() functions describe the average function with the following title line: double avg( int grades[], int cap ) The program prints the student's name, her four grades, and her average grades The main() function also uses the following print function: void print( int grades[], int cap);

Chapter 16 Solutions

STARTING OUT WITH C++ MPL

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License