SlideShare a Scribd company logo
1 of 4
Download to read offline
Rewrite lab assignment 7 using pointer to allocate the array memory.
#include
#include
#include
using namespace std;
//Intiate Functions
int calculateAverageRainFall(int rainFall [], int size)
{
int sum=0;
for(int month=0; month
sum+=rainFall[month];
return sum/size;
}
void inputRainFall(int rainFall[], int size)
{
//Open the file
ifstream inputFile;
inputFile.open("rainfall.txt");
//Initialize month counter
int month = 0;
//Read the monthly rainfall in the file
for(month=0; month
inputFile >> rainFall[month];
}
void classifyAndDisplayRainfall(int rainFall[], int months)
{
//Start to List Month & Store in String
string monthNames[] = {"January","Febuary","March","April","May",
"June","July","August","September","October","November","December"};
int avgRainFall=calculateAverageRainFall(rainFall,months);
int highestRainFall,lowestRainFall;
int highestRainFallIndex,lowestRainFallIndex;
highestRainFall=lowestRainFall=rainFall[0];
highestRainFallIndex=lowestRainFallIndex=0;
//Formatted Output Columns
cout<<" MonthtRainfall(mm)tClassification ";
cout<<"-------t------------t------------------ ";
//Start For-Loop
for(int month=0; month
{
cout<<(month+1)<<"t"<
if((avgRainFall+(avgRainFall*0.2))<=rainFall[month])
cout<<"Rainy ";
else if(avgRainFall>rainFall[month]+(avgRainFall*0.25))
cout<<"Dry ";
else
cout<<"Average ";
if(highestRainFall
{
highestRainFall=rainFall[month];
highestRainFallIndex=month;
}
if(lowestRainFall>rainFall[month])
{
lowestRainFall=rainFall[month];
lowestRainFallIndex=month;
}
}//End For-Loop
///Output Information Back to User
cout<<" The year's average monthly rainfall was "<
cout<
cout<
}
//Start Main
int main()
{
int rainFall[12];
int size=12;
inputRainFall(rainFall,size);
classifyAndDisplayRainfall(rainFall,size);
return 0;
}//End Main
Solution
#include
#include
#include
using namespace std;
//Intiate Functions
int calculateAverageRainFall(int *rainFall, int size)
{
int sum=0;
for(int month=0; month> rainFall[month];
}
// this is how you pass around array pointers
void classifyAndDisplayRainfall(int *rainFall, int months)
{
//Start to List Month & Store in String
string monthNames[] = {"January","Febuary","March","April","May",
"June","July","August","September","October","November","December"};
int avgRainFall=calculateAverageRainFall(rainFall,months);
int highestRainFall,lowestRainFall;
int highestRainFallIndex,lowestRainFallIndex;
highestRainFall=lowestRainFall=rainFall[0];
highestRainFallIndex=lowestRainFallIndex=0;
//Formatted Output Columns
cout<<" MonthtRainfall(mm)tClassification ";
cout<<"-------t------------t------------------ ";
//Start For-Loop
for(int month=0; monthrainFall[month]+(avgRainFall*0.25))
cout<<"Dry ";
else
cout<<"Average ";
if(highestRainFallrainFall[month])
{
lowestRainFall=rainFall[month];
lowestRainFallIndex=month;
}
}//End For-Loop
// uncomment this once you have fixed the below cout statement
/*
///Output Information Back to User
cout<<" The year's average monthly rainfall was "<
cout<
cout<
*/
}
//Start Main
int main()
{
// this is how you initialize an int array with pointers
int *rainFall = new int[12];
int size=12;
inputRainFall(rainFall,size);
classifyAndDisplayRainfall(rainFall,size);
return 0;
}//End Main

More Related Content

More from callawaycorb73779

How is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfHow is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfcallawaycorb73779
 
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfGive three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfcallawaycorb73779
 
Find the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfFind the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfcallawaycorb73779
 
Explain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfExplain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfcallawaycorb73779
 
Do students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfDo students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfcallawaycorb73779
 
describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfcallawaycorb73779
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfcallawaycorb73779
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfcallawaycorb73779
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfcallawaycorb73779
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdfcallawaycorb73779
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfcallawaycorb73779
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfcallawaycorb73779
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfcallawaycorb73779
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdfcallawaycorb73779
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfcallawaycorb73779
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfcallawaycorb73779
 
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfUsing NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfcallawaycorb73779
 
Use the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfUse the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfcallawaycorb73779
 
the three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfthe three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfcallawaycorb73779
 

More from callawaycorb73779 (20)

How is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdfHow is the position of the vascular tissue in roots different from t.pdf
How is the position of the vascular tissue in roots different from t.pdf
 
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdfGive three examples of how the US finacial Crisis impacted HRM.S.pdf
Give three examples of how the US finacial Crisis impacted HRM.S.pdf
 
Find the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdfFind the object focal point for a combination of two thin lenses who.pdf
Find the object focal point for a combination of two thin lenses who.pdf
 
Explain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdfExplain (in points) the roleimportance of the performance of Transp.pdf
Explain (in points) the roleimportance of the performance of Transp.pdf
 
Do students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdfDo students at various colleges differ in how sociable they are 25 .pdf
Do students at various colleges differ in how sociable they are 25 .pdf
 
describe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdfdescribe these organelles and the organisms there found in1. cryst.pdf
describe these organelles and the organisms there found in1. cryst.pdf
 
Compare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdfCompare the small intestine to the large intestine in terms of histo.pdf
Compare the small intestine to the large intestine in terms of histo.pdf
 
Chemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdfChemical composition of rain water.SolutionRainwater gets its .pdf
Chemical composition of rain water.SolutionRainwater gets its .pdf
 
An adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdfAn adult male receives all his water from a municipal supply that is.pdf
An adult male receives all his water from a municipal supply that is.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf1.What does the emergence of autonomous vehicles mean to you What v.pdf
1.What does the emergence of autonomous vehicles mean to you What v.pdf
 
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdfYou have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
You have installed a PCIe wireless NIC in a computer desktop in a sm.pdf
 
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdfYou have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
You have identified a novel enzyme. Supercoiled DNA shows an upward m.pdf
 
Which of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdfWhich of the following wireless standards uses direct sequence sprea.pdf
Which of the following wireless standards uses direct sequence sprea.pdf
 
Which one of the following statements about lichens is false lichen.pdf
Which one of the following statements about lichens is false  lichen.pdfWhich one of the following statements about lichens is false  lichen.pdf
Which one of the following statements about lichens is false lichen.pdf
 
What is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdfWhat is the capability to combine data from separate sources to gain.pdf
What is the capability to combine data from separate sources to gain.pdf
 
What are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdfWhat are Factors that influence primary production in different zone.pdf
What are Factors that influence primary production in different zone.pdf
 
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdfUsing NetBeansQ1. Write a program that uses a stack to convert a n.pdf
Using NetBeansQ1. Write a program that uses a stack to convert a n.pdf
 
Use the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdfUse the counting techniques from the last chapter. A bag contains fo.pdf
Use the counting techniques from the last chapter. A bag contains fo.pdf
 
the three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdfthe three types of associations (chance, non-causal, and causal). De.pdf
the three types of associations (chance, non-causal, and causal). De.pdf
 

Recently uploaded

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 

Recently uploaded (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Rewrite lab assignment 7 using pointer to allocate the array memory..pdf

  • 1. Rewrite lab assignment 7 using pointer to allocate the array memory. #include #include #include using namespace std; //Intiate Functions int calculateAverageRainFall(int rainFall [], int size) { int sum=0; for(int month=0; month sum+=rainFall[month]; return sum/size; } void inputRainFall(int rainFall[], int size) { //Open the file ifstream inputFile; inputFile.open("rainfall.txt"); //Initialize month counter int month = 0; //Read the monthly rainfall in the file for(month=0; month inputFile >> rainFall[month]; } void classifyAndDisplayRainfall(int rainFall[], int months) { //Start to List Month & Store in String string monthNames[] = {"January","Febuary","March","April","May", "June","July","August","September","October","November","December"};
  • 2. int avgRainFall=calculateAverageRainFall(rainFall,months); int highestRainFall,lowestRainFall; int highestRainFallIndex,lowestRainFallIndex; highestRainFall=lowestRainFall=rainFall[0]; highestRainFallIndex=lowestRainFallIndex=0; //Formatted Output Columns cout<<" MonthtRainfall(mm)tClassification "; cout<<"-------t------------t------------------ "; //Start For-Loop for(int month=0; month { cout<<(month+1)<<"t"< if((avgRainFall+(avgRainFall*0.2))<=rainFall[month]) cout<<"Rainy "; else if(avgRainFall>rainFall[month]+(avgRainFall*0.25)) cout<<"Dry "; else cout<<"Average "; if(highestRainFall { highestRainFall=rainFall[month]; highestRainFallIndex=month; } if(lowestRainFall>rainFall[month]) { lowestRainFall=rainFall[month]; lowestRainFallIndex=month; } }//End For-Loop ///Output Information Back to User cout<<" The year's average monthly rainfall was "< cout<
  • 3. cout< } //Start Main int main() { int rainFall[12]; int size=12; inputRainFall(rainFall,size); classifyAndDisplayRainfall(rainFall,size); return 0; }//End Main Solution #include #include #include using namespace std; //Intiate Functions int calculateAverageRainFall(int *rainFall, int size) { int sum=0; for(int month=0; month> rainFall[month]; } // this is how you pass around array pointers void classifyAndDisplayRainfall(int *rainFall, int months) { //Start to List Month & Store in String string monthNames[] = {"January","Febuary","March","April","May", "June","July","August","September","October","November","December"}; int avgRainFall=calculateAverageRainFall(rainFall,months); int highestRainFall,lowestRainFall; int highestRainFallIndex,lowestRainFallIndex;
  • 4. highestRainFall=lowestRainFall=rainFall[0]; highestRainFallIndex=lowestRainFallIndex=0; //Formatted Output Columns cout<<" MonthtRainfall(mm)tClassification "; cout<<"-------t------------t------------------ "; //Start For-Loop for(int month=0; monthrainFall[month]+(avgRainFall*0.25)) cout<<"Dry "; else cout<<"Average "; if(highestRainFallrainFall[month]) { lowestRainFall=rainFall[month]; lowestRainFallIndex=month; } }//End For-Loop // uncomment this once you have fixed the below cout statement /* ///Output Information Back to User cout<<" The year's average monthly rainfall was "< cout< cout< */ } //Start Main int main() { // this is how you initialize an int array with pointers int *rainFall = new int[12]; int size=12; inputRainFall(rainFall,size); classifyAndDisplayRainfall(rainFall,size); return 0; }//End Main