#include
#include"Data.h"
#include"Person.h"
#include"Report.h"
#include
#include
#include "Menu.h"
using namespace std;
/*
Programmers: Javier A. Molina, Eduardo Bonnet
Students #:79249
*/
int main()
{
int cnt;
int idx;
string fileName;
Report * telefonia;
Menu menu("Reports");
bool fileNameExists(string fileName);
Report * addReport(Report * reports, int & totalReports);
Report * delReport(Report * reports, int & totalReports, int idx);
int displayReports(Report * reports, int totalReports);
menu.addItem("New report");
menu.addItem("Delete a report");
menu.addItem("Display a report");
cnt = 0;
telefonia = NULL;
do {
cout << menu;
cin >> menu;
//cls();
switch (menu.getOption()) {
case 1:
cout << "Enter report name (TE?????): ";
cin >> fileName;
if (fileNameExists(fileName + ".tel")) {
telefonia = addReport(telefonia, cnt);
idx = cnt - 1;
telefonia[idx].setFileName(fileName);
// telefonia[idx].loadReport();
}
else {
cls();
cerr << "Error: Report name '" << fileName << "' does not exists!   ";
//pause();
}
break;
case 2:
if (telefonia != NULL) {
do {
cls();
cout << "Delete a Report:  ";
idx = displayReports(telefonia, cnt);
if (between(idx, 0, cnt - 1)) {
cls();
telefonia = delReport(telefonia, cnt, idx);
idx = 0;
// pause();
}
} while (idx != cnt);
}
else {
cerr << "No reports available for deleting!   ";
//pause();
}
break;
case 3:
char ans;
if (telefonia != NULL) {
do {
// cls();
cout << "Display/Filed a Report:  ";
idx = displayReports(telefonia, cnt);
if (between(idx, 0, cnt - 1)) {
// cls();
cout << "Would you like the report to be display otherwise save into a file? ";
cin >> ans;
cls();
cin.ignore();
if (upper(ans) == 'Y') {
cout << telefonia[idx] << endl;
}
else {
//telefonia[idx].saveReport();
cout << "Report '" << telefonia[idx].getFileName() << "' saved as '" <<
telefonia[idx].getFileName() << ".rep'.  ";
}
//pause();
}
} while (idx != cnt);
}
else {
cerr << "No reports available for displaying!   ";
// pause();
}
break;
case 4:
cout << "Thanks for using Telefonia Reports System!!!   ";
break;
}
} while (menu.getLast() != menu.getOption());
delete[] telefonia;
return 0;
}
//Funcion que verifica si existe un archivo en disco
bool fileNameExists(string fileName) {
ifstream fin(fileName.c_str());
bool exists = !(fin.fail());
if (exists) fin.close();
return(exists);
}
//Anade dinamicamente objetos tipo Report al arreglo reports
Report * addReport(Report * reports, int & totalReports) {
if (totalReports == 0) {
reports = new Report[1];
}
else {
Report * tmp = new Report[totalReports];
for (int i = 0; i < totalReports; ++i) {
tmp[i] = reports[i];
}
delete[] reports;
reports = new Report[totalReports + 1];
for (int i = 0; i < totalReports; ++i) {
reports[i] = tmp[i];
}
delete[] tmp;
}
totalReports++;
return(reports);
}
//Borra objetos del arreglo reports segun el idx enviado
Report * delReport(Report * reports, int & totalReports, int idx) {
Report * tmp = new Report[totalReports - 1];
string fileName = reports[idx].getFileName();
for (int i = 0, j = 0; i < totalReports; ++i) {
if (i == idx) continue;
tmp[j] = reports[i];
j++;
}
delete[] reports;
totalReports--;
reports = new Report[totalReports];
for (int i = 0; i < totalReports; ++i) {
reports[i] = tmp[i];
}
delete[] tmp;
cout << "Report '" << fileName << "' has been deleted! " << endl;
if (totalReports == 0) reports = NULL;
return(reports);
}
//Muestra en pantalla la lista de informes que se encuantran en memoria
int displayReports(Report * reports, int totalReports) {
int choice;
int i;
for (i = 0; i < totalReports; ++i) {
cout << "t" << (i + 1) << ".) " << reports[i].getFileName() << endl;
}
cout << "t" << (i + 1) << ".) Return ";
cout << " tChoice: ";
cin >> choice;
return (choice - 1);
}
Data.h
#include
#include
#include
#ifndef DATA_H
#define DATA_H
#include "Person.h"
using namespace std;
#pragma once
//Trata de establecer coneccion entre la clase data y person, utilizando informacion de la clase
person busca informacion de las llamadas hechas por el cliente
//Person(client) con esto saca la informacion de los datos escritos en la clase
class Data
{
private:
Person client;//atributo de la clase person
string callDate;//atributos esenciales de la clase Data
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
public:
Data();//default
Data(Person client, string callDate, bool longDistance, string timeCallBegin, string
timeCallEnd, string callNoFrom, string callNoTo);//parameter constructor
Data(const Data & unData);//copy constructor
~Data();//destructor
void setClient(const Person & client);//setters
void setCallDate(string callDate);
void setLongDistance(bool longDistance);
void setTimeCallBegin(string timeCallBegin);
void setTimeCallEnd(string timeCallEnd);
void setCallNoFrom(string callNoFrom);
void setCallNoTo(string callNoTo);
Person getClient()const;//getters
string getCallDate()const;
bool getLongDistance()const;
string getTimeCallBegin()const;
string getTimeCallEnd()const;
string getCallNoFrom()const;
string getCallNoTo()const;
Data & operator = (const Data & unData);//operador de asignar
bool operator ==(const Data & unData)const;//operador de igualdad
friend ostream & operator <<(ostream & output, const Data & unData);//friend operador,
imprime valores
friend istream & operator >>(istream & input, Data & unData);//friend operator, manipula los
valores de los atributos
};
#endif // DATA_H
Data.cpp
#include "Data.h"
using namespace std;
Data::Data()//default
{
setClient(Person(" "," "," "," "));
setCallDate(" ");//valores asignados por default
setLongDistance(false);
setTimeCallBegin(" ");
setTimeCallEnd(" ");
setCallNoFrom(" ");
setCallNoTo(" ");
}
Data::Data (Person client, string callDate, bool longDistance, string timeCallBegin, string
timeCallEnd, string callNoFrom, string callNoTo)//parameter constructor
{
setClient(client);
setCallDate(callDate);
setLongDistance(longDistance);
setTimeCallBegin(timeCallBegin);
setTimeCallEnd(timeCallEnd);
setCallNoFrom(callNoFrom);
setCallNoTo(callNoTo);
}
Data::Data(const Data & unData)//copy constructor
{
this->client = unData.client;
this->callDate = unData.callDate;
this->longDistance = unData.longDistance;
this->timeCallBegin = unData.timeCallBegin;
this->timeCallEnd = unData.timeCallEnd;
this->callNoFrom = unData.callNoFrom;
this->callNoTo = unData.callNoTo;
}
Data::~Data()//destructor
{
}
void Data::setClient(const Person & client)//setters
{
this->client = client;
}
void Data::setCallDate(string callDate)
{
this->callDate = callDate;
}
void Data::setLongDistance(bool longDistance)
{
if (longDistance == 1)//verificacion del valor para clasificar en true or false
{
longDistance = true;
this->longDistance = longDistance;
}
else
{
longDistance = false;
this->longDistance = longDistance;
}
}
void Data::setTimeCallBegin(string timeCallBegin)
{
this->timeCallBegin = timeCallBegin;
}
void Data::setTimeCallEnd(string timeCallEnd)
{
this->timeCallEnd = timeCallEnd;
}
void Data::setCallNoFrom(string callNoFrom)
{
this->callNoFrom = callNoFrom;
}
void Data::setCallNoTo(string callNoTo)
{
this->callNoTo = callNoTo;
}
Person Data::getClient()const//getters
{
return (this->client);
}
string Data::getCallDate()const
{
return (this->callDate);
}
bool Data::getLongDistance()const
{
return(this->longDistance);
}
string Data::getTimeCallBegin()const
{
return (this->timeCallBegin);
}
string Data::getTimeCallEnd()const
{
return (this->timeCallEnd);
}
string Data::getCallNoFrom()const
{
return (this->callNoFrom);
}
string Data::getCallNoTo()const
{
return(this->callNoTo);
}
Data & Data :: operator =(const Data & unData)//asigna los valores
{
this->client = unData.client;
this->callDate = unData.callDate;
this->longDistance = unData.longDistance;
this->timeCallBegin = unData.timeCallBegin;
this->timeCallEnd = unData.timeCallEnd;
this->callNoFrom = unData.callNoFrom;
this->callNoTo = unData.callNoTo;
return (*this);
}
bool Data :: operator ==(const Data & unData)const//verificacion de igualdad de todos los
valores
{
return (this->client == unData.client && this->callDate == unData.callDate && this-
>longDistance == unData.longDistance &&
this->timeCallBegin == unData.timeCallBegin && this->timeCallEnd ==
unData.timeCallEnd && this->callNoFrom == unData.callNoFrom &&
this->callNoTo == unData.callNoTo);
}
ostream & operator <<(ostream & output, const Data & unData)//imprime valores
{
Person person;
output << "Providing Client Information:" << endl;
output << person.getFirstName();
output << person.getLastName();
output << person.getMiddleName();
output << person.getMaidenName();
output << endl << "Call Date: " << unData.callDate << endl;
output << "longDistance Charge: " << unData.longDistance ? " Y " : " N ";//Yes or No
question
output << "Time Call Begin: " << unData.timeCallBegin;
output << "Time Call End: " << unData.timeCallEnd;
output << "Call # From: " << unData.callNoFrom;
output << "Call # to: " << unData.callNoTo;
return output;
}
istream & operator >>(istream & input, Data & unData)//pide valores
{
cout << "Client Information: " << endl;
input >> unData.client;
cout << "Call Date: " << endl;
input >> unData.callDate;
cout << " Long Distance: " << endl;
input >> unData.longDistance;
cout << " Time Call Begin: " << endl;
input >> unData.timeCallBegin;
cout << " Time Call End: " << endl;
input >> unData.timeCallEnd;
cout << " Call # From : " << endl;
input >> unData.callNoFrom;
cout << " Call # To: " << endl;
input >> unData.callNoTo;
return input;
}
Person.h
#pragma once
#include
#include
using namespace std;
class Person
{
private:
string firstName;
string lastName;
string middleName;
string maidenName;
public:
Person();
Person(string firstName, string lastName, string middleName, string maidenName);
Person(const Person & unPerson);//copy constructor
~Person();//destructor
void setFirstName(string firsName);//setters
void setLastName(string lastName);
void setMiddleName(string middleName);
void setMaidenName(string maidenName);
string getFirstName()const;//getters
string getLastName()const;
string getMiddleName()const;
string getMaidenName()const;
Person & operator = (const Person & unPerson);//operador de asignar valores
bool operator ==(const Person & unPerson)const;//operador de igualdad
friend ostream & operator <<(ostream & output, const Person & unPerson);//friend operador
que imprime
friend istream & operator >>(istream & input, Person & unPerson);//friend operador que pide
cambia valores
};
Person.cpp
#include "Person.h"
using namespace std;
Person::Person()//default cnstructor
{
firstName = (" ");//valores por default
lastName =(" ");
middleName =(" ");
maidenName = (" ");
}
Person::Person(string firstName, string lastName, string middleName, string
maidenName)//parameter
{
setFirstName(firstName);//nombrando las variables
setLastName(lastName);
setMiddleName(middleName);
setMaidenName(maidenName);
}
Person::Person(const Person & unPerson)//copy
{
firstName = unPerson.firstName;//asignando variables
lastName = unPerson.lastName;
middleName = unPerson.middleName;
maidenName = unPerson.maidenName;
}
Person::~Person()//destructor
{
}
void Person::setFirstName(string firstName)//setters
{
this->firstName = firstName;
}
void Person::setLastName(string lastName)
{
this->lastName = lastName;
}
void Person::setMiddleName(string middleName)
{
this->middleName = middleName;
}
void Person::setMaidenName(string maidenName)
{
this->maidenName = maidenName;
}
string Person::getFirstName()const//getters
{
return (this->firstName);
}
string Person::getLastName()const
{
return (this->lastName);
}
string Person::getMiddleName()const
{
return (this->middleName);
}
string Person::getMaidenName()const
{
return (this->maidenName);
}
Person & Person:: operator =(const Person & unPerson)//operador que asigna valores
{
this->firstName = unPerson.firstName;
this->lastName = unPerson.lastName;
this->middleName = unPerson.middleName;
this->maidenName = unPerson.maidenName;
return (*this);//retorna todos los valores guardados
}
bool Person:: operator == (const Person & unPerson)const//operador de igualdad y comparacion
de valores, verifica que sean iguales
{
return (this->firstName == unPerson.firstName && this->lastName == unPerson.lastName
&&
this->middleName == unPerson.middleName && this->maidenName ==
unPerson.maidenName);
}
ostream & operator <<(ostream & output, const Person & unPerson)//imprime valores
{
output << " First Name:  " << unPerson.firstName;
output << " LastName:  " << unPerson.lastName;
output << "MiddleName: " << unPerson.middleName;
output << " Maiden Name: " << unPerson.maidenName;
return output;
}
istream & operator >>(istream & input, Person & unPerson)//cambia o pide valores
{
cout << " Please Enter First Name t Middle Name t Last Name t Maiden Name " <<
endl;
input >> unPerson.firstName;
input >> unPerson.middleName;
input >> unPerson.lastName;
input >> unPerson.maidenName;
return input;
}
Menu.h
#pragma once
#include
#include
#include "MyLib.h"
using namespace::std;
#ifndef MENU_H
#define MENU_H
enum Choice { numeric, alpha };
enum Lang { eng, spa };
class Menu {
private:
string * items;
string title;
int totalItems;
Lang lang;
Choice choice;
int option;
flag validate;
flag subMenu;
public:
Menu()
{
init();
}
Menu(const char * title)
{
init();
this->title = title;
}
Menu(const Menu & aMenu)
{
init();
this->title = aMenu.title;
if (!aMenu.isEmpty()) {
for (int i = 0; i < aMenu.totalItems; ++i) {
addItem(aMenu.items[i]);
}
this->choice = aMenu.choice;
this->validate = aMenu.validate;
this->subMenu = aMenu.subMenu;
this->title = aMenu.title;
}
}
void init() {
this->items = NULL;
this->totalItems = 0;
this->lang = eng;
this->choice = numeric;
this->validate = false;
this->subMenu = false;
this->title = "Menu";
}
~Menu()
{
delete[] this->items;
}
bool isEmpty() const
{
return this->totalItems == 0;
}
void addItem(string item)
{
int idx = this->totalItems;
string * tmp;
int i;
if (isEmpty()) {
this->items = new string[1];
}
else {
tmp = new string[this->totalItems];
for (i = 0; i < this->totalItems; i++) {
tmp[i] = this->items[i];
}
delete[] this->items;
this->items = new string[this->totalItems + 1];
for (i = 0; i < this->totalItems; i++) {
this->items[i] = tmp[i];
}
delete[] tmp;
}
this->items[idx] = item;
this->totalItems++;
}
bool check()
{
if (this->choice == alpha) {
this->validate = between(char(option), 'A', char('A' + this->totalItems));
}
else {
this->validate = between(option, 1, this->totalItems + 1);
}
return this->validate;
}
void setChoice(Choice choice)
{
this->choice = choice;
}
void setOption(int option)
{
this->option = upper(option); check();
}
void setLang(Lang lang)
{
this->lang = lang;
}
void setTitle(string title)
{
this->title = title;
}
void setSubMenu(flag subMenu)
{
subMenu = subMenu;
}
Lang getLanguage() const
{
return this->lang;
}
int getOption() const
{
return this->option;
}
int getLast() const
{
if (this->choice == alpha) {
return char('A' + this->totalItems);
}
else {
return this->totalItems + 1;
}
}
friend ostream & operator <<(ostream & os, Menu & unMenu)
{
int i;
char ch = 'a';
cls();
os << unMenu.title << endl << endl;
for (i = 0; i < unMenu.totalItems; i++) {
os << "t";
if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1;
os << ".) " << unMenu.items[i] << endl;
}
os << "t";
if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1;
os << ".) ";
if (unMenu.lang == eng) {
if (unMenu.subMenu)
os << "Return";
else
os << "Exit";
os << "  Choose: ";
}
else {
if (unMenu.subMenu)
os << "Regresar";
else
os << "Salir";
os << " Opcion: ";
}
return os;
}
friend istream & operator >>(istream & in, Menu & unMenu)
{
do {
char opt;
in >> opt;
unMenu.setOption((unMenu.choice == alpha ? opt : opt - '0'));
if (!unMenu.check()) {
cerr << " Error: Wrong choice!!!  ";
pause();
cout << unMenu;
}
} while (!unMenu.check());
return in;
}
};
#endif // MENU_H
mylib.h
#pragma once
#include
#include
using namespace::std;
#ifndef MYLIB_H
#define MYLIB_H
typedef bool flag;
#ifdef WINDOWS
#define cls() system("cls")
#define pause() system("pause")
#elif windows
#define cls() system("cls")
#define pause() system("pause")
#elif LINUX
#define cls() system("clear")
#define pause() system("sleep 3")
#elif linux
#define cls() system("clear")
#define pause() system("sleep 3")
#else
#define cls() { cerr << "CLS: Unknown OS!!! "; }
#define pause() { cerr << "PAUSE: Unknown OS!!! "; }
#endif
#define between(x, y, z) ((x >= y && x <= z)? true : false)
#define upper(x) (between(x, 'A', 'Z')? x : (between(x, 'a', 'z')? x - 'a' + 'A' : x))
#define lower(x) (between(x, 'a', 'z')? x : x - 'A' + 'a')
#endif // MYLIB_H
DataParser.h
#include "DataParser.h"
#include
#include"Person.h"
#include"Report.h"
DataParser::DataParser()
{
record;
}
DataParser::DataParser(string line)
{
parseLine(line);
}
DataParser::DataParser(const DataParser & unDataParser)
{
this->record = unDataParser.record;
this->fecha = unDataParser.fecha;
}
DataParser::~DataParser()
{
}
Data DataParser::parseLine(string line)
{
Person client;//atributos de clase Person y Data
string callDate;
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
string firstName;
string lastName;
string middleName;
string maidenName;
//substr demostrara en que linea
firstName = line.substr(0, 25);
middleName = line.substr(25, 25);
lastName = line.substr(50, 50);
maidenName = line.substr(100, 50);
callDate = line.substr(150, 8);
if (line.substr(158, 1) == "Y")//yes or no
longDistance = true;
else
longDistance = false;
timeCallBegin = line.substr(159, 6);
timeCallEnd = line.substr(165, 6);
callNoFrom = line.substr(171, 10);
callNoTo = line.substr(181, 10);
record.setClient(Person(firstName, middleName, lastName, maidenName));
record.setCallDate(callDate);
record.setLongDistance(longDistance);
record.setTimeCallBegin(timeCallBegin);
record.setTimeCallEnd(timeCallEnd);
record.setCallNoFrom(callNoFrom);
record.setCallNoTo(callNoTo);
return record;
}
void DataParser::setRecord(string line)
{
parseLine(line);
}
Data DataParser::getRecord() const
{
return (this->record);
}
string DataParser::date(string date)
{
string fecha;
fecha = date.substr(191, 2) + "/" + date.substr(193, 2) + "/" + date.substr(195, 4);
return fecha;
}
void DataParser::setFecha(int fecha)
{
this->fecha = fecha;
}
int DataParser::getFecha()const
{
return(this->fecha);
}
DataParser.h
#pragma once
#include
#include
#include "Data.h"
using namespace std;
class DataParser
{
private:
Data record;
int fecha;
public:
DataParser();
DataParser(string line);
DataParser(const DataParser & unDataPaser);
~DataParser();
void setRecord(string line);
void setFecha(int fecha);
int getFecha()const;
Data getRecord()const;
Data parseLine(string line);
string date(string date);
// friend ostream & operator <<(ostream & os, const DataParser & unDataParser);
// friend istream & operator >> (istream & is, DataParser & unDataParser);
};
Report.cpp
#include "Report.h"
Report::Report()
{
records = NULL;
totalRecords = 0;
totalMinutes = 0.0;
totalAmmount = 0.0;
fileName=(" ");
}
Report::Report(Data records, int totalRecords, float totalMinutes, float totalAmmount, string
fileName)
{
setTotalRecords(totalRecords);
setTotalMinutes(totalMinutes);
setTotalAmmount(totalAmmount);
setFileName(fileName);
}
void Report::addRecord(const Data & unData)
{
Data *records;
records = new Data[this->totalRecords + 1];
for (int i = 0;i < this->totalRecords;i++)
{
records[this->totalRecords] = unData;
delete[](this->records);
this->records = records;
++(this->records);
}
}
Report::Report(const Report & unReport)
{
this->records = NULL;
totalRecords = unReport.totalRecords;
totalMinutes = unReport.totalMinutes;
totalAmmount = unReport.totalAmmount;
fileName = unReport.fileName;
(*this) = unReport;
}
Report::~Report()
{
delete[](this->records);
}
void Report::setTotalRecords(int totalRecords)
{
this->totalRecords = totalRecords;
}
void Report::setTotalAmmount(float totalAmmount)
{
this->totalAmmount = totalAmmount;
}
void Report::setTotalMinutes(float totalMinutes)
{
this->totalMinutes = totalMinutes;
}
void Report::setFileName(string fileName)
{
this->fileName = fileName;
}
const Data & Report::operator[](int indice)const
{
return((this->records)[indice]);
}
Data Report::getRecords()const
{
for (int i = 0;i < totalRecords;i++)
{
return (records[i]);
}
}
int Report::getTotalRecords()const
{
return this->totalRecords;
}
float Report::getTotalAmmount()const
{
return this->totalAmmount;
}
float Report::getTotalMinutes()const
{
return this->totalMinutes;
}
string Report::getFileName()const
{
return this->fileName;
}
Report & Report::operator =(const Report & unReport)
{
delete[](this->records);
if (unReport.totalRecords > 0)
{
this->records = new Data[unReport.totalRecords];
for (int i = 0;i < unReport.totalRecords;i++)
{
(this->records[i] = (unReport.records)[i]);
}
}
else
{
this->records = NULL;
}
this->totalAmmount = unReport.totalAmmount;
this->totalMinutes = unReport.totalMinutes;
this->fileName = unReport.fileName;
return (*this);
}
bool Report::operator ==(const Report & unReport)const
{
bool record = false;
for (int i = 0;i < unReport.totalRecords;i++)
{
if (records[i] == unReport.records[i])
{
record = true;
}
return record;
}
return (this->totalRecords == unReport.totalRecords && this->totalAmmount ==
unReport.totalAmmount &&
this->totalMinutes == unReport.totalMinutes && this->fileName == unReport.fileName);
}
ostream & operator <<(ostream & os, const Report & unReport)
{
for (int i = 0; i < unReport.totalRecords;i++)
{
os << "Record number is: " << unReport.records[i] << endl;
}
return os;
}
istream & operator >>(istream & is, Report & unReport)
{
cout << "Enter record:" << unReport.records << endl;;
cout << "Total Records are: ";
is >> unReport.totalRecords;
cout << "Total Ammount: ";
is >> unReport.totalAmmount;
cout << "Total Minutes:";
is >> unReport.totalMinutes;
cout << "File name is: ";
is >> unReport.fileName;
return is;
}
Report.h
#pragma once
#include"Data.h"
#include
#include
using namespace std;
class Report
{
private:
Data *records;
int totalRecords;
float totalMinutes;
float totalAmmount;
string fileName;
public:
Report();
Report(Data records,int totalRecords, float totalMinutes, float totalAmmount, string
fileName);
Report(const Report & unReport);
~Report();
void addRecord(const Data & unData);
void setTotalRecords(int totalRecords);
void setTotalMinutes(float totalMinutes);
void setTotalAmmount(float totalAmmount);
void setFileName(string fileName);
const Data & operator[](int indice)const;
Data getRecords()const;
int getTotalRecords()const;
float getTotalMinutes()const;
float getTotalAmmount()const;
string getFileName()const;
Report & operator = (const Report & unReport);
bool operator ==(const Report & unReport)const;
friend ostream & operator<<(ostream & os, const Report & unReport);
friend istream & operator>>(istream & is, Report & unReport);
};
Solution
#include
#include"Data.h"
#include"Person.h"
#include"Report.h"
#include
#include
#include "Menu.h"
using namespace std;
/*
Programmers: Javier A. Molina, Eduardo Bonnet
Students #:79249
*/
int main()
{
int cnt;
int idx;
string fileName;
Report * telefonia;
Menu menu("Reports");
bool fileNameExists(string fileName);
Report * addReport(Report * reports, int & totalReports);
Report * delReport(Report * reports, int & totalReports, int idx);
int displayReports(Report * reports, int totalReports);
menu.addItem("New report");
menu.addItem("Delete a report");
menu.addItem("Display a report");
cnt = 0;
telefonia = NULL;
do {
cout << menu;
cin >> menu;
//cls();
switch (menu.getOption()) {
case 1:
cout << "Enter report name (TE?????): ";
cin >> fileName;
if (fileNameExists(fileName + ".tel")) {
telefonia = addReport(telefonia, cnt);
idx = cnt - 1;
telefonia[idx].setFileName(fileName);
// telefonia[idx].loadReport();
}
else {
cls();
cerr << "Error: Report name '" << fileName << "' does not exists!   ";
//pause();
}
break;
case 2:
if (telefonia != NULL) {
do {
cls();
cout << "Delete a Report:  ";
idx = displayReports(telefonia, cnt);
if (between(idx, 0, cnt - 1)) {
cls();
telefonia = delReport(telefonia, cnt, idx);
idx = 0;
// pause();
}
} while (idx != cnt);
}
else {
cerr << "No reports available for deleting!   ";
//pause();
}
break;
case 3:
char ans;
if (telefonia != NULL) {
do {
// cls();
cout << "Display/Filed a Report:  ";
idx = displayReports(telefonia, cnt);
if (between(idx, 0, cnt - 1)) {
// cls();
cout << "Would you like the report to be display otherwise save into a file? ";
cin >> ans;
cls();
cin.ignore();
if (upper(ans) == 'Y') {
cout << telefonia[idx] << endl;
}
else {
//telefonia[idx].saveReport();
cout << "Report '" << telefonia[idx].getFileName() << "' saved as '" <<
telefonia[idx].getFileName() << ".rep'.  ";
}
//pause();
}
} while (idx != cnt);
}
else {
cerr << "No reports available for displaying!   ";
// pause();
}
break;
case 4:
cout << "Thanks for using Telefonia Reports System!!!   ";
break;
}
} while (menu.getLast() != menu.getOption());
delete[] telefonia;
return 0;
}
//Funcion que verifica si existe un archivo en disco
bool fileNameExists(string fileName) {
ifstream fin(fileName.c_str());
bool exists = !(fin.fail());
if (exists) fin.close();
return(exists);
}
//Anade dinamicamente objetos tipo Report al arreglo reports
Report * addReport(Report * reports, int & totalReports) {
if (totalReports == 0) {
reports = new Report[1];
}
else {
Report * tmp = new Report[totalReports];
for (int i = 0; i < totalReports; ++i) {
tmp[i] = reports[i];
}
delete[] reports;
reports = new Report[totalReports + 1];
for (int i = 0; i < totalReports; ++i) {
reports[i] = tmp[i];
}
delete[] tmp;
}
totalReports++;
return(reports);
}
//Borra objetos del arreglo reports segun el idx enviado
Report * delReport(Report * reports, int & totalReports, int idx) {
Report * tmp = new Report[totalReports - 1];
string fileName = reports[idx].getFileName();
for (int i = 0, j = 0; i < totalReports; ++i) {
if (i == idx) continue;
tmp[j] = reports[i];
j++;
}
delete[] reports;
totalReports--;
reports = new Report[totalReports];
for (int i = 0; i < totalReports; ++i) {
reports[i] = tmp[i];
}
delete[] tmp;
cout << "Report '" << fileName << "' has been deleted! " << endl;
if (totalReports == 0) reports = NULL;
return(reports);
}
//Muestra en pantalla la lista de informes que se encuantran en memoria
int displayReports(Report * reports, int totalReports) {
int choice;
int i;
for (i = 0; i < totalReports; ++i) {
cout << "t" << (i + 1) << ".) " << reports[i].getFileName() << endl;
}
cout << "t" << (i + 1) << ".) Return ";
cout << " tChoice: ";
cin >> choice;
return (choice - 1);
}
Data.h
#include
#include
#include
#ifndef DATA_H
#define DATA_H
#include "Person.h"
using namespace std;
#pragma once
//Trata de establecer coneccion entre la clase data y person, utilizando informacion de la clase
person busca informacion de las llamadas hechas por el cliente
//Person(client) con esto saca la informacion de los datos escritos en la clase
class Data
{
private:
Person client;//atributo de la clase person
string callDate;//atributos esenciales de la clase Data
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
public:
Data();//default
Data(Person client, string callDate, bool longDistance, string timeCallBegin, string
timeCallEnd, string callNoFrom, string callNoTo);//parameter constructor
Data(const Data & unData);//copy constructor
~Data();//destructor
void setClient(const Person & client);//setters
void setCallDate(string callDate);
void setLongDistance(bool longDistance);
void setTimeCallBegin(string timeCallBegin);
void setTimeCallEnd(string timeCallEnd);
void setCallNoFrom(string callNoFrom);
void setCallNoTo(string callNoTo);
Person getClient()const;//getters
string getCallDate()const;
bool getLongDistance()const;
string getTimeCallBegin()const;
string getTimeCallEnd()const;
string getCallNoFrom()const;
string getCallNoTo()const;
Data & operator = (const Data & unData);//operador de asignar
bool operator ==(const Data & unData)const;//operador de igualdad
friend ostream & operator <<(ostream & output, const Data & unData);//friend operador,
imprime valores
friend istream & operator >>(istream & input, Data & unData);//friend operator, manipula los
valores de los atributos
};
#endif // DATA_H
Data.cpp
#include "Data.h"
using namespace std;
Data::Data()//default
{
setClient(Person(" "," "," "," "));
setCallDate(" ");//valores asignados por default
setLongDistance(false);
setTimeCallBegin(" ");
setTimeCallEnd(" ");
setCallNoFrom(" ");
setCallNoTo(" ");
}
Data::Data (Person client, string callDate, bool longDistance, string timeCallBegin, string
timeCallEnd, string callNoFrom, string callNoTo)//parameter constructor
{
setClient(client);
setCallDate(callDate);
setLongDistance(longDistance);
setTimeCallBegin(timeCallBegin);
setTimeCallEnd(timeCallEnd);
setCallNoFrom(callNoFrom);
setCallNoTo(callNoTo);
}
Data::Data(const Data & unData)//copy constructor
{
this->client = unData.client;
this->callDate = unData.callDate;
this->longDistance = unData.longDistance;
this->timeCallBegin = unData.timeCallBegin;
this->timeCallEnd = unData.timeCallEnd;
this->callNoFrom = unData.callNoFrom;
this->callNoTo = unData.callNoTo;
}
Data::~Data()//destructor
{
}
void Data::setClient(const Person & client)//setters
{
this->client = client;
}
void Data::setCallDate(string callDate)
{
this->callDate = callDate;
}
void Data::setLongDistance(bool longDistance)
{
if (longDistance == 1)//verificacion del valor para clasificar en true or false
{
longDistance = true;
this->longDistance = longDistance;
}
else
{
longDistance = false;
this->longDistance = longDistance;
}
}
void Data::setTimeCallBegin(string timeCallBegin)
{
this->timeCallBegin = timeCallBegin;
}
void Data::setTimeCallEnd(string timeCallEnd)
{
this->timeCallEnd = timeCallEnd;
}
void Data::setCallNoFrom(string callNoFrom)
{
this->callNoFrom = callNoFrom;
}
void Data::setCallNoTo(string callNoTo)
{
this->callNoTo = callNoTo;
}
Person Data::getClient()const//getters
{
return (this->client);
}
string Data::getCallDate()const
{
return (this->callDate);
}
bool Data::getLongDistance()const
{
return(this->longDistance);
}
string Data::getTimeCallBegin()const
{
return (this->timeCallBegin);
}
string Data::getTimeCallEnd()const
{
return (this->timeCallEnd);
}
string Data::getCallNoFrom()const
{
return (this->callNoFrom);
}
string Data::getCallNoTo()const
{
return(this->callNoTo);
}
Data & Data :: operator =(const Data & unData)//asigna los valores
{
this->client = unData.client;
this->callDate = unData.callDate;
this->longDistance = unData.longDistance;
this->timeCallBegin = unData.timeCallBegin;
this->timeCallEnd = unData.timeCallEnd;
this->callNoFrom = unData.callNoFrom;
this->callNoTo = unData.callNoTo;
return (*this);
}
bool Data :: operator ==(const Data & unData)const//verificacion de igualdad de todos los
valores
{
return (this->client == unData.client && this->callDate == unData.callDate && this-
>longDistance == unData.longDistance &&
this->timeCallBegin == unData.timeCallBegin && this->timeCallEnd ==
unData.timeCallEnd && this->callNoFrom == unData.callNoFrom &&
this->callNoTo == unData.callNoTo);
}
ostream & operator <<(ostream & output, const Data & unData)//imprime valores
{
Person person;
output << "Providing Client Information:" << endl;
output << person.getFirstName();
output << person.getLastName();
output << person.getMiddleName();
output << person.getMaidenName();
output << endl << "Call Date: " << unData.callDate << endl;
output << "longDistance Charge: " << unData.longDistance ? " Y " : " N ";//Yes or No
question
output << "Time Call Begin: " << unData.timeCallBegin;
output << "Time Call End: " << unData.timeCallEnd;
output << "Call # From: " << unData.callNoFrom;
output << "Call # to: " << unData.callNoTo;
return output;
}
istream & operator >>(istream & input, Data & unData)//pide valores
{
cout << "Client Information: " << endl;
input >> unData.client;
cout << "Call Date: " << endl;
input >> unData.callDate;
cout << " Long Distance: " << endl;
input >> unData.longDistance;
cout << " Time Call Begin: " << endl;
input >> unData.timeCallBegin;
cout << " Time Call End: " << endl;
input >> unData.timeCallEnd;
cout << " Call # From : " << endl;
input >> unData.callNoFrom;
cout << " Call # To: " << endl;
input >> unData.callNoTo;
return input;
}
Person.h
#pragma once
#include
#include
using namespace std;
class Person
{
private:
string firstName;
string lastName;
string middleName;
string maidenName;
public:
Person();
Person(string firstName, string lastName, string middleName, string maidenName);
Person(const Person & unPerson);//copy constructor
~Person();//destructor
void setFirstName(string firsName);//setters
void setLastName(string lastName);
void setMiddleName(string middleName);
void setMaidenName(string maidenName);
string getFirstName()const;//getters
string getLastName()const;
string getMiddleName()const;
string getMaidenName()const;
Person & operator = (const Person & unPerson);//operador de asignar valores
bool operator ==(const Person & unPerson)const;//operador de igualdad
friend ostream & operator <<(ostream & output, const Person & unPerson);//friend operador
que imprime
friend istream & operator >>(istream & input, Person & unPerson);//friend operador que pide
cambia valores
};
Person.cpp
#include "Person.h"
using namespace std;
Person::Person()//default cnstructor
{
firstName = (" ");//valores por default
lastName =(" ");
middleName =(" ");
maidenName = (" ");
}
Person::Person(string firstName, string lastName, string middleName, string
maidenName)//parameter
{
setFirstName(firstName);//nombrando las variables
setLastName(lastName);
setMiddleName(middleName);
setMaidenName(maidenName);
}
Person::Person(const Person & unPerson)//copy
{
firstName = unPerson.firstName;//asignando variables
lastName = unPerson.lastName;
middleName = unPerson.middleName;
maidenName = unPerson.maidenName;
}
Person::~Person()//destructor
{
}
void Person::setFirstName(string firstName)//setters
{
this->firstName = firstName;
}
void Person::setLastName(string lastName)
{
this->lastName = lastName;
}
void Person::setMiddleName(string middleName)
{
this->middleName = middleName;
}
void Person::setMaidenName(string maidenName)
{
this->maidenName = maidenName;
}
string Person::getFirstName()const//getters
{
return (this->firstName);
}
string Person::getLastName()const
{
return (this->lastName);
}
string Person::getMiddleName()const
{
return (this->middleName);
}
string Person::getMaidenName()const
{
return (this->maidenName);
}
Person & Person:: operator =(const Person & unPerson)//operador que asigna valores
{
this->firstName = unPerson.firstName;
this->lastName = unPerson.lastName;
this->middleName = unPerson.middleName;
this->maidenName = unPerson.maidenName;
return (*this);//retorna todos los valores guardados
}
bool Person:: operator == (const Person & unPerson)const//operador de igualdad y comparacion
de valores, verifica que sean iguales
{
return (this->firstName == unPerson.firstName && this->lastName == unPerson.lastName
&&
this->middleName == unPerson.middleName && this->maidenName ==
unPerson.maidenName);
}
ostream & operator <<(ostream & output, const Person & unPerson)//imprime valores
{
output << " First Name:  " << unPerson.firstName;
output << " LastName:  " << unPerson.lastName;
output << "MiddleName: " << unPerson.middleName;
output << " Maiden Name: " << unPerson.maidenName;
return output;
}
istream & operator >>(istream & input, Person & unPerson)//cambia o pide valores
{
cout << " Please Enter First Name t Middle Name t Last Name t Maiden Name " <<
endl;
input >> unPerson.firstName;
input >> unPerson.middleName;
input >> unPerson.lastName;
input >> unPerson.maidenName;
return input;
}
Menu.h
#pragma once
#include
#include
#include "MyLib.h"
using namespace::std;
#ifndef MENU_H
#define MENU_H
enum Choice { numeric, alpha };
enum Lang { eng, spa };
class Menu {
private:
string * items;
string title;
int totalItems;
Lang lang;
Choice choice;
int option;
flag validate;
flag subMenu;
public:
Menu()
{
init();
}
Menu(const char * title)
{
init();
this->title = title;
}
Menu(const Menu & aMenu)
{
init();
this->title = aMenu.title;
if (!aMenu.isEmpty()) {
for (int i = 0; i < aMenu.totalItems; ++i) {
addItem(aMenu.items[i]);
}
this->choice = aMenu.choice;
this->validate = aMenu.validate;
this->subMenu = aMenu.subMenu;
this->title = aMenu.title;
}
}
void init() {
this->items = NULL;
this->totalItems = 0;
this->lang = eng;
this->choice = numeric;
this->validate = false;
this->subMenu = false;
this->title = "Menu";
}
~Menu()
{
delete[] this->items;
}
bool isEmpty() const
{
return this->totalItems == 0;
}
void addItem(string item)
{
int idx = this->totalItems;
string * tmp;
int i;
if (isEmpty()) {
this->items = new string[1];
}
else {
tmp = new string[this->totalItems];
for (i = 0; i < this->totalItems; i++) {
tmp[i] = this->items[i];
}
delete[] this->items;
this->items = new string[this->totalItems + 1];
for (i = 0; i < this->totalItems; i++) {
this->items[i] = tmp[i];
}
delete[] tmp;
}
this->items[idx] = item;
this->totalItems++;
}
bool check()
{
if (this->choice == alpha) {
this->validate = between(char(option), 'A', char('A' + this->totalItems));
}
else {
this->validate = between(option, 1, this->totalItems + 1);
}
return this->validate;
}
void setChoice(Choice choice)
{
this->choice = choice;
}
void setOption(int option)
{
this->option = upper(option); check();
}
void setLang(Lang lang)
{
this->lang = lang;
}
void setTitle(string title)
{
this->title = title;
}
void setSubMenu(flag subMenu)
{
subMenu = subMenu;
}
Lang getLanguage() const
{
return this->lang;
}
int getOption() const
{
return this->option;
}
int getLast() const
{
if (this->choice == alpha) {
return char('A' + this->totalItems);
}
else {
return this->totalItems + 1;
}
}
friend ostream & operator <<(ostream & os, Menu & unMenu)
{
int i;
char ch = 'a';
cls();
os << unMenu.title << endl << endl;
for (i = 0; i < unMenu.totalItems; i++) {
os << "t";
if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1;
os << ".) " << unMenu.items[i] << endl;
}
os << "t";
if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1;
os << ".) ";
if (unMenu.lang == eng) {
if (unMenu.subMenu)
os << "Return";
else
os << "Exit";
os << "  Choose: ";
}
else {
if (unMenu.subMenu)
os << "Regresar";
else
os << "Salir";
os << " Opcion: ";
}
return os;
}
friend istream & operator >>(istream & in, Menu & unMenu)
{
do {
char opt;
in >> opt;
unMenu.setOption((unMenu.choice == alpha ? opt : opt - '0'));
if (!unMenu.check()) {
cerr << " Error: Wrong choice!!!  ";
pause();
cout << unMenu;
}
} while (!unMenu.check());
return in;
}
};
#endif // MENU_H
mylib.h
#pragma once
#include
#include
using namespace::std;
#ifndef MYLIB_H
#define MYLIB_H
typedef bool flag;
#ifdef WINDOWS
#define cls() system("cls")
#define pause() system("pause")
#elif windows
#define cls() system("cls")
#define pause() system("pause")
#elif LINUX
#define cls() system("clear")
#define pause() system("sleep 3")
#elif linux
#define cls() system("clear")
#define pause() system("sleep 3")
#else
#define cls() { cerr << "CLS: Unknown OS!!! "; }
#define pause() { cerr << "PAUSE: Unknown OS!!! "; }
#endif
#define between(x, y, z) ((x >= y && x <= z)? true : false)
#define upper(x) (between(x, 'A', 'Z')? x : (between(x, 'a', 'z')? x - 'a' + 'A' : x))
#define lower(x) (between(x, 'a', 'z')? x : x - 'A' + 'a')
#endif // MYLIB_H
DataParser.h
#include "DataParser.h"
#include
#include"Person.h"
#include"Report.h"
DataParser::DataParser()
{
record;
}
DataParser::DataParser(string line)
{
parseLine(line);
}
DataParser::DataParser(const DataParser & unDataParser)
{
this->record = unDataParser.record;
this->fecha = unDataParser.fecha;
}
DataParser::~DataParser()
{
}
Data DataParser::parseLine(string line)
{
Person client;//atributos de clase Person y Data
string callDate;
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
string firstName;
string lastName;
string middleName;
string maidenName;
//substr demostrara en que linea
firstName = line.substr(0, 25);
middleName = line.substr(25, 25);
lastName = line.substr(50, 50);
maidenName = line.substr(100, 50);
callDate = line.substr(150, 8);
if (line.substr(158, 1) == "Y")//yes or no
longDistance = true;
else
longDistance = false;
timeCallBegin = line.substr(159, 6);
timeCallEnd = line.substr(165, 6);
callNoFrom = line.substr(171, 10);
callNoTo = line.substr(181, 10);
record.setClient(Person(firstName, middleName, lastName, maidenName));
record.setCallDate(callDate);
record.setLongDistance(longDistance);
record.setTimeCallBegin(timeCallBegin);
record.setTimeCallEnd(timeCallEnd);
record.setCallNoFrom(callNoFrom);
record.setCallNoTo(callNoTo);
return record;
}
void DataParser::setRecord(string line)
{
parseLine(line);
}
Data DataParser::getRecord() const
{
return (this->record);
}
string DataParser::date(string date)
{
string fecha;
fecha = date.substr(191, 2) + "/" + date.substr(193, 2) + "/" + date.substr(195, 4);
return fecha;
}
void DataParser::setFecha(int fecha)
{
this->fecha = fecha;
}
int DataParser::getFecha()const
{
return(this->fecha);
}
DataParser.h
#pragma once
#include
#include
#include "Data.h"
using namespace std;
class DataParser
{
private:
Data record;
int fecha;
public:
DataParser();
DataParser(string line);
DataParser(const DataParser & unDataPaser);
~DataParser();
void setRecord(string line);
void setFecha(int fecha);
int getFecha()const;
Data getRecord()const;
Data parseLine(string line);
string date(string date);
// friend ostream & operator <<(ostream & os, const DataParser & unDataParser);
// friend istream & operator >> (istream & is, DataParser & unDataParser);
};
Report.cpp
#include "Report.h"
Report::Report()
{
records = NULL;
totalRecords = 0;
totalMinutes = 0.0;
totalAmmount = 0.0;
fileName=(" ");
}
Report::Report(Data records, int totalRecords, float totalMinutes, float totalAmmount, string
fileName)
{
setTotalRecords(totalRecords);
setTotalMinutes(totalMinutes);
setTotalAmmount(totalAmmount);
setFileName(fileName);
}
void Report::addRecord(const Data & unData)
{
Data *records;
records = new Data[this->totalRecords + 1];
for (int i = 0;i < this->totalRecords;i++)
{
records[this->totalRecords] = unData;
delete[](this->records);
this->records = records;
++(this->records);
}
}
Report::Report(const Report & unReport)
{
this->records = NULL;
totalRecords = unReport.totalRecords;
totalMinutes = unReport.totalMinutes;
totalAmmount = unReport.totalAmmount;
fileName = unReport.fileName;
(*this) = unReport;
}
Report::~Report()
{
delete[](this->records);
}
void Report::setTotalRecords(int totalRecords)
{
this->totalRecords = totalRecords;
}
void Report::setTotalAmmount(float totalAmmount)
{
this->totalAmmount = totalAmmount;
}
void Report::setTotalMinutes(float totalMinutes)
{
this->totalMinutes = totalMinutes;
}
void Report::setFileName(string fileName)
{
this->fileName = fileName;
}
const Data & Report::operator[](int indice)const
{
return((this->records)[indice]);
}
Data Report::getRecords()const
{
for (int i = 0;i < totalRecords;i++)
{
return (records[i]);
}
}
int Report::getTotalRecords()const
{
return this->totalRecords;
}
float Report::getTotalAmmount()const
{
return this->totalAmmount;
}
float Report::getTotalMinutes()const
{
return this->totalMinutes;
}
string Report::getFileName()const
{
return this->fileName;
}
Report & Report::operator =(const Report & unReport)
{
delete[](this->records);
if (unReport.totalRecords > 0)
{
this->records = new Data[unReport.totalRecords];
for (int i = 0;i < unReport.totalRecords;i++)
{
(this->records[i] = (unReport.records)[i]);
}
}
else
{
this->records = NULL;
}
this->totalAmmount = unReport.totalAmmount;
this->totalMinutes = unReport.totalMinutes;
this->fileName = unReport.fileName;
return (*this);
}
bool Report::operator ==(const Report & unReport)const
{
bool record = false;
for (int i = 0;i < unReport.totalRecords;i++)
{
if (records[i] == unReport.records[i])
{
record = true;
}
return record;
}
return (this->totalRecords == unReport.totalRecords && this->totalAmmount ==
unReport.totalAmmount &&
this->totalMinutes == unReport.totalMinutes && this->fileName == unReport.fileName);
}
ostream & operator <<(ostream & os, const Report & unReport)
{
for (int i = 0; i < unReport.totalRecords;i++)
{
os << "Record number is: " << unReport.records[i] << endl;
}
return os;
}
istream & operator >>(istream & is, Report & unReport)
{
cout << "Enter record:" << unReport.records << endl;;
cout << "Total Records are: ";
is >> unReport.totalRecords;
cout << "Total Ammount: ";
is >> unReport.totalAmmount;
cout << "Total Minutes:";
is >> unReport.totalMinutes;
cout << "File name is: ";
is >> unReport.fileName;
return is;
}
Report.h
#pragma once
#include"Data.h"
#include
#include
using namespace std;
class Report
{
private:
Data *records;
int totalRecords;
float totalMinutes;
float totalAmmount;
string fileName;
public:
Report();
Report(Data records,int totalRecords, float totalMinutes, float totalAmmount, string
fileName);
Report(const Report & unReport);
~Report();
void addRecord(const Data & unData);
void setTotalRecords(int totalRecords);
void setTotalMinutes(float totalMinutes);
void setTotalAmmount(float totalAmmount);
void setFileName(string fileName);
const Data & operator[](int indice)const;
Data getRecords()const;
int getTotalRecords()const;
float getTotalMinutes()const;
float getTotalAmmount()const;
string getFileName()const;
Report & operator = (const Report & unReport);
bool operator ==(const Report & unReport)const;
friend ostream & operator<<(ostream & os, const Report & unReport);
friend istream & operator>>(istream & is, Report & unReport);
};

#include iostream #includeData.h #includePerson.h#in.pdf

  • 1.
    #include #include"Data.h" #include"Person.h" #include"Report.h" #include #include #include "Menu.h" using namespacestd; /* Programmers: Javier A. Molina, Eduardo Bonnet Students #:79249 */ int main() { int cnt; int idx; string fileName; Report * telefonia; Menu menu("Reports"); bool fileNameExists(string fileName); Report * addReport(Report * reports, int & totalReports); Report * delReport(Report * reports, int & totalReports, int idx); int displayReports(Report * reports, int totalReports); menu.addItem("New report"); menu.addItem("Delete a report"); menu.addItem("Display a report"); cnt = 0; telefonia = NULL; do { cout << menu; cin >> menu; //cls(); switch (menu.getOption()) { case 1: cout << "Enter report name (TE?????): ";
  • 2.
    cin >> fileName; if(fileNameExists(fileName + ".tel")) { telefonia = addReport(telefonia, cnt); idx = cnt - 1; telefonia[idx].setFileName(fileName); // telefonia[idx].loadReport(); } else { cls(); cerr << "Error: Report name '" << fileName << "' does not exists! "; //pause(); } break; case 2: if (telefonia != NULL) { do { cls(); cout << "Delete a Report: "; idx = displayReports(telefonia, cnt); if (between(idx, 0, cnt - 1)) { cls(); telefonia = delReport(telefonia, cnt, idx); idx = 0; // pause(); } } while (idx != cnt); } else { cerr << "No reports available for deleting! "; //pause(); } break; case 3: char ans; if (telefonia != NULL) { do {
  • 3.
    // cls(); cout <<"Display/Filed a Report: "; idx = displayReports(telefonia, cnt); if (between(idx, 0, cnt - 1)) { // cls(); cout << "Would you like the report to be display otherwise save into a file? "; cin >> ans; cls(); cin.ignore(); if (upper(ans) == 'Y') { cout << telefonia[idx] << endl; } else { //telefonia[idx].saveReport(); cout << "Report '" << telefonia[idx].getFileName() << "' saved as '" << telefonia[idx].getFileName() << ".rep'. "; } //pause(); } } while (idx != cnt); } else { cerr << "No reports available for displaying! "; // pause(); } break; case 4: cout << "Thanks for using Telefonia Reports System!!! "; break; } } while (menu.getLast() != menu.getOption()); delete[] telefonia; return 0; } //Funcion que verifica si existe un archivo en disco bool fileNameExists(string fileName) {
  • 4.
    ifstream fin(fileName.c_str()); bool exists= !(fin.fail()); if (exists) fin.close(); return(exists); } //Anade dinamicamente objetos tipo Report al arreglo reports Report * addReport(Report * reports, int & totalReports) { if (totalReports == 0) { reports = new Report[1]; } else { Report * tmp = new Report[totalReports]; for (int i = 0; i < totalReports; ++i) { tmp[i] = reports[i]; } delete[] reports; reports = new Report[totalReports + 1]; for (int i = 0; i < totalReports; ++i) { reports[i] = tmp[i]; } delete[] tmp; } totalReports++; return(reports); } //Borra objetos del arreglo reports segun el idx enviado Report * delReport(Report * reports, int & totalReports, int idx) { Report * tmp = new Report[totalReports - 1]; string fileName = reports[idx].getFileName(); for (int i = 0, j = 0; i < totalReports; ++i) { if (i == idx) continue; tmp[j] = reports[i]; j++; } delete[] reports; totalReports--;
  • 5.
    reports = newReport[totalReports]; for (int i = 0; i < totalReports; ++i) { reports[i] = tmp[i]; } delete[] tmp; cout << "Report '" << fileName << "' has been deleted! " << endl; if (totalReports == 0) reports = NULL; return(reports); } //Muestra en pantalla la lista de informes que se encuantran en memoria int displayReports(Report * reports, int totalReports) { int choice; int i; for (i = 0; i < totalReports; ++i) { cout << "t" << (i + 1) << ".) " << reports[i].getFileName() << endl; } cout << "t" << (i + 1) << ".) Return "; cout << " tChoice: "; cin >> choice; return (choice - 1); } Data.h #include #include #include #ifndef DATA_H #define DATA_H #include "Person.h" using namespace std; #pragma once //Trata de establecer coneccion entre la clase data y person, utilizando informacion de la clase person busca informacion de las llamadas hechas por el cliente //Person(client) con esto saca la informacion de los datos escritos en la clase class Data { private:
  • 6.
    Person client;//atributo dela clase person string callDate;//atributos esenciales de la clase Data bool longDistance; string timeCallBegin; string timeCallEnd; string callNoFrom; string callNoTo; public: Data();//default Data(Person client, string callDate, bool longDistance, string timeCallBegin, string timeCallEnd, string callNoFrom, string callNoTo);//parameter constructor Data(const Data & unData);//copy constructor ~Data();//destructor void setClient(const Person & client);//setters void setCallDate(string callDate); void setLongDistance(bool longDistance); void setTimeCallBegin(string timeCallBegin); void setTimeCallEnd(string timeCallEnd); void setCallNoFrom(string callNoFrom); void setCallNoTo(string callNoTo); Person getClient()const;//getters string getCallDate()const; bool getLongDistance()const; string getTimeCallBegin()const; string getTimeCallEnd()const; string getCallNoFrom()const; string getCallNoTo()const; Data & operator = (const Data & unData);//operador de asignar bool operator ==(const Data & unData)const;//operador de igualdad friend ostream & operator <<(ostream & output, const Data & unData);//friend operador, imprime valores friend istream & operator >>(istream & input, Data & unData);//friend operator, manipula los valores de los atributos }; #endif // DATA_H
  • 7.
    Data.cpp #include "Data.h" using namespacestd; Data::Data()//default { setClient(Person(" "," "," "," ")); setCallDate(" ");//valores asignados por default setLongDistance(false); setTimeCallBegin(" "); setTimeCallEnd(" "); setCallNoFrom(" "); setCallNoTo(" "); } Data::Data (Person client, string callDate, bool longDistance, string timeCallBegin, string timeCallEnd, string callNoFrom, string callNoTo)//parameter constructor { setClient(client); setCallDate(callDate); setLongDistance(longDistance); setTimeCallBegin(timeCallBegin); setTimeCallEnd(timeCallEnd); setCallNoFrom(callNoFrom); setCallNoTo(callNoTo); } Data::Data(const Data & unData)//copy constructor { this->client = unData.client; this->callDate = unData.callDate; this->longDistance = unData.longDistance; this->timeCallBegin = unData.timeCallBegin; this->timeCallEnd = unData.timeCallEnd; this->callNoFrom = unData.callNoFrom; this->callNoTo = unData.callNoTo; } Data::~Data()//destructor {
  • 8.
    } void Data::setClient(const Person& client)//setters { this->client = client; } void Data::setCallDate(string callDate) { this->callDate = callDate; } void Data::setLongDistance(bool longDistance) { if (longDistance == 1)//verificacion del valor para clasificar en true or false { longDistance = true; this->longDistance = longDistance; } else { longDistance = false; this->longDistance = longDistance; } } void Data::setTimeCallBegin(string timeCallBegin) { this->timeCallBegin = timeCallBegin; } void Data::setTimeCallEnd(string timeCallEnd) { this->timeCallEnd = timeCallEnd; } void Data::setCallNoFrom(string callNoFrom) { this->callNoFrom = callNoFrom; } void Data::setCallNoTo(string callNoTo) {
  • 9.
    this->callNoTo = callNoTo; } PersonData::getClient()const//getters { return (this->client); } string Data::getCallDate()const { return (this->callDate); } bool Data::getLongDistance()const { return(this->longDistance); } string Data::getTimeCallBegin()const { return (this->timeCallBegin); } string Data::getTimeCallEnd()const { return (this->timeCallEnd); } string Data::getCallNoFrom()const { return (this->callNoFrom); } string Data::getCallNoTo()const { return(this->callNoTo); } Data & Data :: operator =(const Data & unData)//asigna los valores { this->client = unData.client; this->callDate = unData.callDate; this->longDistance = unData.longDistance; this->timeCallBegin = unData.timeCallBegin;
  • 10.
    this->timeCallEnd = unData.timeCallEnd; this->callNoFrom= unData.callNoFrom; this->callNoTo = unData.callNoTo; return (*this); } bool Data :: operator ==(const Data & unData)const//verificacion de igualdad de todos los valores { return (this->client == unData.client && this->callDate == unData.callDate && this- >longDistance == unData.longDistance && this->timeCallBegin == unData.timeCallBegin && this->timeCallEnd == unData.timeCallEnd && this->callNoFrom == unData.callNoFrom && this->callNoTo == unData.callNoTo); } ostream & operator <<(ostream & output, const Data & unData)//imprime valores { Person person; output << "Providing Client Information:" << endl; output << person.getFirstName(); output << person.getLastName(); output << person.getMiddleName(); output << person.getMaidenName(); output << endl << "Call Date: " << unData.callDate << endl; output << "longDistance Charge: " << unData.longDistance ? " Y " : " N ";//Yes or No question output << "Time Call Begin: " << unData.timeCallBegin; output << "Time Call End: " << unData.timeCallEnd; output << "Call # From: " << unData.callNoFrom; output << "Call # to: " << unData.callNoTo; return output; } istream & operator >>(istream & input, Data & unData)//pide valores { cout << "Client Information: " << endl; input >> unData.client; cout << "Call Date: " << endl;
  • 11.
    input >> unData.callDate; cout<< " Long Distance: " << endl; input >> unData.longDistance; cout << " Time Call Begin: " << endl; input >> unData.timeCallBegin; cout << " Time Call End: " << endl; input >> unData.timeCallEnd; cout << " Call # From : " << endl; input >> unData.callNoFrom; cout << " Call # To: " << endl; input >> unData.callNoTo; return input; } Person.h #pragma once #include #include using namespace std; class Person { private: string firstName; string lastName; string middleName; string maidenName; public: Person(); Person(string firstName, string lastName, string middleName, string maidenName); Person(const Person & unPerson);//copy constructor ~Person();//destructor void setFirstName(string firsName);//setters void setLastName(string lastName); void setMiddleName(string middleName); void setMaidenName(string maidenName); string getFirstName()const;//getters
  • 12.
    string getLastName()const; string getMiddleName()const; stringgetMaidenName()const; Person & operator = (const Person & unPerson);//operador de asignar valores bool operator ==(const Person & unPerson)const;//operador de igualdad friend ostream & operator <<(ostream & output, const Person & unPerson);//friend operador que imprime friend istream & operator >>(istream & input, Person & unPerson);//friend operador que pide cambia valores }; Person.cpp #include "Person.h" using namespace std; Person::Person()//default cnstructor { firstName = (" ");//valores por default lastName =(" "); middleName =(" "); maidenName = (" "); } Person::Person(string firstName, string lastName, string middleName, string maidenName)//parameter { setFirstName(firstName);//nombrando las variables setLastName(lastName); setMiddleName(middleName); setMaidenName(maidenName); } Person::Person(const Person & unPerson)//copy { firstName = unPerson.firstName;//asignando variables lastName = unPerson.lastName; middleName = unPerson.middleName; maidenName = unPerson.maidenName; } Person::~Person()//destructor
  • 13.
    { } void Person::setFirstName(string firstName)//setters { this->firstName= firstName; } void Person::setLastName(string lastName) { this->lastName = lastName; } void Person::setMiddleName(string middleName) { this->middleName = middleName; } void Person::setMaidenName(string maidenName) { this->maidenName = maidenName; } string Person::getFirstName()const//getters { return (this->firstName); } string Person::getLastName()const { return (this->lastName); } string Person::getMiddleName()const { return (this->middleName); } string Person::getMaidenName()const { return (this->maidenName); } Person & Person:: operator =(const Person & unPerson)//operador que asigna valores {
  • 14.
    this->firstName = unPerson.firstName; this->lastName= unPerson.lastName; this->middleName = unPerson.middleName; this->maidenName = unPerson.maidenName; return (*this);//retorna todos los valores guardados } bool Person:: operator == (const Person & unPerson)const//operador de igualdad y comparacion de valores, verifica que sean iguales { return (this->firstName == unPerson.firstName && this->lastName == unPerson.lastName && this->middleName == unPerson.middleName && this->maidenName == unPerson.maidenName); } ostream & operator <<(ostream & output, const Person & unPerson)//imprime valores { output << " First Name: " << unPerson.firstName; output << " LastName: " << unPerson.lastName; output << "MiddleName: " << unPerson.middleName; output << " Maiden Name: " << unPerson.maidenName; return output; } istream & operator >>(istream & input, Person & unPerson)//cambia o pide valores { cout << " Please Enter First Name t Middle Name t Last Name t Maiden Name " << endl; input >> unPerson.firstName; input >> unPerson.middleName; input >> unPerson.lastName; input >> unPerson.maidenName; return input; } Menu.h #pragma once #include #include
  • 15.
    #include "MyLib.h" using namespace::std; #ifndefMENU_H #define MENU_H enum Choice { numeric, alpha }; enum Lang { eng, spa }; class Menu { private: string * items; string title; int totalItems; Lang lang; Choice choice; int option; flag validate; flag subMenu; public: Menu() { init(); } Menu(const char * title) { init(); this->title = title; } Menu(const Menu & aMenu) { init(); this->title = aMenu.title; if (!aMenu.isEmpty()) { for (int i = 0; i < aMenu.totalItems; ++i) { addItem(aMenu.items[i]); } this->choice = aMenu.choice; this->validate = aMenu.validate;
  • 16.
    this->subMenu = aMenu.subMenu; this->title= aMenu.title; } } void init() { this->items = NULL; this->totalItems = 0; this->lang = eng; this->choice = numeric; this->validate = false; this->subMenu = false; this->title = "Menu"; } ~Menu() { delete[] this->items; } bool isEmpty() const { return this->totalItems == 0; } void addItem(string item) { int idx = this->totalItems; string * tmp; int i; if (isEmpty()) { this->items = new string[1]; } else { tmp = new string[this->totalItems]; for (i = 0; i < this->totalItems; i++) { tmp[i] = this->items[i]; } delete[] this->items; this->items = new string[this->totalItems + 1];
  • 17.
    for (i =0; i < this->totalItems; i++) { this->items[i] = tmp[i]; } delete[] tmp; } this->items[idx] = item; this->totalItems++; } bool check() { if (this->choice == alpha) { this->validate = between(char(option), 'A', char('A' + this->totalItems)); } else { this->validate = between(option, 1, this->totalItems + 1); } return this->validate; } void setChoice(Choice choice) { this->choice = choice; } void setOption(int option) { this->option = upper(option); check(); } void setLang(Lang lang) { this->lang = lang; } void setTitle(string title) { this->title = title; } void setSubMenu(flag subMenu) {
  • 18.
    subMenu = subMenu; } LanggetLanguage() const { return this->lang; } int getOption() const { return this->option; } int getLast() const { if (this->choice == alpha) { return char('A' + this->totalItems); } else { return this->totalItems + 1; } } friend ostream & operator <<(ostream & os, Menu & unMenu) { int i; char ch = 'a'; cls(); os << unMenu.title << endl << endl; for (i = 0; i < unMenu.totalItems; i++) { os << "t"; if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1; os << ".) " << unMenu.items[i] << endl; } os << "t"; if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1; os << ".) "; if (unMenu.lang == eng) { if (unMenu.subMenu) os << "Return";
  • 19.
    else os << "Exit"; os<< " Choose: "; } else { if (unMenu.subMenu) os << "Regresar"; else os << "Salir"; os << " Opcion: "; } return os; } friend istream & operator >>(istream & in, Menu & unMenu) { do { char opt; in >> opt; unMenu.setOption((unMenu.choice == alpha ? opt : opt - '0')); if (!unMenu.check()) { cerr << " Error: Wrong choice!!! "; pause(); cout << unMenu; } } while (!unMenu.check()); return in; } }; #endif // MENU_H mylib.h #pragma once #include #include using namespace::std; #ifndef MYLIB_H
  • 20.
    #define MYLIB_H typedef boolflag; #ifdef WINDOWS #define cls() system("cls") #define pause() system("pause") #elif windows #define cls() system("cls") #define pause() system("pause") #elif LINUX #define cls() system("clear") #define pause() system("sleep 3") #elif linux #define cls() system("clear") #define pause() system("sleep 3") #else #define cls() { cerr << "CLS: Unknown OS!!! "; } #define pause() { cerr << "PAUSE: Unknown OS!!! "; } #endif #define between(x, y, z) ((x >= y && x <= z)? true : false) #define upper(x) (between(x, 'A', 'Z')? x : (between(x, 'a', 'z')? x - 'a' + 'A' : x)) #define lower(x) (between(x, 'a', 'z')? x : x - 'A' + 'a') #endif // MYLIB_H DataParser.h #include "DataParser.h" #include #include"Person.h" #include"Report.h" DataParser::DataParser() { record; } DataParser::DataParser(string line) { parseLine(line); } DataParser::DataParser(const DataParser & unDataParser)
  • 21.
    { this->record = unDataParser.record; this->fecha= unDataParser.fecha; } DataParser::~DataParser() { } Data DataParser::parseLine(string line) { Person client;//atributos de clase Person y Data string callDate; bool longDistance; string timeCallBegin; string timeCallEnd; string callNoFrom; string callNoTo; string firstName; string lastName; string middleName; string maidenName; //substr demostrara en que linea firstName = line.substr(0, 25); middleName = line.substr(25, 25); lastName = line.substr(50, 50); maidenName = line.substr(100, 50); callDate = line.substr(150, 8); if (line.substr(158, 1) == "Y")//yes or no longDistance = true; else longDistance = false; timeCallBegin = line.substr(159, 6); timeCallEnd = line.substr(165, 6); callNoFrom = line.substr(171, 10); callNoTo = line.substr(181, 10); record.setClient(Person(firstName, middleName, lastName, maidenName));
  • 22.
    record.setCallDate(callDate); record.setLongDistance(longDistance); record.setTimeCallBegin(timeCallBegin); record.setTimeCallEnd(timeCallEnd); record.setCallNoFrom(callNoFrom); record.setCallNoTo(callNoTo); return record; } void DataParser::setRecord(stringline) { parseLine(line); } Data DataParser::getRecord() const { return (this->record); } string DataParser::date(string date) { string fecha; fecha = date.substr(191, 2) + "/" + date.substr(193, 2) + "/" + date.substr(195, 4); return fecha; } void DataParser::setFecha(int fecha) { this->fecha = fecha; } int DataParser::getFecha()const { return(this->fecha); } DataParser.h #pragma once #include #include #include "Data.h" using namespace std;
  • 23.
    class DataParser { private: Data record; intfecha; public: DataParser(); DataParser(string line); DataParser(const DataParser & unDataPaser); ~DataParser(); void setRecord(string line); void setFecha(int fecha); int getFecha()const; Data getRecord()const; Data parseLine(string line); string date(string date); // friend ostream & operator <<(ostream & os, const DataParser & unDataParser); // friend istream & operator >> (istream & is, DataParser & unDataParser); }; Report.cpp #include "Report.h" Report::Report() { records = NULL; totalRecords = 0; totalMinutes = 0.0; totalAmmount = 0.0; fileName=(" "); } Report::Report(Data records, int totalRecords, float totalMinutes, float totalAmmount, string fileName) { setTotalRecords(totalRecords); setTotalMinutes(totalMinutes); setTotalAmmount(totalAmmount);
  • 24.
    setFileName(fileName); } void Report::addRecord(const Data& unData) { Data *records; records = new Data[this->totalRecords + 1]; for (int i = 0;i < this->totalRecords;i++) { records[this->totalRecords] = unData; delete[](this->records); this->records = records; ++(this->records); } } Report::Report(const Report & unReport) { this->records = NULL; totalRecords = unReport.totalRecords; totalMinutes = unReport.totalMinutes; totalAmmount = unReport.totalAmmount; fileName = unReport.fileName; (*this) = unReport; } Report::~Report() { delete[](this->records); } void Report::setTotalRecords(int totalRecords) { this->totalRecords = totalRecords; } void Report::setTotalAmmount(float totalAmmount) { this->totalAmmount = totalAmmount; } void Report::setTotalMinutes(float totalMinutes)
  • 25.
    { this->totalMinutes = totalMinutes; } voidReport::setFileName(string fileName) { this->fileName = fileName; } const Data & Report::operator[](int indice)const { return((this->records)[indice]); } Data Report::getRecords()const { for (int i = 0;i < totalRecords;i++) { return (records[i]); } } int Report::getTotalRecords()const { return this->totalRecords; } float Report::getTotalAmmount()const { return this->totalAmmount; } float Report::getTotalMinutes()const { return this->totalMinutes; } string Report::getFileName()const { return this->fileName; } Report & Report::operator =(const Report & unReport) {
  • 26.
    delete[](this->records); if (unReport.totalRecords >0) { this->records = new Data[unReport.totalRecords]; for (int i = 0;i < unReport.totalRecords;i++) { (this->records[i] = (unReport.records)[i]); } } else { this->records = NULL; } this->totalAmmount = unReport.totalAmmount; this->totalMinutes = unReport.totalMinutes; this->fileName = unReport.fileName; return (*this); } bool Report::operator ==(const Report & unReport)const { bool record = false; for (int i = 0;i < unReport.totalRecords;i++) { if (records[i] == unReport.records[i]) { record = true; } return record; } return (this->totalRecords == unReport.totalRecords && this->totalAmmount == unReport.totalAmmount && this->totalMinutes == unReport.totalMinutes && this->fileName == unReport.fileName); } ostream & operator <<(ostream & os, const Report & unReport) { for (int i = 0; i < unReport.totalRecords;i++)
  • 27.
    { os << "Recordnumber is: " << unReport.records[i] << endl; } return os; } istream & operator >>(istream & is, Report & unReport) { cout << "Enter record:" << unReport.records << endl;; cout << "Total Records are: "; is >> unReport.totalRecords; cout << "Total Ammount: "; is >> unReport.totalAmmount; cout << "Total Minutes:"; is >> unReport.totalMinutes; cout << "File name is: "; is >> unReport.fileName; return is; } Report.h #pragma once #include"Data.h" #include #include using namespace std; class Report { private: Data *records; int totalRecords; float totalMinutes; float totalAmmount; string fileName; public: Report(); Report(Data records,int totalRecords, float totalMinutes, float totalAmmount, string fileName);
  • 28.
    Report(const Report &unReport); ~Report(); void addRecord(const Data & unData); void setTotalRecords(int totalRecords); void setTotalMinutes(float totalMinutes); void setTotalAmmount(float totalAmmount); void setFileName(string fileName); const Data & operator[](int indice)const; Data getRecords()const; int getTotalRecords()const; float getTotalMinutes()const; float getTotalAmmount()const; string getFileName()const; Report & operator = (const Report & unReport); bool operator ==(const Report & unReport)const; friend ostream & operator<<(ostream & os, const Report & unReport); friend istream & operator>>(istream & is, Report & unReport); }; Solution #include #include"Data.h" #include"Person.h" #include"Report.h" #include #include #include "Menu.h" using namespace std; /* Programmers: Javier A. Molina, Eduardo Bonnet Students #:79249 */ int main() {
  • 29.
    int cnt; int idx; stringfileName; Report * telefonia; Menu menu("Reports"); bool fileNameExists(string fileName); Report * addReport(Report * reports, int & totalReports); Report * delReport(Report * reports, int & totalReports, int idx); int displayReports(Report * reports, int totalReports); menu.addItem("New report"); menu.addItem("Delete a report"); menu.addItem("Display a report"); cnt = 0; telefonia = NULL; do { cout << menu; cin >> menu; //cls(); switch (menu.getOption()) { case 1: cout << "Enter report name (TE?????): "; cin >> fileName; if (fileNameExists(fileName + ".tel")) { telefonia = addReport(telefonia, cnt); idx = cnt - 1; telefonia[idx].setFileName(fileName); // telefonia[idx].loadReport(); } else { cls(); cerr << "Error: Report name '" << fileName << "' does not exists! "; //pause(); } break; case 2: if (telefonia != NULL) {
  • 30.
    do { cls(); cout <<"Delete a Report: "; idx = displayReports(telefonia, cnt); if (between(idx, 0, cnt - 1)) { cls(); telefonia = delReport(telefonia, cnt, idx); idx = 0; // pause(); } } while (idx != cnt); } else { cerr << "No reports available for deleting! "; //pause(); } break; case 3: char ans; if (telefonia != NULL) { do { // cls(); cout << "Display/Filed a Report: "; idx = displayReports(telefonia, cnt); if (between(idx, 0, cnt - 1)) { // cls(); cout << "Would you like the report to be display otherwise save into a file? "; cin >> ans; cls(); cin.ignore(); if (upper(ans) == 'Y') { cout << telefonia[idx] << endl; } else { //telefonia[idx].saveReport(); cout << "Report '" << telefonia[idx].getFileName() << "' saved as '" <<
  • 31.
    telefonia[idx].getFileName() << ".rep'. "; } //pause(); } } while (idx != cnt); } else { cerr << "No reports available for displaying! "; // pause(); } break; case 4: cout << "Thanks for using Telefonia Reports System!!! "; break; } } while (menu.getLast() != menu.getOption()); delete[] telefonia; return 0; } //Funcion que verifica si existe un archivo en disco bool fileNameExists(string fileName) { ifstream fin(fileName.c_str()); bool exists = !(fin.fail()); if (exists) fin.close(); return(exists); } //Anade dinamicamente objetos tipo Report al arreglo reports Report * addReport(Report * reports, int & totalReports) { if (totalReports == 0) { reports = new Report[1]; } else { Report * tmp = new Report[totalReports]; for (int i = 0; i < totalReports; ++i) { tmp[i] = reports[i]; }
  • 32.
    delete[] reports; reports =new Report[totalReports + 1]; for (int i = 0; i < totalReports; ++i) { reports[i] = tmp[i]; } delete[] tmp; } totalReports++; return(reports); } //Borra objetos del arreglo reports segun el idx enviado Report * delReport(Report * reports, int & totalReports, int idx) { Report * tmp = new Report[totalReports - 1]; string fileName = reports[idx].getFileName(); for (int i = 0, j = 0; i < totalReports; ++i) { if (i == idx) continue; tmp[j] = reports[i]; j++; } delete[] reports; totalReports--; reports = new Report[totalReports]; for (int i = 0; i < totalReports; ++i) { reports[i] = tmp[i]; } delete[] tmp; cout << "Report '" << fileName << "' has been deleted! " << endl; if (totalReports == 0) reports = NULL; return(reports); } //Muestra en pantalla la lista de informes que se encuantran en memoria int displayReports(Report * reports, int totalReports) { int choice; int i; for (i = 0; i < totalReports; ++i) { cout << "t" << (i + 1) << ".) " << reports[i].getFileName() << endl;
  • 33.
    } cout << "t"<< (i + 1) << ".) Return "; cout << " tChoice: "; cin >> choice; return (choice - 1); } Data.h #include #include #include #ifndef DATA_H #define DATA_H #include "Person.h" using namespace std; #pragma once //Trata de establecer coneccion entre la clase data y person, utilizando informacion de la clase person busca informacion de las llamadas hechas por el cliente //Person(client) con esto saca la informacion de los datos escritos en la clase class Data { private: Person client;//atributo de la clase person string callDate;//atributos esenciales de la clase Data bool longDistance; string timeCallBegin; string timeCallEnd; string callNoFrom; string callNoTo; public: Data();//default Data(Person client, string callDate, bool longDistance, string timeCallBegin, string timeCallEnd, string callNoFrom, string callNoTo);//parameter constructor Data(const Data & unData);//copy constructor ~Data();//destructor void setClient(const Person & client);//setters void setCallDate(string callDate);
  • 34.
    void setLongDistance(bool longDistance); voidsetTimeCallBegin(string timeCallBegin); void setTimeCallEnd(string timeCallEnd); void setCallNoFrom(string callNoFrom); void setCallNoTo(string callNoTo); Person getClient()const;//getters string getCallDate()const; bool getLongDistance()const; string getTimeCallBegin()const; string getTimeCallEnd()const; string getCallNoFrom()const; string getCallNoTo()const; Data & operator = (const Data & unData);//operador de asignar bool operator ==(const Data & unData)const;//operador de igualdad friend ostream & operator <<(ostream & output, const Data & unData);//friend operador, imprime valores friend istream & operator >>(istream & input, Data & unData);//friend operator, manipula los valores de los atributos }; #endif // DATA_H Data.cpp #include "Data.h" using namespace std; Data::Data()//default { setClient(Person(" "," "," "," ")); setCallDate(" ");//valores asignados por default setLongDistance(false); setTimeCallBegin(" "); setTimeCallEnd(" "); setCallNoFrom(" "); setCallNoTo(" "); } Data::Data (Person client, string callDate, bool longDistance, string timeCallBegin, string timeCallEnd, string callNoFrom, string callNoTo)//parameter constructor
  • 35.
    { setClient(client); setCallDate(callDate); setLongDistance(longDistance); setTimeCallBegin(timeCallBegin); setTimeCallEnd(timeCallEnd); setCallNoFrom(callNoFrom); setCallNoTo(callNoTo); } Data::Data(const Data &unData)//copy constructor { this->client = unData.client; this->callDate = unData.callDate; this->longDistance = unData.longDistance; this->timeCallBegin = unData.timeCallBegin; this->timeCallEnd = unData.timeCallEnd; this->callNoFrom = unData.callNoFrom; this->callNoTo = unData.callNoTo; } Data::~Data()//destructor { } void Data::setClient(const Person & client)//setters { this->client = client; } void Data::setCallDate(string callDate) { this->callDate = callDate; } void Data::setLongDistance(bool longDistance) { if (longDistance == 1)//verificacion del valor para clasificar en true or false { longDistance = true; this->longDistance = longDistance;
  • 36.
    } else { longDistance = false; this->longDistance= longDistance; } } void Data::setTimeCallBegin(string timeCallBegin) { this->timeCallBegin = timeCallBegin; } void Data::setTimeCallEnd(string timeCallEnd) { this->timeCallEnd = timeCallEnd; } void Data::setCallNoFrom(string callNoFrom) { this->callNoFrom = callNoFrom; } void Data::setCallNoTo(string callNoTo) { this->callNoTo = callNoTo; } Person Data::getClient()const//getters { return (this->client); } string Data::getCallDate()const { return (this->callDate); } bool Data::getLongDistance()const { return(this->longDistance); } string Data::getTimeCallBegin()const
  • 37.
    { return (this->timeCallBegin); } string Data::getTimeCallEnd()const { return(this->timeCallEnd); } string Data::getCallNoFrom()const { return (this->callNoFrom); } string Data::getCallNoTo()const { return(this->callNoTo); } Data & Data :: operator =(const Data & unData)//asigna los valores { this->client = unData.client; this->callDate = unData.callDate; this->longDistance = unData.longDistance; this->timeCallBegin = unData.timeCallBegin; this->timeCallEnd = unData.timeCallEnd; this->callNoFrom = unData.callNoFrom; this->callNoTo = unData.callNoTo; return (*this); } bool Data :: operator ==(const Data & unData)const//verificacion de igualdad de todos los valores { return (this->client == unData.client && this->callDate == unData.callDate && this- >longDistance == unData.longDistance && this->timeCallBegin == unData.timeCallBegin && this->timeCallEnd == unData.timeCallEnd && this->callNoFrom == unData.callNoFrom && this->callNoTo == unData.callNoTo); } ostream & operator <<(ostream & output, const Data & unData)//imprime valores
  • 38.
    { Person person; output <<"Providing Client Information:" << endl; output << person.getFirstName(); output << person.getLastName(); output << person.getMiddleName(); output << person.getMaidenName(); output << endl << "Call Date: " << unData.callDate << endl; output << "longDistance Charge: " << unData.longDistance ? " Y " : " N ";//Yes or No question output << "Time Call Begin: " << unData.timeCallBegin; output << "Time Call End: " << unData.timeCallEnd; output << "Call # From: " << unData.callNoFrom; output << "Call # to: " << unData.callNoTo; return output; } istream & operator >>(istream & input, Data & unData)//pide valores { cout << "Client Information: " << endl; input >> unData.client; cout << "Call Date: " << endl; input >> unData.callDate; cout << " Long Distance: " << endl; input >> unData.longDistance; cout << " Time Call Begin: " << endl; input >> unData.timeCallBegin; cout << " Time Call End: " << endl; input >> unData.timeCallEnd; cout << " Call # From : " << endl; input >> unData.callNoFrom; cout << " Call # To: " << endl; input >> unData.callNoTo; return input; } Person.h
  • 39.
    #pragma once #include #include using namespacestd; class Person { private: string firstName; string lastName; string middleName; string maidenName; public: Person(); Person(string firstName, string lastName, string middleName, string maidenName); Person(const Person & unPerson);//copy constructor ~Person();//destructor void setFirstName(string firsName);//setters void setLastName(string lastName); void setMiddleName(string middleName); void setMaidenName(string maidenName); string getFirstName()const;//getters string getLastName()const; string getMiddleName()const; string getMaidenName()const; Person & operator = (const Person & unPerson);//operador de asignar valores bool operator ==(const Person & unPerson)const;//operador de igualdad friend ostream & operator <<(ostream & output, const Person & unPerson);//friend operador que imprime friend istream & operator >>(istream & input, Person & unPerson);//friend operador que pide cambia valores }; Person.cpp #include "Person.h" using namespace std; Person::Person()//default cnstructor {
  • 40.
    firstName = ("");//valores por default lastName =(" "); middleName =(" "); maidenName = (" "); } Person::Person(string firstName, string lastName, string middleName, string maidenName)//parameter { setFirstName(firstName);//nombrando las variables setLastName(lastName); setMiddleName(middleName); setMaidenName(maidenName); } Person::Person(const Person & unPerson)//copy { firstName = unPerson.firstName;//asignando variables lastName = unPerson.lastName; middleName = unPerson.middleName; maidenName = unPerson.maidenName; } Person::~Person()//destructor { } void Person::setFirstName(string firstName)//setters { this->firstName = firstName; } void Person::setLastName(string lastName) { this->lastName = lastName; } void Person::setMiddleName(string middleName) { this->middleName = middleName; } void Person::setMaidenName(string maidenName)
  • 41.
    { this->maidenName = maidenName; } stringPerson::getFirstName()const//getters { return (this->firstName); } string Person::getLastName()const { return (this->lastName); } string Person::getMiddleName()const { return (this->middleName); } string Person::getMaidenName()const { return (this->maidenName); } Person & Person:: operator =(const Person & unPerson)//operador que asigna valores { this->firstName = unPerson.firstName; this->lastName = unPerson.lastName; this->middleName = unPerson.middleName; this->maidenName = unPerson.maidenName; return (*this);//retorna todos los valores guardados } bool Person:: operator == (const Person & unPerson)const//operador de igualdad y comparacion de valores, verifica que sean iguales { return (this->firstName == unPerson.firstName && this->lastName == unPerson.lastName && this->middleName == unPerson.middleName && this->maidenName == unPerson.maidenName); } ostream & operator <<(ostream & output, const Person & unPerson)//imprime valores
  • 42.
    { output << "First Name: " << unPerson.firstName; output << " LastName: " << unPerson.lastName; output << "MiddleName: " << unPerson.middleName; output << " Maiden Name: " << unPerson.maidenName; return output; } istream & operator >>(istream & input, Person & unPerson)//cambia o pide valores { cout << " Please Enter First Name t Middle Name t Last Name t Maiden Name " << endl; input >> unPerson.firstName; input >> unPerson.middleName; input >> unPerson.lastName; input >> unPerson.maidenName; return input; } Menu.h #pragma once #include #include #include "MyLib.h" using namespace::std; #ifndef MENU_H #define MENU_H enum Choice { numeric, alpha }; enum Lang { eng, spa }; class Menu { private: string * items; string title; int totalItems; Lang lang; Choice choice; int option; flag validate;
  • 43.
    flag subMenu; public: Menu() { init(); } Menu(const char* title) { init(); this->title = title; } Menu(const Menu & aMenu) { init(); this->title = aMenu.title; if (!aMenu.isEmpty()) { for (int i = 0; i < aMenu.totalItems; ++i) { addItem(aMenu.items[i]); } this->choice = aMenu.choice; this->validate = aMenu.validate; this->subMenu = aMenu.subMenu; this->title = aMenu.title; } } void init() { this->items = NULL; this->totalItems = 0; this->lang = eng; this->choice = numeric; this->validate = false; this->subMenu = false; this->title = "Menu"; } ~Menu() {
  • 44.
    delete[] this->items; } bool isEmpty()const { return this->totalItems == 0; } void addItem(string item) { int idx = this->totalItems; string * tmp; int i; if (isEmpty()) { this->items = new string[1]; } else { tmp = new string[this->totalItems]; for (i = 0; i < this->totalItems; i++) { tmp[i] = this->items[i]; } delete[] this->items; this->items = new string[this->totalItems + 1]; for (i = 0; i < this->totalItems; i++) { this->items[i] = tmp[i]; } delete[] tmp; } this->items[idx] = item; this->totalItems++; } bool check() { if (this->choice == alpha) { this->validate = between(char(option), 'A', char('A' + this->totalItems)); } else { this->validate = between(option, 1, this->totalItems + 1);
  • 45.
    } return this->validate; } void setChoice(Choicechoice) { this->choice = choice; } void setOption(int option) { this->option = upper(option); check(); } void setLang(Lang lang) { this->lang = lang; } void setTitle(string title) { this->title = title; } void setSubMenu(flag subMenu) { subMenu = subMenu; } Lang getLanguage() const { return this->lang; } int getOption() const { return this->option; } int getLast() const { if (this->choice == alpha) { return char('A' + this->totalItems); }
  • 46.
    else { return this->totalItems+ 1; } } friend ostream & operator <<(ostream & os, Menu & unMenu) { int i; char ch = 'a'; cls(); os << unMenu.title << endl << endl; for (i = 0; i < unMenu.totalItems; i++) { os << "t"; if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1; os << ".) " << unMenu.items[i] << endl; } os << "t"; if (unMenu.choice == alpha) os << char(ch + i); else os << i + 1; os << ".) "; if (unMenu.lang == eng) { if (unMenu.subMenu) os << "Return"; else os << "Exit"; os << " Choose: "; } else { if (unMenu.subMenu) os << "Regresar"; else os << "Salir"; os << " Opcion: "; } return os; } friend istream & operator >>(istream & in, Menu & unMenu) {
  • 47.
    do { char opt; in>> opt; unMenu.setOption((unMenu.choice == alpha ? opt : opt - '0')); if (!unMenu.check()) { cerr << " Error: Wrong choice!!! "; pause(); cout << unMenu; } } while (!unMenu.check()); return in; } }; #endif // MENU_H mylib.h #pragma once #include #include using namespace::std; #ifndef MYLIB_H #define MYLIB_H typedef bool flag; #ifdef WINDOWS #define cls() system("cls") #define pause() system("pause") #elif windows #define cls() system("cls") #define pause() system("pause") #elif LINUX #define cls() system("clear") #define pause() system("sleep 3") #elif linux #define cls() system("clear") #define pause() system("sleep 3") #else
  • 48.
    #define cls() {cerr << "CLS: Unknown OS!!! "; } #define pause() { cerr << "PAUSE: Unknown OS!!! "; } #endif #define between(x, y, z) ((x >= y && x <= z)? true : false) #define upper(x) (between(x, 'A', 'Z')? x : (between(x, 'a', 'z')? x - 'a' + 'A' : x)) #define lower(x) (between(x, 'a', 'z')? x : x - 'A' + 'a') #endif // MYLIB_H DataParser.h #include "DataParser.h" #include #include"Person.h" #include"Report.h" DataParser::DataParser() { record; } DataParser::DataParser(string line) { parseLine(line); } DataParser::DataParser(const DataParser & unDataParser) { this->record = unDataParser.record; this->fecha = unDataParser.fecha; } DataParser::~DataParser() { } Data DataParser::parseLine(string line) { Person client;//atributos de clase Person y Data string callDate; bool longDistance; string timeCallBegin; string timeCallEnd; string callNoFrom;
  • 49.
    string callNoTo; string firstName; stringlastName; string middleName; string maidenName; //substr demostrara en que linea firstName = line.substr(0, 25); middleName = line.substr(25, 25); lastName = line.substr(50, 50); maidenName = line.substr(100, 50); callDate = line.substr(150, 8); if (line.substr(158, 1) == "Y")//yes or no longDistance = true; else longDistance = false; timeCallBegin = line.substr(159, 6); timeCallEnd = line.substr(165, 6); callNoFrom = line.substr(171, 10); callNoTo = line.substr(181, 10); record.setClient(Person(firstName, middleName, lastName, maidenName)); record.setCallDate(callDate); record.setLongDistance(longDistance); record.setTimeCallBegin(timeCallBegin); record.setTimeCallEnd(timeCallEnd); record.setCallNoFrom(callNoFrom); record.setCallNoTo(callNoTo); return record; } void DataParser::setRecord(string line) { parseLine(line); } Data DataParser::getRecord() const { return (this->record);
  • 50.
    } string DataParser::date(string date) { stringfecha; fecha = date.substr(191, 2) + "/" + date.substr(193, 2) + "/" + date.substr(195, 4); return fecha; } void DataParser::setFecha(int fecha) { this->fecha = fecha; } int DataParser::getFecha()const { return(this->fecha); } DataParser.h #pragma once #include #include #include "Data.h" using namespace std; class DataParser { private: Data record; int fecha; public: DataParser(); DataParser(string line); DataParser(const DataParser & unDataPaser); ~DataParser(); void setRecord(string line); void setFecha(int fecha); int getFecha()const; Data getRecord()const; Data parseLine(string line);
  • 51.
    string date(string date); //friend ostream & operator <<(ostream & os, const DataParser & unDataParser); // friend istream & operator >> (istream & is, DataParser & unDataParser); }; Report.cpp #include "Report.h" Report::Report() { records = NULL; totalRecords = 0; totalMinutes = 0.0; totalAmmount = 0.0; fileName=(" "); } Report::Report(Data records, int totalRecords, float totalMinutes, float totalAmmount, string fileName) { setTotalRecords(totalRecords); setTotalMinutes(totalMinutes); setTotalAmmount(totalAmmount); setFileName(fileName); } void Report::addRecord(const Data & unData) { Data *records; records = new Data[this->totalRecords + 1]; for (int i = 0;i < this->totalRecords;i++) { records[this->totalRecords] = unData; delete[](this->records); this->records = records; ++(this->records); } } Report::Report(const Report & unReport)
  • 52.
    { this->records = NULL; totalRecords= unReport.totalRecords; totalMinutes = unReport.totalMinutes; totalAmmount = unReport.totalAmmount; fileName = unReport.fileName; (*this) = unReport; } Report::~Report() { delete[](this->records); } void Report::setTotalRecords(int totalRecords) { this->totalRecords = totalRecords; } void Report::setTotalAmmount(float totalAmmount) { this->totalAmmount = totalAmmount; } void Report::setTotalMinutes(float totalMinutes) { this->totalMinutes = totalMinutes; } void Report::setFileName(string fileName) { this->fileName = fileName; } const Data & Report::operator[](int indice)const { return((this->records)[indice]); } Data Report::getRecords()const { for (int i = 0;i < totalRecords;i++) {
  • 53.
    return (records[i]); } } int Report::getTotalRecords()const { returnthis->totalRecords; } float Report::getTotalAmmount()const { return this->totalAmmount; } float Report::getTotalMinutes()const { return this->totalMinutes; } string Report::getFileName()const { return this->fileName; } Report & Report::operator =(const Report & unReport) { delete[](this->records); if (unReport.totalRecords > 0) { this->records = new Data[unReport.totalRecords]; for (int i = 0;i < unReport.totalRecords;i++) { (this->records[i] = (unReport.records)[i]); } } else { this->records = NULL; } this->totalAmmount = unReport.totalAmmount; this->totalMinutes = unReport.totalMinutes;
  • 54.
    this->fileName = unReport.fileName; return(*this); } bool Report::operator ==(const Report & unReport)const { bool record = false; for (int i = 0;i < unReport.totalRecords;i++) { if (records[i] == unReport.records[i]) { record = true; } return record; } return (this->totalRecords == unReport.totalRecords && this->totalAmmount == unReport.totalAmmount && this->totalMinutes == unReport.totalMinutes && this->fileName == unReport.fileName); } ostream & operator <<(ostream & os, const Report & unReport) { for (int i = 0; i < unReport.totalRecords;i++) { os << "Record number is: " << unReport.records[i] << endl; } return os; } istream & operator >>(istream & is, Report & unReport) { cout << "Enter record:" << unReport.records << endl;; cout << "Total Records are: "; is >> unReport.totalRecords; cout << "Total Ammount: "; is >> unReport.totalAmmount; cout << "Total Minutes:"; is >> unReport.totalMinutes; cout << "File name is: ";
  • 55.
    is >> unReport.fileName; returnis; } Report.h #pragma once #include"Data.h" #include #include using namespace std; class Report { private: Data *records; int totalRecords; float totalMinutes; float totalAmmount; string fileName; public: Report(); Report(Data records,int totalRecords, float totalMinutes, float totalAmmount, string fileName); Report(const Report & unReport); ~Report(); void addRecord(const Data & unData); void setTotalRecords(int totalRecords); void setTotalMinutes(float totalMinutes); void setTotalAmmount(float totalAmmount); void setFileName(string fileName); const Data & operator[](int indice)const; Data getRecords()const; int getTotalRecords()const; float getTotalMinutes()const; float getTotalAmmount()const; string getFileName()const; Report & operator = (const Report & unReport); bool operator ==(const Report & unReport)const;
  • 56.
    friend ostream &operator<<(ostream & os, const Report & unReport); friend istream & operator>>(istream & is, Report & unReport); };