SlideShare a Scribd company logo

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

T
tpaula2

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; } .

1 of 2
Download to read offline
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;
}

Recommended

How can I calculate the missing amounts for each of the independent ca.docx
How can I calculate the missing amounts for each of the independent ca.docxHow can I calculate the missing amounts for each of the independent ca.docx
How can I calculate the missing amounts for each of the independent ca.docxtpaula2
 
How do COQ and capability relate-SolutionBorn 130 years ago- Le coq sp.docx
How do COQ and capability relate-SolutionBorn 130 years ago- Le coq sp.docxHow do COQ and capability relate-SolutionBorn 130 years ago- Le coq sp.docx
How do COQ and capability relate-SolutionBorn 130 years ago- Le coq sp.docxtpaula2
 
How do --per capita-- considerations affect a company-'s decision to e.docx
How do --per capita-- considerations affect a company-'s decision to e.docxHow do --per capita-- considerations affect a company-'s decision to e.docx
How do --per capita-- considerations affect a company-'s decision to e.docxtpaula2
 
How do I calculate the limiting reagent and percent yield for creating.docx
How do I calculate the limiting reagent and percent yield for creating.docxHow do I calculate the limiting reagent and percent yield for creating.docx
How do I calculate the limiting reagent and percent yield for creating.docxtpaula2
 
How can you classify the molecular structures of the polymers- Explain.docx
How can you classify the molecular structures of the polymers- Explain.docxHow can you classify the molecular structures of the polymers- Explain.docx
How can you classify the molecular structures of the polymers- Explain.docxtpaula2
 
How could I show that the nitrate test confirmed that two unknown solu.docx
How could I show that the nitrate test confirmed that two unknown solu.docxHow could I show that the nitrate test confirmed that two unknown solu.docx
How could I show that the nitrate test confirmed that two unknown solu.docxtpaula2
 
how can you determine if a computer is using pipelining-SolutionIn old.docx
how can you determine if a computer is using pipelining-SolutionIn old.docxhow can you determine if a computer is using pipelining-SolutionIn old.docx
how can you determine if a computer is using pipelining-SolutionIn old.docxtpaula2
 
How do changes in activity affect contribution margin and net operatin.docx
How do changes in activity affect contribution margin and net operatin.docxHow do changes in activity affect contribution margin and net operatin.docx
How do changes in activity affect contribution margin and net operatin.docxtpaula2
 

More Related Content

More from tpaula2

How do arrays compare with variables and how do they differ- Give a si.docx
How do arrays compare with variables and how do they differ- Give a si.docxHow do arrays compare with variables and how do they differ- Give a si.docx
How do arrays compare with variables and how do they differ- Give a si.docxtpaula2
 
How can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docxHow can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docxtpaula2
 
How can the forms of business organizations impact the control of the.docx
How can the forms of business organizations impact the control of the.docxHow can the forms of business organizations impact the control of the.docx
How can the forms of business organizations impact the control of the.docxtpaula2
 
how can i store 30 prices on this void get prices and save it to the a.docx
how can i store 30 prices on this void get prices and save it to the a.docxhow can i store 30 prices on this void get prices and save it to the a.docx
how can i store 30 prices on this void get prices and save it to the a.docxtpaula2
 
How can a company assess person-job fit before hiring employees What a.docx
How can a company assess person-job fit before hiring employees What a.docxHow can a company assess person-job fit before hiring employees What a.docx
How can a company assess person-job fit before hiring employees What a.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
 
How can CORS be used to exploit the following password reset page- The.docx
How can CORS be used to exploit the following password reset page- The.docxHow can CORS be used to exploit the following password reset page- The.docx
How can CORS be used to exploit the following password reset page- The.docxtpaula2
 
How are encryption- authentication- digital signatures- and digital ce.docx
How are encryption- authentication- digital signatures- and digital ce.docxHow are encryption- authentication- digital signatures- and digital ce.docx
How are encryption- authentication- digital signatures- and digital ce.docxtpaula2
 
How are cash equivalents treated on a statement of cash flows- They ar.docx
How are cash equivalents treated on a statement of cash flows- They ar.docxHow are cash equivalents treated on a statement of cash flows- They ar.docx
How are cash equivalents treated on a statement of cash flows- They ar.docxtpaula2
 
home - study - science - physics - physics questions and answers - an.docx
home - study - science - physics - physics questions and answers - an.docxhome - study - science - physics - physics questions and answers - an.docx
home - study - science - physics - physics questions and answers - an.docxtpaula2
 
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docx
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docxHOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docx
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docxtpaula2
 
Horizontal Analysis The comparative accounts payable and long-term deb.docx
Horizontal Analysis The comparative accounts payable and long-term deb.docxHorizontal Analysis The comparative accounts payable and long-term deb.docx
Horizontal Analysis The comparative accounts payable and long-term deb.docxtpaula2
 
Horizontal analysis (trend analysis) percentages for Harley Companys s.docx
Horizontal analysis (trend analysis) percentages for Harley Companys s.docxHorizontal analysis (trend analysis) percentages for Harley Companys s.docx
Horizontal analysis (trend analysis) percentages for Harley Companys s.docxtpaula2
 
Homework Help Thanks in advance!SolutionCost of material used in april.docx
Homework Help Thanks in advance!SolutionCost of material used in april.docxHomework Help Thanks in advance!SolutionCost of material used in april.docx
Homework Help Thanks in advance!SolutionCost of material used in april.docxtpaula2
 
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docx
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docxHomework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docx
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docxtpaula2
 
hoice Questions in a unit cell is defined as the number of spheres of.docx
hoice Questions in a unit cell is defined as the number of spheres of.docxhoice Questions in a unit cell is defined as the number of spheres of.docx
hoice Questions in a unit cell is defined as the number of spheres of.docxtpaula2
 
home - study - engineering - computer science - questions and answers.docx
home - study - engineering - computer science - questions and answers.docxhome - study - engineering - computer science - questions and answers.docx
home - study - engineering - computer science - questions and answers.docxtpaula2
 
home - study - engineering - computer science - questions and answers (1).docx
home - study - engineering - computer science - questions and answers (1).docxhome - study - engineering - computer science - questions and answers (1).docx
home - study - engineering - computer science - questions and answers (1).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
 
Holliday Company-'s inventory records show the following data- Units U.docx
Holliday Company-'s inventory records show the following data- Units U.docxHolliday Company-'s inventory records show the following data- Units U.docx
Holliday Company-'s inventory records show the following data- Units U.docxtpaula2
 

More from tpaula2 (20)

How do arrays compare with variables and how do they differ- Give a si.docx
How do arrays compare with variables and how do they differ- Give a si.docxHow do arrays compare with variables and how do they differ- Give a si.docx
How do arrays compare with variables and how do they differ- Give a si.docx
 
How can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docxHow can the use of Internet search engines to locate information about.docx
How can the use of Internet search engines to locate information about.docx
 
How can the forms of business organizations impact the control of the.docx
How can the forms of business organizations impact the control of the.docxHow can the forms of business organizations impact the control of the.docx
How can the forms of business organizations impact the control of the.docx
 
how can i store 30 prices on this void get prices and save it to the a.docx
how can i store 30 prices on this void get prices and save it to the a.docxhow can i store 30 prices on this void get prices and save it to the a.docx
how can i store 30 prices on this void get prices and save it to the a.docx
 
How can a company assess person-job fit before hiring employees What a.docx
How can a company assess person-job fit before hiring employees What a.docxHow can a company assess person-job fit before hiring employees What a.docx
How can a company assess person-job fit before hiring employees What a.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
 
How can CORS be used to exploit the following password reset page- The.docx
How can CORS be used to exploit the following password reset page- The.docxHow can CORS be used to exploit the following password reset page- The.docx
How can CORS be used to exploit the following password reset page- The.docx
 
How are encryption- authentication- digital signatures- and digital ce.docx
How are encryption- authentication- digital signatures- and digital ce.docxHow are encryption- authentication- digital signatures- and digital ce.docx
How are encryption- authentication- digital signatures- and digital ce.docx
 
How are cash equivalents treated on a statement of cash flows- They ar.docx
How are cash equivalents treated on a statement of cash flows- They ar.docxHow are cash equivalents treated on a statement of cash flows- They ar.docx
How are cash equivalents treated on a statement of cash flows- They ar.docx
 
home - study - science - physics - physics questions and answers - an.docx
home - study - science - physics - physics questions and answers - an.docxhome - study - science - physics - physics questions and answers - an.docx
home - study - science - physics - physics questions and answers - an.docx
 
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docx
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docxHOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docx
HOME -NSERI PAGE LAYOUT FORMULAS DATA REVEW VIPw Cut Copy Farnat Paint.docx
 
Horizontal Analysis The comparative accounts payable and long-term deb.docx
Horizontal Analysis The comparative accounts payable and long-term deb.docxHorizontal Analysis The comparative accounts payable and long-term deb.docx
Horizontal Analysis The comparative accounts payable and long-term deb.docx
 
Horizontal analysis (trend analysis) percentages for Harley Companys s.docx
Horizontal analysis (trend analysis) percentages for Harley Companys s.docxHorizontal analysis (trend analysis) percentages for Harley Companys s.docx
Horizontal analysis (trend analysis) percentages for Harley Companys s.docx
 
Homework Help Thanks in advance!SolutionCost of material used in april.docx
Homework Help Thanks in advance!SolutionCost of material used in april.docxHomework Help Thanks in advance!SolutionCost of material used in april.docx
Homework Help Thanks in advance!SolutionCost of material used in april.docx
 
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docx
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docxHomework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docx
Homework 10 Classical Electron Spin 4 of 13 - ParI A If you treat an e.docx
 
hoice Questions in a unit cell is defined as the number of spheres of.docx
hoice Questions in a unit cell is defined as the number of spheres of.docxhoice Questions in a unit cell is defined as the number of spheres of.docx
hoice Questions in a unit cell is defined as the number of spheres of.docx
 
home - study - engineering - computer science - questions and answers.docx
home - study - engineering - computer science - questions and answers.docxhome - study - engineering - computer science - questions and answers.docx
home - study - engineering - computer science - questions and answers.docx
 
home - study - engineering - computer science - questions and answers (1).docx
home - study - engineering - computer science - questions and answers (1).docxhome - study - engineering - computer science - questions and answers (1).docx
home - study - engineering - computer science - questions and answers (1).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
 
Holliday Company-'s inventory records show the following data- Units U.docx
Holliday Company-'s inventory records show the following data- Units U.docxHolliday Company-'s inventory records show the following data- Units U.docx
Holliday Company-'s inventory records show the following data- Units U.docx
 

Recently uploaded

ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptxADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptxAKSHAYMAGAR17
 
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...SUMIT TIWARI
 
Google Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfGoogle Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfTechSoup
 
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaPrince Armah, PhD
 
Peninsula Channel Commanders Rules Handbook
Peninsula Channel Commanders Rules HandbookPeninsula Channel Commanders Rules Handbook
Peninsula Channel Commanders Rules Handbookpccwebmasterhmb
 
Healthy Habits for Happy School Staff - presentation
Healthy Habits for Happy School Staff - presentationHealthy Habits for Happy School Staff - presentation
Healthy Habits for Happy School Staff - presentationPooky Knightsmith
 
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Aggregage
 
Persuasive Speaking and Organizational Patterns
Persuasive Speaking and Organizational PatternsPersuasive Speaking and Organizational Patterns
Persuasive Speaking and Organizational PatternsCorinne Weisgerber
 
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...EduSkills OECD
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Katherine Villaluna
 
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptxMaryPotorti1
 
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxCATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxAizaPolinarCruz
 
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...SABC News
 
Candace-Stone project& portfolio 1 class
Candace-Stone project& portfolio 1 classCandace-Stone project& portfolio 1 class
Candace-Stone project& portfolio 1 classccstone
 
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.Florence Dayana
 
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfUnit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfSUMIT TIWARI
 
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdf
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdfDr.M.Florence Dayana-Cloud Computing-unit - 4.pdf
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdfDr.Florence Dayana
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in LithuaniaEduSkills OECD
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesCeline George
 

Recently uploaded (20)

ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptxADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS  method.pptx
ADAPTABILITY, Types of Adaptability AND STABILITY ANALYSIS method.pptx
 
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
 
Google Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdfGoogle Ad Grants Services at TechSoup.pdf
Google Ad Grants Services at TechSoup.pdf
 
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
 
Advance Mobile Application Development class 04
Advance Mobile Application Development class 04Advance Mobile Application Development class 04
Advance Mobile Application Development class 04
 
Peninsula Channel Commanders Rules Handbook
Peninsula Channel Commanders Rules HandbookPeninsula Channel Commanders Rules Handbook
Peninsula Channel Commanders Rules Handbook
 
Healthy Habits for Happy School Staff - presentation
Healthy Habits for Happy School Staff - presentationHealthy Habits for Happy School Staff - presentation
Healthy Habits for Happy School Staff - presentation
 
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
Can Brain Science Actually Help Make Your Training & Teaching "Stick"?
 
Persuasive Speaking and Organizational Patterns
Persuasive Speaking and Organizational PatternsPersuasive Speaking and Organizational Patterns
Persuasive Speaking and Organizational Patterns
 
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
Managing Choice, Coherence and Specialisation in Upper Secondary Education - ...
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
 
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
 
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxCATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
 
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
MEC MAJUBA SADDENED BY THE PASSING AWAY OF THREE TEACHERS FOLLOWING A CAR ACC...
 
Candace-Stone project& portfolio 1 class
Candace-Stone project& portfolio 1 classCandace-Stone project& portfolio 1 class
Candace-Stone project& portfolio 1 class
 
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
 
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdfUnit 5th topic Drugs used in congestive Heart failure and shock.pdf
Unit 5th topic Drugs used in congestive Heart failure and shock.pdf
 
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdf
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdfDr.M.Florence Dayana-Cloud Computing-unit - 4.pdf
Dr.M.Florence Dayana-Cloud Computing-unit - 4.pdf
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 Sales
 

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; }