Question
Reading Data From a File and Formatting Output in C++ file is composed of bunch of neighborhoods. a neighborhoob starts with a ; and finishes
Reading Data From a File and Formatting Output in C++
file is composed of bunch of neighborhoods.
a neighborhoob starts with a ; and finishes with a ;
Each neighborhood is composed of a number of households
Each household has an ID (first int) a revenue (int) and number of members (int) separated by spaces
the main goal is to compute the revenue average of each neighborhood. I need help to read the inpu properly si I can create objects out of them and then store in a dynamic array of neighborhood
File to read from : data.txt
Neighborhood1
;
1041 12180 4
1062 13240 3
6217 10000 2
9280 6200 1
;
Neighborhood2
;
1227 24180 6
1060 70240 1
;
household.h
#if !defined(__FOYER_H__) #define __FOYER_H__ #include
class Household{ public: Household(); Household(int id, int revenue, int nbrMembre); // getters int getId(); int getRevenue(); int getNbrMembre(); // setters void setId(int _id); void setRevenue(int _revenue); void setMembre(int _nbrMembre); private: int id; int revenue; int nbrMembre;
friend std::ostream& operator << (std::ostream&, const Household&); friend std::istream& operator >> (std::istream&, Household&); };
#endif
neighborhood.h
#if !defined(__NEIGHBORHOOD_H__) #define __NEIGHBORHOOD_H__ #include #include #include #include "household.h" #include "tableau.h"
using namespace std;
class Quartier{ public: Neighborhood(); Neighborhood(std::string nom, Tableau _listFoyer); Household f;
private: Tableau listFoyer; std::string nom;
friend std::ostream& operator << (std::ostream&, const Neighberhood&); friend std::istream& operator >> (std::istream&, Neighborhood&);
}; #endif
tableau.h
#if !defined(__TABLEAU_H__) #define __TABLEAU_H__
template
void add(const T& element); // la fin //void inserer_fin(const T& element){ajouter(element);} bool empty() const {return nbElements==0;} void toEmpty(); int size() const {return nbElements;}
void insert(const T& element, int index=0); void remove(int index=0); void remove_last(); int find(const T& element) const; bool contain(const T& element) const;
T& operator[] (int index); const T& operator[] (int index) const;
Tableau
bool operator == (const Tableau
private: T* elements; int cap; int nbElements;
};
#include
template
template
template
template
template
template
template
template
template
template
template
template
template
nbElements = other.nbElements; if(capacite
template
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started