SlideShare a Scribd company logo
#include
#include
using namespace std;
void getData(ifstream &in, int highLowTemperatures[][2]){
for(int i = 0; i < 12; ++i){
in >> highLowTemperatures[i][0];
}
for(int i = 0; i < 12; ++i){
in >> highLowTemperatures[i][1];
}
}
int indexHighTemp(int temperatures[][2]){
int val = 0;
for(int i = 1; i < 12; ++i){
if(temperatures[val][0] < temperatures[i][0]){
val = i;
}
}
return val;
}
int indexLowTemp(int temperatures[][2]){
int val = 0;
for(int i = 1; i < 12; ++i){
if(temperatures[val][1] > temperatures[i][1]){
val = i;
}
}
return val;
}
int main(){
ifstream in;
string fName;
cout << "Enter file name: ";
cin >> fName;
in.open(fName.c_str());
int highLowTemperatures[12][2];
if(in.is_open()){
getData(in, highLowTemperatures);
cout << "Highest temperature of the year is " <<
highLowTemperatures[indexHighTemp(highLowTemperatures)][0] << endl;
cout << "Lowest temperature of the year is " <<
highLowTemperatures[indexLowTemp(highLowTemperatures)][1] << endl;
}
else{
cout << "Can not open the file" << endl;
}
return 0;
}
Solution
#include
#include
using namespace std;
void getData(ifstream &in, int highLowTemperatures[][2]){
for(int i = 0; i < 12; ++i){
in >> highLowTemperatures[i][0];
}
for(int i = 0; i < 12; ++i){
in >> highLowTemperatures[i][1];
}
}
int indexHighTemp(int temperatures[][2]){
int val = 0;
for(int i = 1; i < 12; ++i){
if(temperatures[val][0] < temperatures[i][0]){
val = i;
}
}
return val;
}
int indexLowTemp(int temperatures[][2]){
int val = 0;
for(int i = 1; i < 12; ++i){
if(temperatures[val][1] > temperatures[i][1]){
val = i;
}
}
return val;
}
int main(){
ifstream in;
string fName;
cout << "Enter file name: ";
cin >> fName;
in.open(fName.c_str());
int highLowTemperatures[12][2];
if(in.is_open()){
getData(in, highLowTemperatures);
cout << "Highest temperature of the year is " <<
highLowTemperatures[indexHighTemp(highLowTemperatures)][0] << endl;
cout << "Lowest temperature of the year is " <<
highLowTemperatures[indexLowTemp(highLowTemperatures)][1] << endl;
}
else{
cout << "Can not open the file" << endl;
}
return 0;
}

More Related Content

PDF
The Weather Service Bureau department has data representing .pdf
PDF
In JAVA Write a program that uses a two-dimensional array to sto.pdf
PDF
Write a program in c++ that produces a bar chart showing the populat.pdf
PDF
Program 1 (Practicing an example of function using call by referenc.pdf
PDF
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
DOCX
data_selectionOctober 19, 2022[1] # Data Selection.docx
PDF
Alternative 1 Continuing present jobPV = Pmt x (1 + i) x (1 - (1 .pdf
PDF
Wilhelm Johannsen first proposed the distinction between genotype a.pdf
The Weather Service Bureau department has data representing .pdf
In JAVA Write a program that uses a two-dimensional array to sto.pdf
Write a program in c++ that produces a bar chart showing the populat.pdf
Program 1 (Practicing an example of function using call by referenc.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
data_selectionOctober 19, 2022[1] # Data Selection.docx
Alternative 1 Continuing present jobPV = Pmt x (1 + i) x (1 - (1 .pdf
Wilhelm Johannsen first proposed the distinction between genotype a.pdf

More from anupamele (20)

PDF
True, they are identical Thats just the bottom vi.pdf
PDF
The NH2OH is in acidic solution as a reactant and.pdf
PDF
The atom is a basic unit of matter consisting of .pdf
PDF
see the inner one is union of events from 1-inf. .pdf
PDF
No you wouldnt include the intermediates in the.pdf
PDF
mole of NaOH= 1240 =0.3 so molarity = 0.31.8 = .pdf
PDF
millimoles of HBr=500.04=2 millimoles of KOH=25.pdf
PDF
initially 2 moles of HCl per L of water suppose x.pdf
PDF
i cant see the question.. please post the complet.pdf
PDF
hey pls give the reactions.... .pdf
PDF
FT-Raman spectra of some calcium phosphates, calc.pdf
PDF
H is oxidised here no O2 is not oxidised as it g.pdf
PDF
Current Stock price = Expected dividend (Required rate of return -.pdf
PDF
YES the news stories in the Illustrated American sympathetic or non-.pdf
PDF
Well its quite an easy one. The given curve is a cardioid. The limit.pdf
PDF
Total ionic Equation is 2Cu2+ +4 Cl - + 4H+ +SO42- --- Cu2SiO4+ 4.pdf
PDF
AnswerSOCS are the supressor of cytokine signaling proteins and a.pdf
PDF
The pre-mRNA is converted into mature mRNA by modifications known as.pdf
PDF
CH3CH2OH will have high boiling point becauseof t.pdf
PDF
SO4 would have isolated (unlinked) tetrahedra that are all oxygen an.pdf
True, they are identical Thats just the bottom vi.pdf
The NH2OH is in acidic solution as a reactant and.pdf
The atom is a basic unit of matter consisting of .pdf
see the inner one is union of events from 1-inf. .pdf
No you wouldnt include the intermediates in the.pdf
mole of NaOH= 1240 =0.3 so molarity = 0.31.8 = .pdf
millimoles of HBr=500.04=2 millimoles of KOH=25.pdf
initially 2 moles of HCl per L of water suppose x.pdf
i cant see the question.. please post the complet.pdf
hey pls give the reactions.... .pdf
FT-Raman spectra of some calcium phosphates, calc.pdf
H is oxidised here no O2 is not oxidised as it g.pdf
Current Stock price = Expected dividend (Required rate of return -.pdf
YES the news stories in the Illustrated American sympathetic or non-.pdf
Well its quite an easy one. The given curve is a cardioid. The limit.pdf
Total ionic Equation is 2Cu2+ +4 Cl - + 4H+ +SO42- --- Cu2SiO4+ 4.pdf
AnswerSOCS are the supressor of cytokine signaling proteins and a.pdf
The pre-mRNA is converted into mature mRNA by modifications known as.pdf
CH3CH2OH will have high boiling point becauseof t.pdf
SO4 would have isolated (unlinked) tetrahedra that are all oxygen an.pdf
Ad

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
advance database management system book.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
Computing-Curriculum for Schools in Ghana
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Hazard Identification & Risk Assessment .pdf
A systematic review of self-coping strategies used by university students to ...
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
RMMM.pdf make it easy to upload and study
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
advance database management system book.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Digestion and Absorption of Carbohydrates, Proteina and Fats
Computing-Curriculum for Schools in Ghana
LDMMIA Reiki Yoga Finals Review Spring Summer
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Orientation - ARALprogram of Deped to the Parents.pptx
What if we spent less time fighting change, and more time building what’s rig...
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
History, Philosophy and sociology of education (1).pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Weekly quiz Compilation Jan -July 25.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Hazard Identification & Risk Assessment .pdf
Ad

#include iostream #include fstreamusing namespace std;void.pdf

  • 1. #include #include using namespace std; void getData(ifstream &in, int highLowTemperatures[][2]){ for(int i = 0; i < 12; ++i){ in >> highLowTemperatures[i][0]; } for(int i = 0; i < 12; ++i){ in >> highLowTemperatures[i][1]; } } int indexHighTemp(int temperatures[][2]){ int val = 0; for(int i = 1; i < 12; ++i){ if(temperatures[val][0] < temperatures[i][0]){ val = i; } } return val; } int indexLowTemp(int temperatures[][2]){ int val = 0; for(int i = 1; i < 12; ++i){ if(temperatures[val][1] > temperatures[i][1]){ val = i; } } return val; } int main(){ ifstream in; string fName; cout << "Enter file name: "; cin >> fName; in.open(fName.c_str());
  • 2. int highLowTemperatures[12][2]; if(in.is_open()){ getData(in, highLowTemperatures); cout << "Highest temperature of the year is " << highLowTemperatures[indexHighTemp(highLowTemperatures)][0] << endl; cout << "Lowest temperature of the year is " << highLowTemperatures[indexLowTemp(highLowTemperatures)][1] << endl; } else{ cout << "Can not open the file" << endl; } return 0; } Solution #include #include using namespace std; void getData(ifstream &in, int highLowTemperatures[][2]){ for(int i = 0; i < 12; ++i){ in >> highLowTemperatures[i][0]; } for(int i = 0; i < 12; ++i){ in >> highLowTemperatures[i][1]; } } int indexHighTemp(int temperatures[][2]){ int val = 0; for(int i = 1; i < 12; ++i){ if(temperatures[val][0] < temperatures[i][0]){ val = i; } } return val; }
  • 3. int indexLowTemp(int temperatures[][2]){ int val = 0; for(int i = 1; i < 12; ++i){ if(temperatures[val][1] > temperatures[i][1]){ val = i; } } return val; } int main(){ ifstream in; string fName; cout << "Enter file name: "; cin >> fName; in.open(fName.c_str()); int highLowTemperatures[12][2]; if(in.is_open()){ getData(in, highLowTemperatures); cout << "Highest temperature of the year is " << highLowTemperatures[indexHighTemp(highLowTemperatures)][0] << endl; cout << "Lowest temperature of the year is " << highLowTemperatures[indexLowTemp(highLowTemperatures)][1] << endl; } else{ cout << "Can not open the file" << endl; } return 0; }