SlideShare a Scribd company logo
1 of 6
Download to read offline
#include
#include
#include
using namespace std;
struct Person
{
string name;
int age;
float gpa;
};
void CopyData(string filename,Person a[])
{
std::ifstream infile(filename);
string temp_name;
int temp_age;
float temp_gpa;
int i=0;
while(infile >> temp_name >> temp_age >> temp_gpa)
{
a[i].name = temp_name;
a[i].age = temp_age;
a[i].gpa = temp_gpa;
i++;
}
}
void Display(Person a[])
{
int i = 0;
cout << "Name of all the teenagers whose age is in between 13 and 19 :  ";
while(i<6)
{
if(a[i].age>=13 && a[i].age<=19)
cout << a[i].name << endl;
i++;
}
cout << endl;
}
void ComputeAverage(Person a[],float &AgeAve,float &GpaAve)
{
int i=0;
float ageSum = 0,gpaSum = 0;
while(i<6)
{
ageSum += a[i].age;
gpaSum += a[i].gpa;
i++;
}
AgeAve = ageSum/6.0;
GpaAve = gpaSum/6.0;
}
void Display(float AgeAve,float GpaAve)
{
cout << "Age Average is : " << AgeAve << endl;
cout << "GPA Average is : " << GpaAve << endl;
cout << endl;
}
void Display(Person a[],float GpaAve)
{
int i = 0;
cout << "Name of all the teenagers whose gpa is greater than average gpa :  ";
while(i<6)
{
if(a[i].gpa>GpaAve)
cout << a[i].name << " " << a[i].age << " " << a[i].gpa << endl;
i++;
}
cout << endl;
}
int main()
{
Person a[6];
string filename = "/Users/deepanshugupta/Documents/chegg/chegg/data.txt";
CopyData(filename,a);
Display(a);
float AgeAve = 0.0 ,GpaAve = 0.0;
ComputeAverage(a, AgeAve, GpaAve);
Display(AgeAve,GpaAve);
cout << endl;
Display(a,GpaAve);
cout << endl;
return 0;
}
Solution
#include
#include
#include
using namespace std;
struct Person
{
string name;
int age;
float gpa;
};
void CopyData(string filename,Person a[])
{
std::ifstream infile(filename);
string temp_name;
int temp_age;
float temp_gpa;
int i=0;
while(infile >> temp_name >> temp_age >> temp_gpa)
{
a[i].name = temp_name;
a[i].age = temp_age;
a[i].gpa = temp_gpa;
i++;
}
}
void Display(Person a[])
{
int i = 0;
cout << "Name of all the teenagers whose age is in between 13 and 19 :  ";
while(i<6)
{
if(a[i].age>=13 && a[i].age<=19)
cout << a[i].name << endl;
i++;
}
cout << endl;
}
void ComputeAverage(Person a[],float &AgeAve,float &GpaAve)
{
int i=0;
float ageSum = 0,gpaSum = 0;
while(i<6)
{
ageSum += a[i].age;
gpaSum += a[i].gpa;
i++;
}
AgeAve = ageSum/6.0;
GpaAve = gpaSum/6.0;
}
void Display(float AgeAve,float GpaAve)
{
cout << "Age Average is : " << AgeAve << endl;
cout << "GPA Average is : " << GpaAve << endl;
cout << endl;
}
void Display(Person a[],float GpaAve)
{
int i = 0;
cout << "Name of all the teenagers whose gpa is greater than average gpa :  ";
while(i<6)
{
if(a[i].gpa>GpaAve)
cout << a[i].name << " " << a[i].age << " " << a[i].gpa << endl;
i++;
}
cout << endl;
}
int main()
{
Person a[6];
string filename = "/Users/deepanshugupta/Documents/chegg/chegg/data.txt";
CopyData(filename,a);
Display(a);
float AgeAve = 0.0 ,GpaAve = 0.0;
ComputeAverage(a, AgeAve, GpaAve);
Display(AgeAve,GpaAve);
cout << endl;
Display(a,GpaAve);
cout << endl;
return 0;
}

More Related Content

Similar to #includeiostream#includestring#include fstreamusing name.pdf

Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programsKandarp Tiwari
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMKrishna Raj
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
    #include STDIO.H     int main() {        char file_name[.pdf
    #include STDIO.H     int main() {        char file_name[.pdf    #include STDIO.H     int main() {        char file_name[.pdf
    #include STDIO.H     int main() {        char file_name[.pdfanjalipub
 
C basics
C basicsC basics
C basicsMSc CST
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacionJeff Tu Pechito
 
Aplikasi menghitung matematika dengan c++
Aplikasi menghitung matematika dengan c++Aplikasi menghitung matematika dengan c++
Aplikasi menghitung matematika dengan c++radar radius
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)hasan0812
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
 

Similar to #includeiostream#includestring#include fstreamusing name.pdf (20)

Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
Cmptr ass
Cmptr assCmptr ass
Cmptr ass
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
    #include STDIO.H     int main() {        char file_name[.pdf
    #include STDIO.H     int main() {        char file_name[.pdf    #include STDIO.H     int main() {        char file_name[.pdf
    #include STDIO.H     int main() {        char file_name[.pdf
 
C basics
C basicsC basics
C basics
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Aplikasi menghitung matematika dengan c++
Aplikasi menghitung matematika dengan c++Aplikasi menghitung matematika dengan c++
Aplikasi menghitung matematika dengan c++
 
Ccc
CccCcc
Ccc
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Programs of C++
Programs of C++Programs of C++
Programs of C++
 
C programms
C programmsC programms
C programms
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 

More from noelbuddy

1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdfnoelbuddy
 
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdfnoelbuddy
 
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdfnoelbuddy
 
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdfnoelbuddy
 
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdfnoelbuddy
 
just hit the ln button sorry guys .pdf
                     just hit the ln button sorry guys                .pdf                     just hit the ln button sorry guys                .pdf
just hit the ln button sorry guys .pdfnoelbuddy
 
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf
I have seen in a table that pKa of H3PO4 =2.12 s.pdfnoelbuddy
 
Yes. You can prove it experimentally, but if you.pdf
                     Yes.  You can prove it experimentally, but if you.pdf                     Yes.  You can prove it experimentally, but if you.pdf
Yes. You can prove it experimentally, but if you.pdfnoelbuddy
 
the one which is oxidized is reducing agent Pb wa.pdf
                     the one which is oxidized is reducing agent Pb wa.pdf                     the one which is oxidized is reducing agent Pb wa.pdf
the one which is oxidized is reducing agent Pb wa.pdfnoelbuddy
 
   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdfnoelbuddy
 
What inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfWhat inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfnoelbuddy
 
The tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfThe tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfnoelbuddy
 
public class Party {    private int guests;      return .pdf
public class Party {    private int guests;        return .pdfpublic class Party {    private int guests;        return .pdf
public class Party {    private int guests;      return .pdfnoelbuddy
 
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfThe main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfnoelbuddy
 
The motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfThe motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfnoelbuddy
 
The formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfThe formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfnoelbuddy
 
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf
Density = MassVolume = 4.023.57 = 1.126 gml .pdfnoelbuddy
 
D is correct. Solution D .pdf
                     D is correct. Solution                     D .pdf                     D is correct. Solution                     D .pdf
D is correct. Solution D .pdfnoelbuddy
 
doesnt work since S in SO3 is +6 oxidation stat.pdf
                     doesnt work since S in SO3 is +6 oxidation stat.pdf                     doesnt work since S in SO3 is +6 oxidation stat.pdf
doesnt work since S in SO3 is +6 oxidation stat.pdfnoelbuddy
 
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdf
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdftan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdf
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdfnoelbuddy
 

More from noelbuddy (20)

1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
 
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
 
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
 
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
 
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
 
just hit the ln button sorry guys .pdf
                     just hit the ln button sorry guys                .pdf                     just hit the ln button sorry guys                .pdf
just hit the ln button sorry guys .pdf
 
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
 
Yes. You can prove it experimentally, but if you.pdf
                     Yes.  You can prove it experimentally, but if you.pdf                     Yes.  You can prove it experimentally, but if you.pdf
Yes. You can prove it experimentally, but if you.pdf
 
the one which is oxidized is reducing agent Pb wa.pdf
                     the one which is oxidized is reducing agent Pb wa.pdf                     the one which is oxidized is reducing agent Pb wa.pdf
the one which is oxidized is reducing agent Pb wa.pdf
 
   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf
 
What inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfWhat inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdf
 
The tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfThe tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdf
 
public class Party {    private int guests;      return .pdf
public class Party {    private int guests;        return .pdfpublic class Party {    private int guests;        return .pdf
public class Party {    private int guests;      return .pdf
 
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfThe main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
 
The motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfThe motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdf
 
The formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfThe formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdf
 
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
 
D is correct. Solution D .pdf
                     D is correct. Solution                     D .pdf                     D is correct. Solution                     D .pdf
D is correct. Solution D .pdf
 
doesnt work since S in SO3 is +6 oxidation stat.pdf
                     doesnt work since S in SO3 is +6 oxidation stat.pdf                     doesnt work since S in SO3 is +6 oxidation stat.pdf
doesnt work since S in SO3 is +6 oxidation stat.pdf
 
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdf
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdftan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdf
tan(x) = 2 , 0x 90degcosx = 1sqrt5sinx =2sqrt5Usinf the tr.pdf
 

Recently uploaded

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 

Recently uploaded (20)

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 

#includeiostream#includestring#include fstreamusing name.pdf

  • 1. #include #include #include using namespace std; struct Person { string name; int age; float gpa; }; void CopyData(string filename,Person a[]) { std::ifstream infile(filename); string temp_name; int temp_age; float temp_gpa; int i=0; while(infile >> temp_name >> temp_age >> temp_gpa) { a[i].name = temp_name; a[i].age = temp_age; a[i].gpa = temp_gpa; i++; } } void Display(Person a[]) { int i = 0; cout << "Name of all the teenagers whose age is in between 13 and 19 : "; while(i<6) { if(a[i].age>=13 && a[i].age<=19)
  • 2. cout << a[i].name << endl; i++; } cout << endl; } void ComputeAverage(Person a[],float &AgeAve,float &GpaAve) { int i=0; float ageSum = 0,gpaSum = 0; while(i<6) { ageSum += a[i].age; gpaSum += a[i].gpa; i++; } AgeAve = ageSum/6.0; GpaAve = gpaSum/6.0; } void Display(float AgeAve,float GpaAve) { cout << "Age Average is : " << AgeAve << endl; cout << "GPA Average is : " << GpaAve << endl; cout << endl; } void Display(Person a[],float GpaAve) { int i = 0; cout << "Name of all the teenagers whose gpa is greater than average gpa : "; while(i<6) { if(a[i].gpa>GpaAve) cout << a[i].name << " " << a[i].age << " " << a[i].gpa << endl; i++;
  • 3. } cout << endl; } int main() { Person a[6]; string filename = "/Users/deepanshugupta/Documents/chegg/chegg/data.txt"; CopyData(filename,a); Display(a); float AgeAve = 0.0 ,GpaAve = 0.0; ComputeAverage(a, AgeAve, GpaAve); Display(AgeAve,GpaAve); cout << endl; Display(a,GpaAve); cout << endl; return 0; } Solution #include #include #include using namespace std; struct Person { string name; int age; float gpa; }; void CopyData(string filename,Person a[]) { std::ifstream infile(filename); string temp_name;
  • 4. int temp_age; float temp_gpa; int i=0; while(infile >> temp_name >> temp_age >> temp_gpa) { a[i].name = temp_name; a[i].age = temp_age; a[i].gpa = temp_gpa; i++; } } void Display(Person a[]) { int i = 0; cout << "Name of all the teenagers whose age is in between 13 and 19 : "; while(i<6) { if(a[i].age>=13 && a[i].age<=19) cout << a[i].name << endl; i++; } cout << endl; } void ComputeAverage(Person a[],float &AgeAve,float &GpaAve) { int i=0; float ageSum = 0,gpaSum = 0; while(i<6) { ageSum += a[i].age; gpaSum += a[i].gpa; i++;
  • 5. } AgeAve = ageSum/6.0; GpaAve = gpaSum/6.0; } void Display(float AgeAve,float GpaAve) { cout << "Age Average is : " << AgeAve << endl; cout << "GPA Average is : " << GpaAve << endl; cout << endl; } void Display(Person a[],float GpaAve) { int i = 0; cout << "Name of all the teenagers whose gpa is greater than average gpa : "; while(i<6) { if(a[i].gpa>GpaAve) cout << a[i].name << " " << a[i].age << " " << a[i].gpa << endl; i++; } cout << endl; } int main() { Person a[6]; string filename = "/Users/deepanshugupta/Documents/chegg/chegg/data.txt"; CopyData(filename,a); Display(a); float AgeAve = 0.0 ,GpaAve = 0.0; ComputeAverage(a, AgeAve, GpaAve); Display(AgeAve,GpaAve); cout << endl;