hi please me on this to fix the error and this is not the graded question so please dont cancel the question. this is a homework question and i need help
hi please me on this to fix the error and this is not the graded question so please dont cancel the question. this is a homework question and i need help
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
hi please me on this to fix the error
and this is not the graded question so please dont cancel the question.
this is a homework question and i need help
![You are working on problem set: Lab 1 copy
mean
Language/Type:
Related Links:
Author:
C++ vector collections STL
vector
Eric Roberts (on 2021/07/06)
Pause) i
Write a function named mean that accepts as a parameter a reference to a vector of real numbers, and
returns the arithmetic mean (average) of the integers in the vector as a real number. For example, if the
vector passed contains {2.0, 4.5, 6.5, 1.0), your function should return 3.5. If the vector is empty,
return Ø. Ø. Do not modify the vector that is passed in.
You passed 3 of 4 tests. Try again.
mean ({2.0, 4.5, 6.5, 1.0})
mean({9.0, 3.25, 2.5, 8.25, 15.0, -2.0, 35.5, 44.5})
mean ({1.0, 3.25, 2.5, 8.25, 15.0, -2.0, 35.5, 44.5, 0.0, 2.0}) →
* mean({})
Testing began at 2023/02/01 17:16 (PST) and ran for 1319 ms.
←
3.5
14.5
11.0
→ -nan (expected Ø.0)
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4 double mean (vector<double> &v) {
double sum = Ø;
6
for (int i=0; i < v.size(); i++)
sum += v[i];
return sum/v.size();
8
9}
10 int main()
11 {
12
13
14
15
16
17 }
18
19
Function: Write a C++ function as described, not a complete program.
// Sum of elements of the vector.
vector<double> v{2.0, 4.5, 6.5, 1.0);
double avg = mean(v);
// Call the mean function.
cout<<"Mean of the elements of the vector is :: " << avg;
return 0;
Submit
X](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc2e97f32-5988-4deb-9547-eb6ce37eb1f3%2F0a2b67fe-1c02-4b86-9bf4-45f66aa0b171%2Fepyou3s_processed.png&w=3840&q=75)
Transcribed Image Text:You are working on problem set: Lab 1 copy
mean
Language/Type:
Related Links:
Author:
C++ vector collections STL
vector
Eric Roberts (on 2021/07/06)
Pause) i
Write a function named mean that accepts as a parameter a reference to a vector of real numbers, and
returns the arithmetic mean (average) of the integers in the vector as a real number. For example, if the
vector passed contains {2.0, 4.5, 6.5, 1.0), your function should return 3.5. If the vector is empty,
return Ø. Ø. Do not modify the vector that is passed in.
You passed 3 of 4 tests. Try again.
mean ({2.0, 4.5, 6.5, 1.0})
mean({9.0, 3.25, 2.5, 8.25, 15.0, -2.0, 35.5, 44.5})
mean ({1.0, 3.25, 2.5, 8.25, 15.0, -2.0, 35.5, 44.5, 0.0, 2.0}) →
* mean({})
Testing began at 2023/02/01 17:16 (PST) and ran for 1319 ms.
←
3.5
14.5
11.0
→ -nan (expected Ø.0)
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4 double mean (vector<double> &v) {
double sum = Ø;
6
for (int i=0; i < v.size(); i++)
sum += v[i];
return sum/v.size();
8
9}
10 int main()
11 {
12
13
14
15
16
17 }
18
19
Function: Write a C++ function as described, not a complete program.
// Sum of elements of the vector.
vector<double> v{2.0, 4.5, 6.5, 1.0);
double avg = mean(v);
// Call the mean function.
cout<<"Mean of the elements of the vector is :: " << avg;
return 0;
Submit
X
Expert Solution

Step 1
We can use a if condition so that if size is 0 of vector return 0.0 as output
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education