Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
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
Corner Case Write a function called corners that takes a matrix as an input argument and returns four outputs: the elements at its four corners in this order: top left, top right, bottom left and bottom right. (Note that loops and if-statements are neither necessary nor allowed as we have not covered them yet.) See an example run below: > [a, b, c, d] = corners([1 2; 3 4]) a = 1. 2 C = 3 4 Function e A Save C Reset MATLAB Documentation 1 Code to call your function e C Reset 1 A = randi(100,4,5) 2 [top_left, top_right, bottom_left, bottom_right] = corners (A) 3 B = [1; 2] 4 [top_left, top_right, bottom_left, bottom_right] = corners (B)
vowelIndex Write a function vowelIndex that accepts a word (a str) as an argument and returns the index of the first vowel in the word. If there is no vowel, -1 is returned. For this problem, both upper and lower case vowels count, and 'y' is not considered to be a vowel. Sample usage: >>> vowelIndex('hello') 1 >>> vowelIndex('string') 3 >>> vowelIndex('string') 3 >>> vowelIndex('BUY') 1 >>> vowelIndex('APPLE') 0 >>> vowelIndex('nymphly') -1 >>> vowelIndex('string')==3 True >>> vowel Index ('nymphly')==-1 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);

Chapter 16 Solutions

Starting Out with C++: Early Objects (9th Edition)

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