I could use some help starting my main program. I want toread people from an inp
ID: 3615484 • Letter: I
Question
I could use some help starting my main program. I want toread people from an input file into an array of personClassobjects. Once they are in the array I am supposed to sortthem by last name and then print them to an output file.Here is my header file "person.h" :
#pragma once
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class personClass
{
public:
personClass();
string getFname()const;
string getLname()const;
int getAge()const;
char getGender()const;
void setFname(string val);
void setLname(string val);
void setAge(int val);
void setGender(char val);
void print(ostream &out);
bool read(istream &in);
private:
string fname, lname;
int age;
char gender;
};
Here is "person.cpp" :
#include "person.h"
personClass::personClass()
{
age=0;
gender='u';
}
string personClass::getFname()const
{
return fname;
}
string personClass::getLname()const
{
return lname;
}
int personClass::getAge()const
{
return age;
}
char personClass::getGender()const
{
return gender;
}
void personClass::setFname(string val)
{
fname=val;
}
void personClass::setLname(string val)
{
lname=val;
}
void personClass::setAge(int val)
{
age=val;
}
void personClass::setGender(char val)
{
gender=val;
}
void personClass::print(ostream &out)
{
out << setw(15) << fname
<< setw(15)<< lname
<< setw(10)<< age
<< setw(10)<< gender;
}
bool personClass::read(istream &in)
{
in >> fname >> lname >> age>> gender;
return in.good();
}
I am a bit confused with what to do so here is my mainprogram file so far:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include "person.h"
using namespace std;
const int SIZE = 2000;
int main()
{
return 0;
}
As you can see it is pretty much blank. How would I read froman input file into the array personClass objects?
How would I then print the array to an output file? I canwork on sorting it but I need to be able to read and print before Ican do that.
Here is a sample from my input file:
NELSON BARBER 67 m
LEWIS CASEY 24 m
BEVERLY RUSH 64 f
MARIAN HEAD 27 m
BRAD GALLOWAY 42 m
JANE RAYMOND 4 m
RUDY WISE 82 f
WM BRADY 95 f
PAT FRY 38 m
ROGELIO ADAMS 99 m
SALLY WEBER 11 m
MAMIE BURNS 64 m
DOUG GAINES 68 m
BETSY GONZALEZ 57 f
CEDRIC OCONNOR 41 m
TAYLOR GREENE 35 f
MOSES MITCHELL 6 f
KENDRA PITTMAN 48 f
DUSTIN INGRAM 29 f
BYRON ADKINS 1 f
TOMMIE POWELL 23 m
Explanation / Answer
Is any clarification needed?
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.