1. #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?????): ";
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 = 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:
6. 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
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 << "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);
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;
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) {
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);
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
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;