Hi I am trying to write program that a program that allows the user to transfer an amount from an account (the account being text file "shop" which simply contains the value 100).
I want to have it so that the user can make as many transfers as they want, without overdrawing the account. The file also needs to be updated after each transaction. Can anyone help me with where I'm going wrong?
int read_balance(void);
void write_balance(int balance);
#include <limits>
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR * argv[])
{
std::cout << "You have choosen to transfer an amount" << std::endl;
std::cout << "How much do you wish to transfer from the shop account?" << std::endl;
int amount = 0;
if (std::cin >> amount)
{
std::cout << "DEBUG: amount:" << amount << "\n";
int balance = read_balance();
if (amount <= 0)
{
std::cout << "Amount must be positive\n";
}
else if (balance < amount)
{
std::cout << "Insufficient funds\n";
}
else
{
int new_balance = balance - amount;
write_balance(new_balance);
std::cout << "New account balance: " << new_balance << std::endl;
}
}
system("pause");
return 0;
}
int read_balance(void)
{
std::ifstream f;
f.exceptions(std::ios::failbit | std::ios::badbit);
f.open("shop.txt");
int balance;
f >> balance;
f.close();
return balance;
}
void write_balance(int balance)
{
std::ofstream f;
f.exceptions(std::ios::failbit | std::ios::badbit);
f.open("shop.txt");
f << balance;
f.close();
}
As the compiler warns you when using precompiled headers for stdafx.h the #include "stdafx.h" must be the first line of code. So it's better to start with
#include "stdafx.h"
#include <limits>
#include <iostream>
#include <fstream>
using namespace std;
int read_balance(void);
void write_balance(int balance);
Related
I have created a program and I want to create with it files like aff1.txt, aff2.txt, etc. In these files, I want to have here a text created this way: It will open the file: text.txt and it will take each sentence, copy it 4700/sentence length times to each file. But it isn't working, when: cout << ss << endl;, it writes to cmd nothing, while there should be something, which was assigned before. What should I do?
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <string.h>
#include <sstream>
using namespace std;
int main()
{
ifstream vstup("text.txt"); // 4700,2700,2200,1700
string vety;
getline(vstup,vety);
vstup.close();
string ss="affn.txt";
char q[vety.length()];
for (int u=0;u<vety.length();u++)
{
q[u] = vety[u];
}
int l=0,m=0,n=0;
int v,i,e,o;
char vl[999999];
//cout << vety.length() << endl;
for (i=0;i<vety.length();i++)
{
//cout << "ss" << endl;
if (q[i]=='.')
{
// cout << "ss" << endl;
v=4700/i;
for (e=0;e<v;e++)
{
//cout << "ss" << endl;
for (o=0;o<i-l;o++)
{
// cout << "ss" << endl;
m=o+e*(i-l);
vl[m]=q[o+l];
}
}
l=l+i;
cout << vl << endl;
n++;
//ofstream aff("aff.txt");
//aff << vl << endl;
//aff.close();
ss[3]=n;
ofstream writer(ss.c_str());
//writer.open(ss.c_str());
writer << vl << endl;
writer.close();
cout << ss << endl;
ss.clear();
}
}
return 0;
}
I'm making a surface to let the user to input information and print it out.
And this is what it looks like.
main <- menu <- Reservation
<- BookingManager <- BookingRecord
And I create a vector vector<string> CompanyName in Reservation,
This is outputdataInfo() that add CompanyName,
void Reservation::outputdataInfo()
{
string CompName;
cout << "Company Name <-" << endl;
cin >> CompName;
Reservation::setCompanyName(string (CompName) );
cout << CompanyName.at(0) << endl;
// Use for test and it works
cout << CompanyName.size() << endl;
// Use for test and it works
cout << "End of Reservation, thank you." << endl;
}
The setter of CompanyName:(worked)
void Reservation::setCompanyName(const string& cn)
{this->CompanyName.push_back(cn);}
But now BookingRecord::outputdataInfo() wants to print Booking Record.
void BookingRecord::outputdataInfo()
{
cout << " ----- Booking Record -----" << endl;
Reservation::printBookingRecord();
}
And I wrote like this(unconfirm this is correct or not):
void Reservation::printBookingRecord() {
for (int i = 0; i < CompanyName.size(); i++) {
cout << " ---- Company ---- " << endl;
cout << "Name: " << CompanyName.at(i) << endl;
}
}
But CompanyName suddenly looks like it forget anything, or like reset the size.
The result is BookingRecord::outputdataInfo() is printing infinitly non-stop, but nothing happen to the Reservation::printBookingRecord(). This is weird beacuse there suppose no for-loop in BookingRecord::outputdataInfo().
And I wanna know how to print data with (Reservation::printBookingRecord() is called by BookingRecord::outputdataInfo(), but the vector is at "Reservation")
(or vector can be use in other classes)
Big thanks :)
Source Code (kinda bit long sry)
//
// main.cpp
//
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include "Menu.h"
#include "Reservation.h"
#include "BookingManager.h"
using namespace std;
int main(int argc, const char* argv[]) {
Menu m;
Reservation R;
BookingManager BM;
char choice;
do {
choice = m.menu();
switch (choice)
{
case 'R': case 'r':
R.outputdataInfo();
break;
case 'B': case 'b':
BM.outputdataInfo();
break;
default:
cout << "Invalid Alphabet. Please try again." << endl;
break;
}
} while (choice == 'R' || choice == 'r' || choice == 'B' || choice == 'b');
return 0;
}
//.....................
// Menu.h
//
#include <iostream>
#ifndef Menu_h
#define Menu_h
class Menu {
public: //Accessibility as public
char option;
char menu();
};
#endif
//.....................
// Menu.cpp
//
#include <iostream>
#include "Menu.h"
using namespace std;
char Menu::menu() {
cout << "" << endl;
cout << " BNC Exhibition Tour in European Cities" << endl;
cout << " Exhibition Recruitment " << endl;
cout << " " << endl;
cout << "Please type:" << endl;
cout << "R -> for Reservation Page" << endl;
cout << "B -> for Booking Manager Page" << endl;
cout << "And Press ENTER." << endl;
cin >> option;
cout << "" << endl;
return option;
}
//.............................
// Reservation.h
//
#include <iostream>
#include <vector>
using namespace std;
#ifndef Reservation_h
#define Reservation_h
class Reservation {
private:
vector<string> CompanyName;
public: //Accessibility as public
void outputdataInfo();
void setCompanyName(const string& cn);
Reservation();
~Reservation();
void printBookingRecord();
};
#endif
//.....................................
// Reservation.cpp
//
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <vector>
using namespace std;
#include "Reservation.h"
void Reservation::outputdataInfo()
{
cout << "Please input detail information first :" << endl;
string CompName;
cout << "Company Name <-" << endl;
cin >> CompName;
Reservation::setCompanyName(string (CompName) );
cout << CompanyName.at(0) << endl; //it works
cout << CompanyName.size() << endl; //it works
cout << "End of Reservation, thank you." << endl;
}
//////////////////////// S E T T E R ////////////////////
void Reservation::setCompanyName(const string& cn)
{
this->CompanyName.push_back(cn);
}
//////////////////////// S E T T E R ////////////////////
Reservation::Reservation() {}
Reservation::~Reservation() {}
/////////////////////// P R I N T ///////////////////////
void Reservation::printBookingRecord() {
for (int i = 0; i < CompanyName.size(); i++) {
cout << " ---- Company ---- " << endl;
cout << "Name: " << CompanyName.at(i) << endl;
}
}
//.............................
// BookingManager.h
//
#include <iostream>
#include <vector>
#ifndef BookingManager_h
#define BookingManager_h
class BookingManager {
public: //Accessibility as public
char option;
void outputdataInfo();
};
//..........................................
// BookingManager.cpp
//
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <vector>
#include "BookingManager.h"
#include "BookingRecord.h"
using namespace std;
void BookingManager::outputdataInfo() {
BookingRecord BR;
cout << "" << endl;
cout << " ----- Booking Manager -----" << endl;
cout << "" << endl;
cout << "Please type:" << endl;
cout << "B -> for Booking Record" << endl;
cout << "And Press ENTER." << endl;
cin >> option;
cout << "" << endl;
do {
switch (option)
{
case 'B': case 'b':
BR.outputdataInfo();
break;
default:
cout << "Invalid Alphabet. Please try again." << endl;
break;
}
} while (option == 'B' || option == 'b');
}
#endif
//...........................................
// BookingRecord.h
//
#include <iostream>
#include <vector>
#include "Reservation.h"
#ifndef BookingRecord_h
#define BookingRecord_h
class BookingRecord : public Reservation {
public: //Accessibility as public
void outputdataInfo();
};
#endif
//..........................................
// BookingRecord.cpp
//
#include <iostream>
#include <string>
#include <vector>
#include "Reservation.h"
#include "BookingRecord.h"
void BookingRecord::outputdataInfo()
{
cout << "" << endl;
cout << " ----- Booking Record -----" << endl;
cout << "" << endl;
cout << " Print all the information..." << endl;
Reservation::printBookingRecord();
}
// END
So you have two CompanyNames in your code.
One is here, part of the R variable.
int main(int argc, const char* argv[]) {
Menu m;
Reservation R;
And the other is here
void BookingManager::outputdataInfo() {
BookingRecord BR;
BookingRecord derives from Reservation, so it also contains a CompanyName.
I think it's pretty clear that you are adding a name to the CompanyName in R in main but printing out the CompanyName in BR in BookingManager::outputdataInfo.
The class design looks wrong to me.For instance there's a lack of parameters to your methods. Surely BookingManager::outputdataInfo should take a BookingRecord as a parameter to allow the caller to specify which BookingRecord they want to output. Just declaring a BookingRecord as a local variable in BookingManager::outputdataInfo doesn't make any sense.
Before you rush to write a lot of code, try and think about the design of your classes. How the different classes should relate to each other, what member variables they need, what methods they need, what parameters and return types those methods need. Think about this in terms of how your classes model the real world, not in terms of how you are going to implement functionality. That comes later, get the design right first.
Here is the code:
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
string sidelength;
cout << "Perimeter of Square" << endl;
cout << "Enter length of one side: ";
getline(cin, sidelength);
cout << sidelength * 4 << endl;
return 0;
}
When run, this is the error message:
error: no match for 'operator*' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'int')|
How do I fix this error and make the program run correctly?
The get line function takes a string as it's second parameter, but you want to get an integer/double/float as an input. So don't use getline. Simply run this code below and it will solve your problem.
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int sidelength;
cout << "Perimeter of Square" << endl;
cout << "Enter length of one side: ";
cin >> sidelength;
cout << sidelength * 4 << endl;
return 0;
}
If you really want to multiply a string by a number, you can overload operator*:
#include <cmath>
#include <iostream>
#include <cctype>
#include <string>
std::string operator*(const std::string &s,int x) {
std::string result;
try {
result = std::to_string(stoi(s)*x);
} catch(const std::invalid_argument&) {
result="UND";
}
return result;
}
std::string operator*(const std::string &s,double x) {
std::string result;
try {
result = std::to_string(stof(s)*x);
} catch(const std::invalid_argument&) {
result="UND";
}
return result;
}
int main()
{
std::string input("1");
input = input * 5.32;
std::cout << input << std::endl;
input = input * 2;
std::cout << input << std::endl;
return 0;
}
When I compile the below code, for some reason, the student/instructors name, age, and GPA/Rating, are not returned via their respective printPerson functions.
With the name variable, nothing is printed to the console.
With the age, GPA/Rating, console prints out a negative 8 digit number, and a negative float.
What am I not seeing?
Person.h
#pragma once
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <vector>
#include <string>
using std::string;
// Base class
class Person {
protected:
string name;
int age;
public:
void setName(string name);
void setAge(int age);
virtual void do_work(int number) {};
virtual void printPerson() {};
};
#endif;
Person.cpp
#include "Person.h"
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::cin;
using std::endl;
void Person::setName(string name) {
name = name;
}
void Person::setAge(int age) {
age = age;
}
Student.h
#pragma once
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
using std::string;
class Student : public Person {
private:
float gpa;
public:
void setGPA(float gpa);
float getGPA();
void do_work(int number);
void printPerson();
};
#endif;
Student.cpp
#include "Student.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Student::setGPA(float gpa) {
gpa = gpa;
}
float Student::getGPA() {
return gpa;
}
void Student::do_work(int number) {
//cout << name << ".. " << number << "hours of homework.” << endl;
cout << name;
}
void Student::printPerson() {
cout << "Name : " << name << "Age :" << age << " GPA : " << getGPA() << endl;
}
Instructor.h
#pragma once
#ifndef INSTRUCTOR_H
#define INSTRUCTOR_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
class Instructor : public Person {
private:
float rating;
public:
void setRating(float rating);
float getRating();
void do_work(int number);
void printPerson();
};
#endif;
Instructor.cpp
#include "Instructor.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Instructor::setRating(float rating) {
rating = rating;
}
float Instructor::getRating() {
return rating;
}
void Instructor::do_work(int number) {
cout << name << "graded papers for" << number << "hours." << endl;
}
void Instructor::printPerson() {
cout << " Name : " << name << " Age : " << age << " Rating : " << getRating() << endl;
}
University.h
#pragma once
#ifndef UNIVERSITY_H
#define UNIVERSITY_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
#include "Building.h"
#include "Student.h"
using std::cout;
using std::string;
using std::vector;
class University {
public:
string name;
vector<Person*> persons;
vector<Building> buildings;
public:
void printAllBuildings();
void printAllPersonsRecord();
};
#endif;
University.cpp
#include "University.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void University::printAllBuildings() {
cout << " Building Details : " << endl;
for (int j = 0; j < buildings.size(); j++) {
buildings[j].printBuilding();
}
}
void University::printAllPersonsRecord() {
cout << " Persons Details : " << endl;
for (int i = 0; i < persons.size(); i++) {
persons[i]->printPerson();
}
}
Building.h
#pragma once
#ifndef BUILDING_H
#define BUILDING_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
class Building {
public:
string name;
int size;
string address;
public:
void printBuilding();
};
#endif;
Building.cpp
#include "Building.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Building::printBuilding() {
cout << " Name : " << name << " Address : " << address << endl;
}
main.cpp
#include "University.h"
#include "Person.h"
#include "Student.h"
#include "Instructor.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main() {
Student student;
Instructor instructor;
student.setName("deepak");
student.setAge(12);
student.setGPA(12.0);
instructor.setName("rajdev");
instructor.setAge(23);
instructor.setRating(5.0);
Building building;
building.name = "block1";
building.size = 2000;
building.address = "noida sector-2";
Building building2;
building2.name = "block2";
building2.size = 4000;
building2.address = "noida sector-2";
University university;
university.name = "Oregon State University";
university.persons.emplace_back(&student);
university.persons.emplace_back(&instructor);
university.buildings.push_back(building);
university.buildings.push_back(building2);
university.printAllBuildings();
university.printAllPersonsRecord();
int choice;
bool isValidMainChoice = false;
while (!isValidMainChoice) {
cout << "Kindly choose one of the option from follwoing list of operations or Menu" << endl;
cout << "1 : Prints names of all the buildings" << endl;
cout << "2 : Prints names of everybody at the university" << endl;
cout << "3 : Choose a person to do work" << endl;
cout << "4 : Exit the program" << endl;
cin >> choice;
cout << "The value you entered is " << choice << endl;
if (choice == 1) {
university.printAllBuildings();
}
else if (choice == 2) {
university.printAllPersonsRecord();
}
else if (choice == 3) {
int personChoice;
bool isInputValid = false;
while (!isInputValid) {
cout << "Kindly choose the one of the following option to provide person's details." << endl;
cout << "5 : Student" << endl;
cout << "6 : Instructor" << endl;
cin >> personChoice;
if (personChoice == 5) {
isInputValid = true;
string studentName;
bool isValidName = false;
while (!isValidName) {
cout << " Kindly enter Name of the student :" << endl;
cin >> studentName;
if (studentName.length() == 0) {
cout << " Name must not be blank. Kindly re-enter the student's name." << endl;
}
else {
isValidName = true;
}
}
int age1 = 0;
bool isValidAge1 = false;
while (!isValidAge1) {
cout << " Kindly enter age of the student :" << endl;
cin >> age1;
if (age1 < 0 || age1 > 100) {
cout << " Age must be geter than 0 or lessa then 100. Kindly re-enter the student's age." << endl;
}
else {
isValidAge1 = true;
}
}
float gpa;
bool isValidGPA = false;
while (!isValidGPA) {
cout << " Kindly enter GPA of the student :" << endl;
cin >> gpa;
if (gpa < 0.0 || gpa > 4.0) {
cout << " GPA must be geter than 0.0 or less then 4.0. Kindly re-enter the Student GPA." << endl;
isValidGPA = false;
}
else {
isValidGPA = true;
}
}
Student student;
student.setName(studentName);
student.setAge(age1);
student.setGPA(gpa);
university.persons.emplace_back(&student);
university.printAllPersonsRecord();
}
else if (personChoice == 6) {
isInputValid = true;
string instructorName;
bool isValidName = false;
while (!isValidName) {
cout << " Kindly enter Name of the instructor :" << endl;
cin >> instructorName;
if (instructorName.length() == 0) {
cout << " Name must not be blank. Kindly re-enter the instructor's name." << endl;
}
else {
isValidName = true;
}
}
float rating;
bool isValidRating = false;
while (!isValidRating) {
cout << " Kindly enter rating of the instructor :" << endl;
cin >> rating;
if (rating < 0.0 || rating > 5.5) {
cout << " rating must be geter than 0.0 or less then 5.5. Kindly re-enter the instructor rating." << endl;
isValidRating = false;
}
else {
isValidRating = true;
}
}
int age2 = 0;
bool isValidAge2 = false;
while (!isValidAge2) {
cout << " Kindly enter age of the instructor :" << endl;
cin >> age2;
if (age2 < 0 || age2 > 100) {
cout << " Age must be geter than 0 or lessa then 100. Kindly re-enter the instructor's age." << endl;
}
else {
isValidAge2 = true;
}
}
Instructor instructor;
instructor.setName(instructorName);
instructor.setAge(age2);
instructor.setRating(rating);
university.persons.emplace_back(&instructor);
}
else {
cout << "The value you entered is incorrct.Please r-enter the values." << endl;
}
}
}
else if (choice == 4) {
isValidMainChoice = true;
cout << " You are exits from system. Thanks You !!" << endl;
}
}
return 0;
};
Please modify all your code for setter
void Person::setName(string name) {
//before-edit: name = name;
this->name = name; //OR Person::name = name;
}
As the local string name parameter and your class variable are the same, you expect the parameter are passed correctly, but it doesn't.
im currently working on a small console app, i read from some files, and i have made a simple animated loading bar thread to show the progress of file reading (sometimes the file are really huge)
i have read on the microsoft documentation and on the forum and that error seems to suggest that i defined the class multiple time.
but i did include all the header blocks to prevent this from happenning, any of you see my mistake, probly obvious, i havent done c++ in years.
here is the code
fileReader.h
#pragma once
#ifndef FILEREADER_H // must be unique name in the project
#define FILEREADER_H
#include <vector>
using namespace std;
class fileReader {
private:
public:
vector<string> readTextFile(string path);
unsigned int getSize();
unsigned int getLoadedBytes();
};
#endif // FILEREADER_H
#pragma once
fileReader.cpp
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <thread>
#include "numbers.h"
#include "loadingBar.h"
using namespace std;
class fileReader {
private:
public :
vector<string> list;
int i;
unsigned int size;
unsigned int loadedBytes;
string line;
std::thread* barThread;
vector<string> fileReader::readTextFile(string path) {
ifstream file(path.c_str(), ios::in | ios::binary | ios::ate);
i = 0;
size = 0;
loadedBytes = 0;
ifstream file(path.c_str(), ios::in | ios::binary | ios::ate);
if (file.is_open()) {
size = file.tellg();
cout << "\t" << path << " (" << formatNumbers(size) << " bytes)" << endl;
file.clear();
file.seekg(0, ios::beg);
barThread = new std::thread(&loadingBar::run, *this);
while (file >> line) {
list.push_back(line);
loadedBytes += strlen(line.c_str());
i++;
}
}
else {
cout << "Error reading : \"" << path << "\"" << endl;
exit(EXIT_FAILURE);
}
file.close();
return list;
}
unsigned int fileReader::getSize() { return size; }
unsigned int fileReader::getLoadedBytes() { return loadedBytes; }
};
loadingBar.h
#pragma once
#ifndef LOADINGBAR_H
#define LOADINGBAR_H
#include<stdlib.h>
#include<string>
#include<iomanip>
#include "numbers.h"
#include "fileReader.h"
using namespace std;
class loadingBar {
public:
void notififyFinish();
void notifyError();
void notifiError(string);
void drawloadingBar();
void drawPathBar();
void drawBytesBar();
void setLoadedUnits(int);
void setTotalUnits(int);
void run(fileReader*);
};
#endif // NUMBERS_H
loadingBar.cpp
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <iomanip>
#include "numbers.h"
#include "fileReader.h"
using namespace std;
class loadingBar {
private:
public:
double totalUnits = 1;
double loadedUnits = 0;
char loadedChar = '/';
char emptyChar = ' ';
int barLength = 50;
double percent;
int nbChar;
void notiftyFinish() {
cout << " Ok" << endl;
//exit(EXIT_SUCCESS);
}
void notifiyError() {
cout << " Error !" << endl;
//exit(EXIT_FAILURE);
}
void notifiyError(string errMess) {
cout << " Error !" << endl << "\t" << errMess;
//exit(EXIT_FAILURE);
}
void drawLoadingBar() {
cout << fixed;
cout << "\rLoading [";
for (int i = 0; i < nbChar; i++)
cout << loadedChar;
for (int i = nbChar; i < barLength - 1; i++)
cout << emptyChar;
cout << "] " << setprecision(0) << percent << "%";
}
void drawPathBar(string path) {
cout << fixed;
cout << "\rLoading [ ";
cout << path;
cout << " ] " << setprecision(0) << percent << "%";
}
void drawBytesBar() {
cout << fixed;
cout << "\rLoading [ ";
cout << formatNumbers(loadedUnits) << " / " << formatNumbers(totalUnits);
cout << " ] " << setprecision(0) << percent << "%";
}
void setLoadedUnits(int newValue) {
if (newValue > 0)
loadedUnits = newValue;
}
void setTotalUnits(int value) {
if (value > 0)
totalUnits = value;
}
void run(fileReader *f) {
setTotalUnits(f->getSize());
setLoadedUnits(f->getLoadedBytes());
while (loadedUnits <= totalUnits) {
setLoadedUnits(f->getLoadedBytes());
percent = ((double)(loadedUnits / totalUnits) * 100);
nbChar = (int)(percent / (int)(100 / barLength));
drawLoadingBar();
//setLoadedUnits((int)loadedUnits + 10);
if (loadedUnits >= totalUnits) notiftyFinish();
}
}
};
Your .cpp files redefine your classes. You've already defined them in the respective .h files. All you need to include in your .cpp files is the implementations. They should look more like this:
fileReader.cpp
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <thread>
#include "numbers.h"
#include "loadingBar.h"
vector<string> fileReader::readTextFile(string path) {
ifstream file(path.c_str(), ios::in | ios::binary | ios::ate);
i = 0;
size = 0;
loadedBytes = 0;
ifstream file(path.c_str(), ios::in | ios::binary | ios::ate);
if (file.is_open()) {
size = file.tellg();
cout << "\t" << path << " (" << formatNumbers(size) << " bytes)" << endl;
file.clear();
file.seekg(0, ios::beg);
barThread = new std::thread(&loadingBar::run, *this);
while (file >> line) {
list.push_back(line);
loadedBytes += strlen(line.c_str());
i++;
}
}
else {
cout << "Error reading : \"" << path << "\"" << endl;
exit(EXIT_FAILURE);
}
file.close();
return list;
}
unsigned int fileReader::getSize() { return size; }
unsigned int fileReader::getLoadedBytes() { return loadedBytes; }
Similarly for loadingBar.cpp.