SlideShare uma empresa Scribd logo
1 de 2
Write a function mostExpensive that:
• takes as argument a string, filename, which is the name of a text file containing lines looking
like this:
bicycle ??? dollars
• The function finds the most expensive item in the file and returns it (as a string).
For example, suppose that file "inventory.txt" has these contents:
bicycle 80 dollars
table 150 dollars
chair 40 dollars
watch 25 dollars
Then: mostExpensive("inventory.txt") returns "table".
Solution
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
string mostExpensive(char* filename){
ifstream infile;
infile.open (filename);
string s,smax,dollar;
int n,nmax;
infile>>smax;
infile>>nmax;
infile>>dollar;
while(infile>>s){
infile>>n;
infile>>dollar;
if(n>nmax){
nmax = n;
smax = s;
}
}
return smax;
}
int main(){
cout<<mostExpensive("inventory.txt");
return 0;
}

Mais conteúdo relacionado

Semelhante a Write a function mostExpensive that- takes as argument a string- file.docx

Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Template Haskell Tutorial
Template Haskell TutorialTemplate Haskell Tutorial
Template Haskell Tutorialkizzx2
 
F# delight
F# delightF# delight
F# delightpriort
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxDIPESH30
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189Mahmoud Samir Fayed
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and GoEleanor McHugh
 
The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185Mahmoud Samir Fayed
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetSamuel Lampa
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181Mahmoud Samir Fayed
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala Knoldus Inc.
 

Semelhante a Write a function mostExpensive that- takes as argument a string- file.docx (20)

Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Template Haskell Tutorial
Template Haskell TutorialTemplate Haskell Tutorial
Template Haskell Tutorial
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
08 php-files
08 php-files08 php-files
08 php-files
 
F# delight
F# delightF# delight
F# delight
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Five
FiveFive
Five
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180
 
Php sql-android
Php sql-androidPhp sql-android
Php sql-android
 
The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185The Ring programming language version 1.5.4 book - Part 34 of 185
The Ring programming language version 1.5.4 book - Part 34 of 185
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
 
The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181The Ring programming language version 1.5.2 book - Part 22 of 181
The Ring programming language version 1.5.2 book - Part 22 of 181
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 

Mais de lez31palka

ctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docxctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docxlez31palka
 
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docxCSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docxlez31palka
 
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docxCritical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docxlez31palka
 
Critical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docxCritical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docxlez31palka
 
Credit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docxCredit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docxlez31palka
 
Create software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docxCreate software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docxlez31palka
 
create a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docxcreate a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docxlez31palka
 
Create a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docxCreate a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docxlez31palka
 
Create a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docxCreate a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docxlez31palka
 
Create a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docxCreate a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docxlez31palka
 
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docxCreate a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docxlez31palka
 
Create a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docxCreate a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docxlez31palka
 
Create a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docxCreate a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docxlez31palka
 
Create a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docxCreate a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docxlez31palka
 
Create a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docxCreate a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docxlez31palka
 
Create a Java class with the below attributes- Create a class called.docx
Create a Java class with the below attributes-  Create a class called.docxCreate a Java class with the below attributes-  Create a class called.docx
Create a Java class with the below attributes- Create a class called.docxlez31palka
 
Create a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docxCreate a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docxlez31palka
 
Create a garden project - Submit a project scope document - Submit R.docx
Create a garden project   - Submit a project scope document - Submit R.docxCreate a garden project   - Submit a project scope document - Submit R.docx
Create a garden project - Submit a project scope document - Submit R.docxlez31palka
 
Create a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docxCreate a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docxlez31palka
 
Corporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docxCorporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docxlez31palka
 

Mais de lez31palka (20)

ctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docxctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
 
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docxCSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
 
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docxCritical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
 
Critical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docxCritical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docx
 
Credit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docxCredit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docx
 
Create software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docxCreate software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docx
 
create a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docxcreate a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docx
 
Create a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docxCreate a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docx
 
Create a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docxCreate a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docx
 
Create a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docxCreate a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docx
 
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docxCreate a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docx
 
Create a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docxCreate a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docx
 
Create a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docxCreate a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docx
 
Create a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docxCreate a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docx
 
Create a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docxCreate a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docx
 
Create a Java class with the below attributes- Create a class called.docx
Create a Java class with the below attributes-  Create a class called.docxCreate a Java class with the below attributes-  Create a class called.docx
Create a Java class with the below attributes- Create a class called.docx
 
Create a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docxCreate a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docx
 
Create a garden project - Submit a project scope document - Submit R.docx
Create a garden project   - Submit a project scope document - Submit R.docxCreate a garden project   - Submit a project scope document - Submit R.docx
Create a garden project - Submit a project scope document - Submit R.docx
 
Create a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docxCreate a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docx
 
Corporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docxCorporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docx
 

Último

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Último (20)

Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 

Write a function mostExpensive that- takes as argument a string- file.docx

  • 1. Write a function mostExpensive that: • takes as argument a string, filename, which is the name of a text file containing lines looking like this: bicycle ??? dollars • The function finds the most expensive item in the file and returns it (as a string). For example, suppose that file "inventory.txt" has these contents: bicycle 80 dollars table 150 dollars chair 40 dollars watch 25 dollars Then: mostExpensive("inventory.txt") returns "table". Solution #include<iostream> #include<fstream> #include<string> using namespace std; string mostExpensive(char* filename){ ifstream infile; infile.open (filename); string s,smax,dollar; int n,nmax; infile>>smax; infile>>nmax;
  • 2. infile>>dollar; while(infile>>s){ infile>>n; infile>>dollar; if(n>nmax){ nmax = n; smax = s; } } return smax; } int main(){ cout<<mostExpensive("inventory.txt"); return 0; }