SlideShare uma empresa Scribd logo
1 de 2
How do convert strings inside a vector to integers and then find the average of set of their values
in C++?
Solution
Answer:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
int n, i;
string input;
getline(cin, input);
stringstream stream(input);
float num[100], sum=0.0, average;
getline(cin,num);
stringstream stream1(num);
cout << "Enter the numbers of data: ";
cin >> n;
while (n>100 || n<=0)
{
stream >> n;
if(!stream)
break;
cout << "Integer Detected: " << n << " ";
}
for(i=0; i<n; ++i)
{
cout << i+1 << ". Enter number: ";
stream1>> num[i];
sum+=num[i];
}
average=sum/n;
cout << "Average of integers is :" << average;
return 0;
}

Mais conteúdo relacionado

Mais de tpaula2

How are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docxHow are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docxtpaula2
 
How are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docxHow are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docxtpaula2
 
How can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docxHow can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docxtpaula2
 
Holmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docxHolmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docxtpaula2
 
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docxHNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docxtpaula2
 
Hi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docxHi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docxtpaula2
 
Hi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docxHi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docxtpaula2
 
Hi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docxHi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docxtpaula2
 
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docxHerbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docxtpaula2
 
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docxHere is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docxtpaula2
 
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docxtpaula2
 
1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docxtpaula2
 
1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docxtpaula2
 
1- Graynold Company reported the following balances at December 31- 20.docx
1- Graynold Company reported the following balances at December 31- 20.docx1- Graynold Company reported the following balances at December 31- 20.docx
1- Graynold Company reported the following balances at December 31- 20.docxtpaula2
 
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docxtpaula2
 
1- Experiments show that the hydronium ion- H3O- is actually further h.docx
1- Experiments show that the hydronium ion- H3O- is actually further h.docx1- Experiments show that the hydronium ion- H3O- is actually further h.docx
1- Experiments show that the hydronium ion- H3O- is actually further h.docxtpaula2
 
1- Does it seem practical to have both a project management methodolog.docx
1- Does it seem practical to have both a project management methodolog.docx1- Does it seem practical to have both a project management methodolog.docx
1- Does it seem practical to have both a project management methodolog.docxtpaula2
 
1- Evidence obtained from third parties- such as- vendors or creditors.docx
1- Evidence obtained from third parties- such as- vendors or creditors.docx1- Evidence obtained from third parties- such as- vendors or creditors.docx
1- Evidence obtained from third parties- such as- vendors or creditors.docxtpaula2
 
1- Does the project management methodology apply equally well to progr.docx
1- Does the project management methodology apply equally well to progr.docx1- Does the project management methodology apply equally well to progr.docx
1- Does the project management methodology apply equally well to progr.docxtpaula2
 
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docxtpaula2
 

Mais de tpaula2 (20)

How are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docxHow are standing waves similar to beats and how are they different- Ty.docx
How are standing waves similar to beats and how are they different- Ty.docx
 
How are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docxHow are corporate abuse of power corporate fraud- and corporate econom.docx
How are corporate abuse of power corporate fraud- and corporate econom.docx
 
How can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docxHow can biometric technology be used to fight cybercrime and cyber rel.docx
How can biometric technology be used to fight cybercrime and cyber rel.docx
 
Holmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docxHolmes- CPA- assisted Williams Corporation in preparing its financial.docx
Holmes- CPA- assisted Williams Corporation in preparing its financial.docx
 
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docxHNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
HNO2 has a Ka of 4-00x10^-3- What is the pH of a solution prepared by.docx
 
Hi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docxHi- Can you answer this question- Please show all your work and show i.docx
Hi- Can you answer this question- Please show all your work and show i.docx
 
Hi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docxHi! I think the answer is C Outsource the software- I juyst wanted to.docx
Hi! I think the answer is C Outsource the software- I juyst wanted to.docx
 
Hi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docxHi all! someone help me pls Fraud examination I need to write an essay.docx
Hi all! someone help me pls Fraud examination I need to write an essay.docx
 
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docxHerbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
Herbie Corp-'s Balance Sheet showed the following at 12-31-13 Common S.docx
 
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docxHere is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
Here is a list of the main characters in Shakespeare-'s Romeo and Juli.docx
 
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
1- How many ATOMS of sulfur are present in 2-25 moles of sulfur trioxi.docx
 
1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx1- How does having a scope and WBS help project teams during project e.docx
1- How does having a scope and WBS help project teams during project e.docx
 
1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx1- How did the Roman Catholc church influence music in the Middle Ages.docx
1- How did the Roman Catholc church influence music in the Middle Ages.docx
 
1- Graynold Company reported the following balances at December 31- 20.docx
1- Graynold Company reported the following balances at December 31- 20.docx1- Graynold Company reported the following balances at December 31- 20.docx
1- Graynold Company reported the following balances at December 31- 20.docx
 
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx
1- Explain the nature and importance of a job cost sheet- 2- Distingui.docx
 
1- Experiments show that the hydronium ion- H3O- is actually further h.docx
1- Experiments show that the hydronium ion- H3O- is actually further h.docx1- Experiments show that the hydronium ion- H3O- is actually further h.docx
1- Experiments show that the hydronium ion- H3O- is actually further h.docx
 
1- Does it seem practical to have both a project management methodolog.docx
1- Does it seem practical to have both a project management methodolog.docx1- Does it seem practical to have both a project management methodolog.docx
1- Does it seem practical to have both a project management methodolog.docx
 
1- Evidence obtained from third parties- such as- vendors or creditors.docx
1- Evidence obtained from third parties- such as- vendors or creditors.docx1- Evidence obtained from third parties- such as- vendors or creditors.docx
1- Evidence obtained from third parties- such as- vendors or creditors.docx
 
1- Does the project management methodology apply equally well to progr.docx
1- Does the project management methodology apply equally well to progr.docx1- Does the project management methodology apply equally well to progr.docx
1- Does the project management methodology apply equally well to progr.docx
 
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx
1- Do you agree with Judith Jarvis Thomson that every privacy right vi.docx
 

Último

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Último (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

How do convert strings inside a vector to integers and then find the a.docx

  • 1. How do convert strings inside a vector to integers and then find the average of set of their values in C++? Solution Answer: #include <iostream> #include <string> #include <sstream> using namespace std; int main(){ int n, i; string input; getline(cin, input); stringstream stream(input); float num[100], sum=0.0, average; getline(cin,num); stringstream stream1(num); cout << "Enter the numbers of data: "; cin >> n; while (n>100 || n<=0) { stream >> n; if(!stream) break; cout << "Integer Detected: " << n << " "; } for(i=0; i<n; ++i) { cout << i+1 << ". Enter number: "; stream1>> num[i]; sum+=num[i]; }
  • 2. average=sum/n; cout << "Average of integers is :" << average; return 0; }