This is an assignment for a course that I am having problems with. Until now I thought I was fairly familiar with vectors in C++. This program is supposed to take a file from the user calculate the users pay then spit back out in a nice table all the information relevant.
It must contain a vector of struct and I must use push_back. I get two errors that I cannot figure out at this moment. In the for loop at the end of main() it tells me a reference type of vector cannot be initialized with Employee. The two functions after ward tell me that I for example .HoursWorked is not a member of the struct.
I tried looking around other questions for help but they all mentioned not using pointers which I'm 100% positive there are no pointers in my program. The txt file I am using for testing the program looks as follows:
John Smith 123-09-8765 9.00 46 F
Kevin Ashes 321-09-8444 9.50 40 F
Kim Cares 131-12-1231 11.25 50 P
Trish Dish 141-51-4564 7.52 24 P
Kyle Wader 432-12-9889 5.75 48 F
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
using namespace std;
struct Employee
{
string name;
string ssn;
double hourlyWage;
double HoursWorked;
char status;
double straightTimePay;
double overTimePay;
double netPay;
};
void calculatePay(vector<Employee>& buisness);
void displayEmployee(vector<Employee> buisness);
int main()
{
vector<Employee> buisness;
string fileName, line;
ifstream inFile;
stringstream ss;
cout << "Please input the file name to read: ";
cin >> fileName;
inFile.open(fileName);
if (!inFile)
{
cout << "Cannot open file " << fileName << " Aborting!" << endl;
exit(1);
}
int index = 0;
string firstName, lastName;
getline(inFile, line);
while (!inFile.eof())
{
if (line.length() > 0)
{
ss.clear();
ss.str(line);
buisness.push_back;
ss >> firstName >> lastName;
buisness[index].name = firstName + " " + lastName;
ss >> buisness[index].ssn;
ss >> buisness[index].hourlyWage >> buisness[index].HoursWorked;
ss >> buisness[index].status;
index++;
}
getline(inFile, line);
}
inFile.close();
cout << "The information of the buisness:" << endl;
cout << setw(20) << "Name" << setw(15) << "SSN" << setw(12) << "Hourly Wage";
cout << setw(14) << "Hours Worked" << setw(18) << "Straight Time Pay";
cout << setw(14) << "Over Time Pay" << setw(6) << "Status" << setw(10) << "Net Pay" << endl;
for (index = 0; index < buisness.size(); index++)
{
calculatePay(buisness[index]);
displayEmployee(buisness[index]);
}
return 0;
}
void calculatePay(vector<Employee>& buisness)
{
if (buisness.HoursWorked <= 40)
{
buisness.straightTimePay = buisness.hourlyWage * buisness.HoursWorked;
buisness.overTimePay = 0;
}
else
{
buisness.straightTimePay = buisness.hourlyWage * 40;
buisness.overTimePay = buisness.hourlyWage * 1.5 * (buisness.HoursWorked - 40);
}
buisness.netPay = buisness.straightTimePay + buisness.overTimePay;
if (buisness.status == 'F')
buisness.netPay -= 10;
}
void displayEmployee(vector<Employee> buisness)
{
int precisionSetting = cout.precision();
long flagSettings = cout.flags();
cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);
cout << setw(20) << buisness.name << setw(15) << buisness.ssn << setw(12) << buisness.hourlyWage;
cout << setw(14) << buisness.HoursWorked << setw(18) << buisness.straightTimePay;
cout << setw(14) << buisness.overTimePay << setw(6) << buisness.status << setw(10) << buisness.netPay << endl;
cout.precision(precisionSetting);
cout.flags(flagSettings);
}
At the very least.. You have the line:
calculatePay(buisness[index]);
So clearly we all calling a function calculatePay and we're passing it an Employee.
But your function prototype says that it takes a std::vector<Employee>. You probably intended for the functions to take Employee & instead.
You should call vector push_back with the element to put in:
Employee employee;
// assign values to employee
ss << employee.ssn;
ss << employee.name;
business.push_back(employee);
Although the compiler error logs seem tedious, but you can almost always get enough information from the error logs. Compiling under gcc 4.2.1, the error logs says :
error: invalid initialization of reference of type ‘std::vector<Employee, std::allocator<Employee> >&’ from expression of type ‘Employee’ on the line of calling method calculatePay(). We can infer that you passed Employee to and function which want an vector of Employee as parameter. You can fix this by change calculatePay(vector<Employee>& buisness) to calculatePay(Employee& buisness). And that will fix error: ‘class std::vector<Employee, std::allocator<Employee> >’ has no member named ‘HoursWorked’
Related
i made a file named clientFile.txt
the file contain this clientFile.txt. Content:
abcd abcd 123 1607325695
A AI 123 1607327861
the function below should show the content of the text file when the function called.
void displayFile()
{
string str1;
string str2;
string fileN = "clientFile.txt";
ifstream myfilein;
myfilein.open("clientFile.txt");
double balance;
int numAct = 0;
time_t transTime;
if(!myfilein){
cerr << "FIle could not be opened" << endl;
exit(1);
}
while(myfilein >> str1 >> str2 >> balance >> transTime){
cout << setw(15) << str1 << ' ' << setw(15) << str2 << ' '
<< setw(7) << balance << " " << ctime(&transTime);
numAct++;
}
myfilein.close();
cout << "Number of records in the file " << fileN << ": " << numAct << endl;
}
but when i call it on this int main:
int main(){
ofstream myfileout;
ifstream myfilein;
string firstName,lastName;
int i=0;
string FN[1000],LN[1000];
double actBalance,AB[1000];
time_t currentTime,CT[1000];
myfilein.open ("clientFile.txt");
void displayFile();
if(myfilein.fail()){
cout<<"Creating new files"<<endl;
myfileout.open ("clientFile.txt",ios::out);
myfileout.close();
exit(1);
}
while(myfilein>>firstName>>lastName>>actBalance>>currentTime){
FN[i]=firstName;
LN[i]=lastName;
AB[i]=actBalance;
CT[i]=currentTime;
i++;
}
myfileout.open("clientFile.txt",ios::app);
cout<<"Enter first name, last name, and balance:"<<endl;
while(cin>>firstName>>lastName>>actBalance){
createRecord(myfileout, firstName,lastName,actBalance);
}
void displayFile();
myfileout.close();
}
it didnt show me any of the file content.
can you guys help me?
im using dev c++ with TDM-GCC 4.9.2 64-bit release
In last lines of main() you just need to change
void displayFile();
to
displayFile();
Because with void you're declaring a function, not calling it.
I'm working on a project for my "Programming I" class, and I am getting a strange error. It's a payroll program that calculates taxes and what-not, and our professor wants us to put some of our functions in separate .cpp files.
I've set it up so that each employee is treated as a struct:
#include <string>
using namespace std;
struct Employee {
string firstName;
string lastName;
string name;
double rate;
double hours;
char status;
double grossPay;
double insurance;
double socialSecurity;
double stateTax;
double federalTax;
double PYE;
double netPay;
};
In my main program, I have an array of seven employees: "employees", and initialize it from a separate text file, but when I try to pass the array to one of my functions in the separate .cpp files, I get this error:
argument of type "Employee *" is incompatible with parameter of type "Employee *"
The thing is, though that only happens on the first two out of three functions, while the third is fine even when commenting out the first two:
int main() {
const int numEmployees = 7;
Employee employees[numEmployees];
cout << "name" << setw(20) << right << "rate" << setw(8) << "hours" << setw(7) << "ins" << setw(7) << "soc" << setw(7) << "state" << setw(7) << "fed" << setw(7) << "net" << endl
<< setw(46) << "sec" << setw(6) << "tax" << setw(8) << "tax" << endl;
fstream data("employees.txt");
for (int i = 0; i < numEmployees; i++) {
data >> employees[i].firstName >> employees[i].lastName >> employees[i].rate >> employees[i].hours >> employees[i].status;
employees[i].name = employees[i].firstName + " " + employees[i].lastName;
}
computeGrossPay(employees, numEmployees); //<-\
computeInsurance(employees, numEmployees); //<- these two are errors
computeFederalTax(employees, numEmployees); //<-- this one is fine
for (int i = 0; i < numEmployees; i++) {
// compute social security withheld as 7% of gross pay
employees[i].socialSecurity = employees[i].grossPay * 0.07;
// compute state tax as 3% of gross pay
employees[i].stateTax = employees[i].grossPay * 0.03;
// Compute PYE (Projected Yearly earnings) as gross-pay times 52.
employees[i].PYE = employees[i].grossPay * 52;
// Compute Net pay as gross-pay minus insurance minus soc-sec minus state-tax minus fed-tax
employees[i].netPay = employees[i].grossPay - employees[i].insurance - employees[i].socialSecurity - employees[i].stateTax - employees[i].federalTax;
}
printPayroll(employees, numEmployees);
}
Here are what each of the functions look like, each in their own separate file:
void computeGrossPay(Employee* employees, int numEmployees) {
// do stuff
}
void computeInsurance(Employee* employees, int numEmployees) {
// do stuff
}
void computeFederalTax(Employee* employees, int numEmployees) {
// do stuff
}
How can I fix this?
EDIT: I believe this may have been a problem with my IDE. I was using Visual Studio, and as other users pointed out, it compiles just fine elsewhere. I think I'll stick to basic text editors until I'm ready for the more advanced IDEs.
I have several remarks about this code. This code is using C-style arrays, and passing it as pointers and pointer size, which is ill-advised. Also, It doesn't use some of the most basic concepts of C++.
I have made some rearrangements - mostly made Employee into a real struct/class, with its own member functions, instead of passing it from outside. Made the array using the std::array (which is preferable over the raw array), and finally, a small touch - made the number of employees a constexpr.
I haven't arranged the input parsing, but actually, Employee needs to be a class, that disallows touching the values of its members from outside, and should have a constructor, which gets all the relevant inputs, instead of what is done now.
Look at this rearranged code:
using namespace std; // I strongly suggest against it!!!!
struct Employee {
string firstName;
string lastName;
string name;
double rate;
double hours;
char status;
double grossPay;
double insurance;
double socialSecurity;
double stateTax;
double federalTax;
double PYE;
double netPay;
void computeAll() // a bad name, but I don't have a better idea now!
{
computeGrossPay();
computeInsurance();
computeFederalTax();
computeSocialSecurity();
computeStateTax();
computePYE();
computeNetPay();
}
private:
void computeGrossPay();
void computeInsurance();
void computeFederalTax();
void computeSocialSecurity();
void computeStateTax();
void computePYE();
void computeNetPay();
};
int main() {
constexpr uint64_t NUM_OF_EMPLOYEES = 7;
std::array<Employee, NUM_OF_EMPLOYEES> employees{};
cout << "name" << setw(20) << right << "rate" << setw(8) << "hours" << setw(7) << "ins" << setw(7) << "soc" << setw(7) << "state" << setw(7) << "fed" << setw(7) << "net" << endl
<< setw(46) << "sec" << setw(6) << "tax" << setw(8) << "tax" << endl;
fstream data("employees.txt");
for (auto& employee : employees)
{
data >> employee.firstName >> employee.lastName >> employee.rate >> employee.hours >> employee.status;
employee.name = employee.firstName + " " + employee.lastName;
employee.computeAll();
}
return 0;
}
trying to format with c++ getline function. The output puts everything at the first record number forename instead of where it should go.
Code:
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
const int RANGE = 12;
string tab[RANGE];
int i = 0, j = 0;
ifstream reader("records.txt");
if (!reader)
{
cout << "Error opening input file" << endl;
return -1;
}
while (!reader.eof())
{
if ( ( i + 1) % 4 == 0)
getline( reader, tab[i++], '\n');
else
getline( reader, tab[i++], '\t');
}
reader.close();
i = 0;
while (i < RANGE)
{
cout << endl << "Record Number: " << ++j << endl;
cout << "Forename: " << tab[i++] << endl;
cout << "Surname: " << tab[i++] << endl;
cout << "Department: " << tab[i++] << endl;
cout << "Telephone: " << tab[i++] << endl;
}
return 0;
}
Contents of TXT file:
John Smith Sales 555-1234
Mary Jones Wages 555-9876
Paul Harris Accts 555-4321
Please run the code for yourself to understand what happens and put the txt file in the same folder as your code.
Hope someone can help me thanks.
See Why is iostream::eof inside a loop condition (i.e. while (!stream.eof())) considered wrong?.
Also, your final while loop should only output the strings that were actually read into the array, not the full array, if the file has less than 12 strings. But unless you can guarantee that your file never exceeds 12 strings, you should use std::vector instead of a fixed array.
Also, instead of alternating the getline() delimiter in a single loop, I would just use an outer loop to read whole lines only, and then separately read tab-delimited values from each line. And then store the values in an array/vector of struct instead of individually.
Try something more like this:
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
struct Person
{
string foreName;
string surName;
string department;
string phoneNumber;
};
int main()
{
ifstream reader("records.txt");
if (!reader)
{
cout << "Error opening input file" << endl;
return -1;
}
vector<Person> people;
string line;
while (getline(reader, line))
{
istringstream iss(line);
Person p;
getline(iss, p.foreName, '\t');
getline(iss, p.surName, '\t');
getline(iss, p.department, '\t');
getline(iss, p.phoneNumber, '\t');
people.push_back(p);
}
reader.close();
int j = 0;
for (Person &p : people)
{
cout << endl << "Record Number: " << ++j << endl;
cout << "Forename: " << p.foreName << endl;
cout << "Surname: " << p.surName << endl;
cout << "Department: " << p.department << endl;
cout << "Telephone: " << p.phoneNumber << endl;
}
return 0;
}
There are easier ways to separate words in an istream, namely C++ sring stream tools:
#include <fstream>
#include <iostream>
#include <sstream> //<-- string stream library
using namespace std; //<-- should not be used, use scope std::
int main() {
const int RANGE = 12;
string tab[RANGE];
string temp; //<--to store each field temporarily
int i = 0, j = 0;
ifstream reader("records.txt");
if (!reader) {
cout << "Error opening input file" << endl;
return -1;
}
while (getline(reader, temp)) { //<-- read one full line
stringstream ss(temp); // <-- input to a string stream
while(ss >> tab[i]){ // <-- passing strings to the string array one by one
i++;
}
}
reader.close();
i = 0;
while (i < RANGE) {
cout << endl << "Record Number: " << ++j << endl;
cout << "Forename: " << tab[i++] << endl;
cout << "Surname: " << tab[i++] << endl;
cout << "Department: " << tab[i++] << endl;
cout << "Telephone: " << tab[i++] << endl;
}
return 0;
}
The idea here was to mess as little as possible with your code, one thing I would advise is to use std::vector instead of normal fixed size arrays. Also, as it was said and linked, eof is very unreliable.
The source of your problem, I think, is explained in Why is iostream::eof inside a loop condition (i.e. `while (!stream.eof())`) considered wrong?.
You are reading into tab[12], tab[13], tab[13], and tab[14] due to that error. Of course, that leads to undefined behavior.
Change the loop to:
// Read the contents of the file line by line
std::string line;
while (getline( reader, line))
{
// Process each line's contents.
std::istringstream str(line);
getline(str, tab[i++], '\t');
getline(str, tab[i++], '\t');
getline(str, tab[i++], '\t');
getline(str, tab[i++], '\n');
}
Make sure to add
#include <sstream>
To be doubly sure that you are not using the array using out of bounds indices, add a check.
while ( i+4 < RANGE && getline( reader, line))
{
...
}
First, while (!reader.eof()) is not doing the right thing.
The immediate problem you see is caused by the fact that your file does not contain '\t', hence already the very first getline reads all the contents of the file into tab[0]. (At least thats what I got after 1-to-1 copying your file contents)
Your code is rather difficult, because you declare variables long before you use them and later reuse them. You have a fixed size array, but when there are more lines in the file your code will just crash. Also reading everything into a plain array of strings is making things complicated. Accessing forename or other fields requires you to compute the offset into the array. Better use a data structure:
struct file_entry {
std::string first_name;
std::string last_name;
std::string departure;
std::string phone;
};
Then you can define an input operator:
std::istream& operator>>(std::istream& in,file_entry& fe) {
return in >> fe.first_name >> fe.last_name >> fe.departure >> fe.phone;
};
And use a std::vector to store as many entries as there are in the file:
int main() {
std::string contents{"John Smith Sales 555-1234\n"
"Mary Jones Wages 555-9876\n"
"Paul Harris Accts 555-4321\n"};
std::stringstream reader{contents};
std::vector<file_entry> data;
std::string line;
while (std::getline(reader,line)) {
file_entry fe;
std::stringstream{line} >> fe;
data.push_back(fe);
}
for (const auto& fe : data) {
std::cout << "Forename: " << fe.first_name << '\n';
std::cout << "Surname: " << fe.last_name << '\n';
std::cout << "Department: " << fe.departure << '\n';
std::cout << "Telephone: " << fe.phone << '\n';
}
}
live example
PS you do not need to call close on the file, this is already done in its destructor. Not calling it explicitly has the benefit that the same code that works for a file stream also works for a stringstream.
I have an assignment where we need to create a class object that has many different variables, one of which being a struct. I can't figure out how to fill the struct from my setter function. I've attached some codes snippets I've pulled out of my code. my count_file_line function returns an int value of however many lines are in a txt file. I'm also really new to coding and have been struggling so if it's an obvious answer, sorry
When I run the program and try to cout teachers[I].password from within the setter function, nothing shows up (the "Flag" does show up)
struct teacher{
int id;
string password;
string first_name;
string last_name;
};
void University::set_teachers(ifstream& inFile){
int amountOfTeachers = count_file_lines(inFile);
this->teachers = new teacher[amountOfTeachers];
for(int i = 0; i < amountOfTeachers; i++){
inFile >> teachers[i].password;
inFile >> teachers[i].first_name;
inFile >> teachers[i].last_name;
cout << "Flag" << endl;
}
}
What you're trying to accomplish is a "de-serialization" of a sequence of teacher objects.
You may be interested in:
Is it possible to serialize and deserialize a class in C++?
for some general-purpose solutions. Note those may (or may not) be a bit "heavy-weight" for what you need to achieve.
Example of using tell, don't ask:
#include <iostream>
using std::cout, std::cerr, std::endl;
#include <iomanip>
using std::setw, std::setfill;
#include <fstream>
using std::ifstream, std::istream; // std::ofstream;
#include <sstream>
using std::stringstream;
#include <string>
using std::string, std::to_string;
#include <cstdint>
#include <cassert>
// stub - this function implemented and tested elsewhere
int count_file_lines(ifstream& inFile)
{
if (!inFile.good())
cerr << "\n !infile.good()" << endl;
return 5; // for test purposes
}
struct teacher
{
private:
int id; // unique number in record order
string password;
string first_name;
string last_name;
static int ID; // init value below
// note: On my system each string is 32 bytes in this object,
// regardless of char count: the chars are in dynamic memory
public:
teacher() : id(++ID) // password, first_name, last_name
{ } // default init is empty string
~teacher() = default; // do nothing
void read(istream& inFile) // tell instance to read next record
{
inFile >> password;
inFile >> first_name;
inFile >> last_name;
}
void show()
{
cout << "\n show id:" << id
<< "\n pw :" << password
<< "\n fn :" << first_name
<< "\n ln :" << last_name
<< endl;
}
};
int teacher::ID = 0; // compute unique ID number for each record
And a demo of input and output (teacher::read(), teacher::show())
Note use of "stringstream ss;". It is filled using a for loop, and passed to each teacher object using "teacher.read()".
Then the teacher values are echo'd to output using "teacher.show()"
class F834_t
{
teacher* teachers = nullptr; // do not yet know how many
ifstream inFile; // declared, but not opened
uint amountOfTeachers = 0;
stringstream ss; // for debug / demo use
public:
// use default ctor, dtor
F834_t() = default;
~F834_t() = default;
int exec(int , char** )
{
// open infile to count lines
amountOfTeachers = static_cast<uint>(count_file_lines(inFile)); // use working func
cout << "\n teacher count: " << amountOfTeachers << "\n "; // echo
// init ss with 5 values
for (uint i=1; i<=amountOfTeachers; ++i)
ss << " pw" << i << " fn" << i << " ln" << i << " ";
cout << ss.str() << endl;
teachers = new teacher[amountOfTeachers]; // allocate space, invoke default ctor of each
assert(teachers);
cout << "\n teachers: " << setw(4) << sizeof(teachers) << " (pointer bytes)"
<< "\n a teacher: " << setw(4) << sizeof(teacher) << " (teacher bytes)"
<< "\n size of all: " << setw(4) << (amountOfTeachers * sizeof(teacher))
<< " ( " << setw(3) << sizeof(teacher) << " * " << setw(3) << amountOfTeachers << ')'
<< endl;
// reset stream to start of inFIle, maybe close/open inFile
for (uint i=0;i<amountOfTeachers; ++i)
{
assert(ss.good()); // (inFile.good());
teachers[i].read(ss); // (inFile); // tell the object to read the file
}
for (uint i=0;i<amountOfTeachers; ++i)
{
teachers[i].show(); // tell the object to show its contents
}
return 0;
}
}; // class F834_t
int main(int argc, char* argv[])
{
F834_t f834;
return f834.exec(argc, argv);
}
Output - note that a much simplified input stream is created on the fly, and is echo'd early in this output.
teacher count: 5
pw1 fn1 ln1 pw2 fn2 ln2 pw3 fn3 ln3 pw4 fn4 ln4 pw5 fn5 ln5
teachers: 8 (pointer bytes)
a teacher: 104 (teacher bytes)
size of all: 520 ( 104 * 5)
show id:1
pw :pw1
fn :fn1
ln :ln1
show id:2
pw :pw2
fn :fn2
ln :ln2
show id:3
pw :pw3
fn :fn3
ln :ln3
show id:4
pw :pw4
fn :fn4
ln :ln4
show id:5
pw :pw5
fn :fn5
ln :ln5
I am having trouble with a program that uses void functions. I have never used them before so I'm a bit lost. My program has a 3 sets of cities. It is supposed to get the three cities in one of the sets and figure out how long the flight is. My problem is that I keep getting the error that my variables are undefined. This is the first program I have tried using void functions. I have tried initializing every variable by itself but I don't think that is the correct way to do it or is it? Any help would be appreciated. Here is my code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void readFile (int wall1, double &lat1, double &lon1, string &city1,
double &lat2, double &lon2, string &city2,
double &lat3, double &lon3, string &city3);
void intro();
void askDataSet(int &w);
//--------------------------------------------------
int main()
{
intro();
askDataSet(int &w);
string name;
int lat1, lat2, lat3, , lon1, lon2, lon3, beginLat, beginLon, beginCity, midLat, midLon, midCity, endLat, endLon, endCity;
string city1, city2, city3;
readFile (beginLat, beginLon, beginCity, midLat, midLon, midCity, endLat, endLon, endCity);
cout << "The First City at coordinates " << beginLat << " and " << lon1 << " is: " << city1 << endl;
cout << "The Second City is at coordinates " << beginLat << " is " << lon2 << ": " << city2 << endl;
cout << "The Third City is at coordinates " << beginLat << " is " << lon3 << ": " << city3 << endl;
leg1 = dist( beginLat, beginLon, midLat, midLon);
leg2 = dist( midLat, midLon, endLat, endLon);
nonstop = dist( leg1-leg2 );
cout << "It is " << dist << "fewer miles for non-stop" << endl;
system("pause");
return 0;
}
void readFile (int &wall1, double &lat1, double &lon1, string &city1,
double &lat2, double &lon2, string &city2,
double &lat3, double &lon3, string &city3)
{
ifstream dataIn;
dataIn.open("cities.txt");
if(dataIn.fail())
{
cout << "Error. File does not exist. " << endl;
exit(1);
}
dataIn >> lat1;
dataIn >> lon1;
dataIn.get();
getline(dataIn, city1);
dataIn >> lat2;
dataIn >> lon2;
dataIn.get();
getline(dataIn, city2);
dataIn >> lat3;
dataIn >> lon3;
dataIn.get();
getline(dataIn, city3);
}
void intro()
{
cout << "In this lab we will try to figure out how much shorter it is to fly non-stop compared to one-stop." << endl;
cout << endl;
}
void askDataSet(int &w)
{
cout << "Which set of cities would you like to figure the distances for? " << endl;
cin >> w;
}
To give back a value from a void function via a reference-parameter, a variable has to exist in the caller's scope which is given as the parameter.
So in your case, for example to call askDataSet, you first have to declare an int to hold the result:
int w;
askDataSet(w);
Then askDataSet will write into your integer variable and you can use it after the call.
Further points I noticed with the code:
For the readFile call, the variables passed must have the same type as the parameters (double, not int).
There is an extra comma in the declarations before the readData call: "lat3, , lon1"
Maybe you'll want to replace beginLat, midLon etc. with lat1, lon2 (or the other way around).
readFile seems to have an unused first argument int wall1, which is missing in the readFile-call in main.
The dist function is not defined and at the end of main you try to print it.
To use system and exit, you should #include <cstdlib>.