Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the sum of the vector's elements. Then, the function returns true if the sum is not equal to the integer parameter, and returns false otherwise. Ex: If the input is: 4 -6940 4

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the
sum of the vector's elements. Then, the function returns true if the sum is not equal to the integer parameter, and returns false
otherwise.
Ex: If the input is:
4
-69 40
4
then the vector has 4 elements (-6, 9, 4, 0), and the integer parameter is 4. The output is:
True, the sum of all the elements is not equal to 4.
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4
5* Your code goes here */
6
7 int main() {
8
9
10
11
12
13
14
15
16
17
vector<int> inVector;
int size;
int input;
int i;
int x;
bool result;
// Read the vector's size, and then the vector's elements
cin >> size;
for (i = 0; i < size; ++i) {
Transcribed Image Text:Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the sum of the vector's elements. Then, the function returns true if the sum is not equal to the integer parameter, and returns false otherwise. Ex: If the input is: 4 -69 40 4 then the vector has 4 elements (-6, 9, 4, 0), and the integer parameter is 4. The output is: True, the sum of all the elements is not equal to 4. 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5* Your code goes here */ 6 7 int main() { 8 9 10 11 12 13 14 15 16 17 vector<int> inVector; int size; int input; int i; int x; bool result; // Read the vector's size, and then the vector's elements cin >> size; for (i = 0; i < size; ++i) {
Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the
sum of the vector's elements. Then, the function returns true if the sum is not equal to the integer parameter, and returns false
otherwise.
Ex: If the input is:
4
-6940
4
then the vector has 4 elements (-6, 9, 4, 0), and the integer parameter is 4. The output is:
True, the sum of all the elements is not equal to 4.
for (i = 0; i < size; ++i) {
cin >> input;
invector.push_back (input);
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 1
}
cin >> X;
result CheckSum(inVector, x);
if (result) {
cout << "True, the sum of all the elements is not equal to " << x << "." << endl;
}
else {
cout << "False, the sum of all the elements is equal to " << x << "." << endl;
}
return 0;
U
Transcribed Image Text:Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the sum of the vector's elements. Then, the function returns true if the sum is not equal to the integer parameter, and returns false otherwise. Ex: If the input is: 4 -6940 4 then the vector has 4 elements (-6, 9, 4, 0), and the integer parameter is 4. The output is: True, the sum of all the elements is not equal to 4. for (i = 0; i < size; ++i) { cin >> input; invector.push_back (input); 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 1 } cin >> X; result CheckSum(inVector, x); if (result) { cout << "True, the sum of all the elements is not equal to " << x << "." << endl; } else { cout << "False, the sum of all the elements is equal to " << x << "." << endl; } return 0; U
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY