To write a program that implements the following C concepts
To write a program that implements the following C++ concepts 1. Data Encapsulation 2. Instantiate classes 3. Composition Class 4. Aggregation Class 5. Dynamic Memory 6. File Stream Make a program that reads a file and can generate reports. Each file will have phone calls records (see section 4). The program will process the data gathering all minutes and total amount for each report. The program should have a menu (see section 1): 1. New Report – this option will ask a file name (TE??????.tel). This option will instantiate an object of Report class, loading the whole file into memory. 2. Delete a report – this option will display all reports available in memory and ask which one you would like to delete. 3. Display a report – this option will display all reports available in memory and ask you which one you would like to generate a report. 4. Exit – Program ends. For option 1, you do not know how many reports are, meaning that you will create dynamically the reports. For long distance calls the formula will be (minutes call x $1.50). For local phone calls the formula will be (minutes call x $0.25)
------------------------------------------------------------------------------------------------------------------------------------------------
//Main.cpp
*#define between(x,y,z) ((x>=y && x<=z)? true:false)
#include<iostream>
#include<string>
#include<fstream>
#include \"Data.h\"
#include \"Report.h\"
#include \"Menu.h\"
using namespace std;
//uses class Report to create reports
//uses class Menu to display a menu to choose
int main() {
int idx = 0;
int count = idx;
Menu menu(\"Reports\");
Data temp;
string fileName;
Report* phoneCompany;
Report* newReport(Report*, int&);
Report* deleteReport(Report*, int&, int);
int displayReport(Report*, int);
bool fileNameExists(string);
menu.addMenuItem(\"New Report\");
menu.addMenuItem(\"Delete a Report\");
menu.addMenuItem(\"Display a Report\");
ofstream openFile;
phoneCompany = NULL;
phoneCompany = new Report[count];
do {
cout << menu;
cin >> menu;
switch (menu.getChoice()) {
case \'1\':
cout << \"\ \\tEnter report name (TE??????): \";
cin >> fileName;
openFile.open(fileName + \".tel\");
if (openFile.good()) {
cout << \"\ \\tReport succesfully created.\ \";
phoneCompany[count].setFileName(fileName);
count++;
}
else {
cout << \"\ \\terror: Could not create report.\ \";
}
break;
case \'2\':
if (count != 0) {
do {
system(\"cls\");
cout << \"\ \ \\tDelete a Report:\ \ \";
idx = displayReport(phoneCompany, count);
if (between(idx, 0, count - 1)) {
phoneCompany = deleteReport(phoneCompany, count, idx);
idx = 0;
}
else
cout << \"\ \\terror: Report could not be deleted.\ \";
} while (idx != count);
}
else {
cout << \"\ \ \\tNo reports to delete.\ \ \";
system(\"pause\");
}
break;
case \'3\':
if (count != 0) {
do {
system(\"cls\");
cout << \"Display a Report:\ \ \";
idx = displayReport(phoneCompany, count);
system(\"cls\");
cout << \"\ \\t\" << phoneCompany[idx].getFileName();
cout << \"\ \ \\tWould you like to edit the report?\";
cout << \"\ \\t1. Yes\";
cout << \"\ \\t2. No\";
char ch;
cin >> ch;
do {
switch (ch) {
case \'1\':
cin >> temp;
phoneCompany[idx].setRecord(temp);
case \'2\':
cout << phoneCompany[idx];
default:
cin.ignore();
break;
}
} while (ch != \'2\');
} while (idx != count);
}
else {
cout << \"\ \ \\tNo reports to display.\ \ \";
system(\"pause\");
}
break;
case \'4\':
cout << \"\\tThank you for using this Report System.\ \ \";
break;
default:
cin.ignore();
break;
}
} while (menu.getChoice() != 4);
delete[]phoneCompany;
system(\"pause\");
}
Report* newReport(Report* report, int& total) {
if (total == 0) {
report = new Report[1];
}
else {
Report* temp = new Report[total];
for (int i = 0; i < total; i++) {
temp[i] = report[i];
}
delete[]report;
report = new Report[total + 1];
for (int i = 0; i < total; i++) {
report[i] = temp[i];
}
delete[]temp;
}
total++;
return report;
}
Report* deleteReport(Report* report, int& total, int idx) {
Report* temp = new Report[total - 1];
string fileName = report[idx].getFileName();
for (int i = 0; i < total; i++) {
temp[i] = report[i];
}
delete[]report;
total--;
report = new Report[total];
for (int i = 0; i < total; i++) {
report[i] = temp[i];
}
delete[]temp;
cout << \"Report \" << fileName << \" has been deleted.\ \ \";
if (total == 0)
report = NULL;
return report;
}
int displayReports(Report* report, int total) {
int choice;
int i;
for (i = 0; i < total; i++) {
cout << \"\\t\" << i + 1 << \". \" << report[i].getFileName() << endl;
}
cout << \"\\t\" << i + 1 << \". Return\ \ \";
cout << \"Choose: \";
cin >> choice;
return (choice - 1);
}*/
// Report.h
#pragma once
#include<iostream>
#include<string>
#include \"Data.h\"
using namespace std;
//uses class Data to create a dynamic array containing client phone information
class Report {
friend ostream&operator<<(ostream&, const Report&);
private:
Data* records;
string fileName;
int totalRecords;
float totalMinutes;
float totalAmount;
public:
Report();
Report(const Data&, string);
Report(const Report&);
~Report();
void setRecord(const Data&);
void setFileName(string);
void setTotalMinutes(float);
void setTotalAmount(int);
Data getRecord(int)const;
string getFileName()const;
int getTotalRecords()const;
float getTotalMinutes()const;
float getTotalAmount()const;
};
//Report.cpp
#include<iostream>
#include<string>
#include \"Data.h\"
#include \"Report.h\"
using namespace std;
ostream&operator<<(ostream& output, const Report& aReport) {
for (int i = 0; i < aReport.getTotalRecords(); i++) {
output << \"Report number is: \" << aReport.getRecord(i) << endl;
}
return output;
}
Report::Report() {
totalRecords = 0;
fileName = \"\";
}
Report::Report(const Data& aData, string name) {
records[0] = aData;
fileName = name;
totalRecords = 1;
}
Report::Report(const Report& aReport) {
setRecord(*aReport.records);
setFileName(aReport.fileName);
setTotalMinutes(aReport.totalMinutes);
setTotalAmount(aReport.totalAmount);
}
Report::~Report() {}
void Report::setRecord(const Data& aData) {
int idx = totalRecords;
if (totalRecords == 0) {
records = new Data[1];
}
else {
Data* temp = new Data[totalRecords];
for (int i = 0; i < totalRecords; i++) {
temp[i] = records[i];
}
delete[]records;
records = new Data[totalRecords + 1];
for (int i = 0; i < totalRecords; i++) {
records[i] = temp[i];
}
delete[]temp;
}
records[idx] = aData;
totalRecords++;
}
void Report::setFileName(string name) {
fileName = name;
}
void Report::setTotalMinutes(float minutes) {
totalMinutes = minutes;
}
void Report::setTotalAmount(int idx) {
if (records[idx].getLongDistance() == 1) {
totalAmount = getTotalMinutes()*1.25;
}
else {
totalAmount = getTotalMinutes()*0.25;
}
}
Data Report::getRecord(int idx)const {
return records[idx];
}
string Report::getFileName()const {
return fileName;
}
int Report::getTotalRecords()const {
return totalRecords;
}
float Report::getTotalMinutes()const {
return totalMinutes;
}
float Report::getTotalAmount()const {
return totalAmount;
}
// Person.h
#pragma once
#include<string>
using namespace std;
//stores a Persons\' information
class Person {
friend ostream&operator<<(ostream&, const Person&);
friend istream&operator>>(istream&, Person&);
private:
string firstName;
string middleName;
string lastName;
string maidenName;
public:
Person();
Person(string, string, string, string);
Person(const Person&);
~Person();
void setFirstName(string);
void setMiddleName(string);
void setLastName(string);
void setMaidenName(string);
string getFirstName()const;
string getMiddleName()const;
string getLastName()const;
string getMaidenName()const;
};
//Person.cpp
#include<iostream>
#include<string>
#include \"Person.h\"
using namespace std;
ostream & operator <<(ostream & output, const Person & aPerson) {
output << \" First Name: \ \" << aPerson.firstName;
output << \" LastName: \ \" << aPerson.lastName;
output << \"MiddleName:\ \" << aPerson.middleName;
output << \" Maiden Name:\ \" << aPerson.maidenName;
return output;
}
istream & operator >>(istream & input, Person & aPerson) {
cout << \"\ \\tEnter First Name, Middle Name, Last Name, and Maiden Name \" << endl;
input >> aPerson.firstName;
input >> aPerson.middleName;
input >> aPerson.lastName;
input >> aPerson.maidenName;
return input;
}
Person::Person() {
firstName = \"\";
middleName = \"\";
lastName = \"\";
maidenName = \"\";
}
Person::Person(string first, string middle, string last, string maiden) {
firstName = first;
middleName = middle;
lastName = last;
maidenName = maiden;
}
Person::Person(const Person & aPerson) {
setFirstName(aPerson.firstName);
setMiddleName(aPerson.middleName);
setLastName(aPerson.lastName);
setMaidenName(aPerson.maidenName);
}
Person::~Person(){}
void Person::setFirstName(string first) {
firstName = first;
}
void Person::setMiddleName(string middle) {
middleName = middle;
}
void Person::setLastName(string last) {
lastName = last;
}
void Person::setMaidenName(string maiden) {
maidenName = maiden;
}
string Person::getFirstName()const {
return firstName;
}
string Person::getMiddleName()const {
return middleName;
}
string Person::getLastName()const {
return lastName;
}
string Person::getMaidenName()const {
return maidenName;
}
//Report.h
#pragma once
#include<iostream>
#include<string>
#include \"Data.h\"
using namespace std;
//uses class Data to create a dynamic array containing client phone information
class Report {
friend ostream&operator<<(ostream&, const Report&);
private:
Data* records;
string fileName;
int totalRecords;
float totalMinutes;
float totalAmount;
public:
Report();
Report(const Data&, string);
Report(const Report&);
~Report();
void setRecord(const Data&);
void setFileName(string);
void setTotalMinutes(float);
void setTotalAmount(int);
Data getRecord(int)const;
string getFileName()const;
int getTotalRecords()const;
float getTotalMinutes()const;
float getTotalAmount()const;
};
//Report.cpp
#include<iostream>
#include<string>
#include \"Data.h\"
#include \"Report.h\"
using namespace std;
ostream&operator<<(ostream& output, const Report& aReport) {
for (int i = 0; i < aReport.getTotalRecords(); i++) {
output << \"Report number is: \" << aReport.getRecord(i) << endl;
}
return output;
}
Report::Report() {
totalRecords = 0;
fileName = \"\";
}
Report::Report(const Data& aData, string name) {
records[0] = aData;
fileName = name;
totalRecords = 1;
}
Report::Report(const Report& aReport) {
setRecord(*aReport.records);
setFileName(aReport.fileName);
setTotalMinutes(aReport.totalMinutes);
setTotalAmount(aReport.totalAmount);
}
Report::~Report() {}
void Report::setRecord(const Data& aData) {
int idx = totalRecords;
if (totalRecords == 0) {
records = new Data[1];
}
else {
Data* temp = new Data[totalRecords];
for (int i = 0; i < totalRecords; i++) {
temp[i] = records[i];
}
delete[]records;
records = new Data[totalRecords + 1];
for (int i = 0; i < totalRecords; i++) {
records[i] = temp[i];
}
delete[]temp;
}
records[idx] = aData;
totalRecords++;
}
void Report::setFileName(string name) {
fileName = name;
}
void Report::setTotalMinutes(float minutes) {
totalMinutes = minutes;
}
void Report::setTotalAmount(int idx) {
if (records[idx].getLongDistance() == 1) {
totalAmount = getTotalMinutes()*1.25;
}
else {
totalAmount = getTotalMinutes()*0.25;
}
}
Data Report::getRecord(int idx)const {
return records[idx];
}
string Report::getFileName()const {
return fileName;
}
int Report::getTotalRecords()const {
return totalRecords;
}
float Report::getTotalMinutes()const {
return totalMinutes;
}
float Report::getTotalAmount()const {
return totalAmount;
}
//Menu.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
//displays choices
class Menu {
friend ostream&operator<<(ostream& output, const Menu& aMenu) {
system(\"cls\");
int i;
output << aMenu.title << endl << endl;
for (i = 0; i < aMenu.totalItems; i++) {
output << \"\\t\\t\" << i + 1 << \". \" << aMenu.menuItems[i] << endl;
}
output << \"\\t\\t\" << i + 1 << \". Exit\";
output << \"\ \ Choose: \";
return output;
}
friend istream&operator>>(istream& input, Menu& aMenu) {
do {
char ch;
input >> ch;
aMenu.setChoice(ch);
if (!aMenu.check()) {
cout << \"\ ERROR.\";
system(\"pause\");
cout << aMenu;
}
} while (!aMenu.check());
return input;
}
private:
string* menuItems;
string title;
int totalItems;
int choice;
public:
Menu() {
menuItems = NULL;
title = \"Title\";
totalItems = 0;
}
Menu(const char* ttl) {
Menu();
title = ttl;
}
Menu(const Menu& aMenu) {
}
~Menu() {
delete[]menuItems;
}
void addMenuItem(string item) {
int idx = totalItems;
string* temp;
if (idx == 0) {
menuItems = new string[1];
}
else {
temp = new string[totalItems];
for (int i = 0; i < totalItems; i++) {
temp[i] = menuItems[i];
}
delete[]menuItems;
menuItems = new string[totalItems + 1];
for (int i = 0; i < totalItems; i++) {
menuItems[i] = temp[i];
}
delete[]temp;
}
menuItems[idx] = item;
totalItems++;
}
void setTitle(string ttl) {
title = ttl;
}
void setChoice(char choose) {
choice = choose;
}
int getChoice()const {
return choice;
}
int getLast()const {
return totalItems + 1;
}
bool check() {
bool validate;
if (choice > 0 && choice <= (totalItems + 1)) {
validate = true;
}
else
validate = false;
return validate;
}
};
//Data.h
#pragma once
#include<iostream>
#include<string>
#include \"Person.h\"
using namespace std;
//uses class Person to create a profile for a client
class Data {
friend ostream&operator<<(ostream&, const Data&);
friend istream&operator>>(istream&, Data&);
private:
Person client;
string callDate;
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
public:
Data();
Data(const Person&, string, bool, string, string, string, string);
Data(const Data&);
~Data();
void setClient(const Person&);
void setCallDate(string);
void setLongDistance(bool);
void setTimeCallBegin(string);
void setTimeCallEnd(string);
void setCallNoFrom(string);
void setCallNoTo(string);
Person getClient()const;
string getCallDate()const;
bool getLongDistance()const;
string getTimeCallBegin()const;
string getTimeCallEnd()const;
string getCallNoFrom()const;
string getCallNoTo()const;
Data operator=(const Data&);
};
//Data.cpp
#include<iostream>
#include<string>
#include \"Person.h\"
#include \"Data.h\"
using namespace std;
ostream & operator <<(ostream & output, const Data & aData) {
Person person;
output << \"Providing Client Information:\" << endl;
output << person.getFirstName();
output << person.getLastName();
output << person.getMiddleName();
output << person.getMaidenName();
output << endl << \"Call Date: \" << aData.callDate << endl;
output << \"longDistance Charge: \" << aData.longDistance ? \" Y \" : \" N \";//Yes or No question
output << \"Time Call Begin: \" << aData.timeCallBegin;
output << \"Time Call End: \" << aData.timeCallEnd;
output << \"Call # From: \" << aData.callNoFrom;
output << \"Call # to: \" << aData.callNoTo;
return output;
}
istream & operator >>(istream & input, Data & aData) {
cout << \"Client Information: \" << endl;
input >> aData.client;
cout << \"Call Date: \" << endl;
input >> aData.callDate;
cout << \" Long Distance: \" << endl;
input >> aData.longDistance;
cout << \" Time Call Begin: \" << endl;
input >> aData.timeCallBegin;
cout << \" Time Call End: \" << endl;
input >> aData.timeCallEnd;
cout << \" Call # From : \" << endl;
input >> aData.callNoFrom;
cout << \" Call # To: \" << endl;
input >> aData.callNoTo;
return input;
}
Data::Data() {
setClient(Person(\"\", \"\", \"\", \"\"));
setCallDate(\" \");
setLongDistance(false);
setTimeCallBegin(\" \");
setTimeCallEnd(\" \");
setCallNoFrom(\" \");
setCallNoTo(\" \");
}
Data::Data(const Person& aPerson, string date, bool longD, string begin, string end, string from, string to) {
setClient(aPerson);
setCallDate(date);
setLongDistance(longD);
setTimeCallBegin(begin);
setTimeCallEnd(end);
setCallNoFrom(from);
setCallNoTo(to);
}
Data::Data(const Data& aData) {
setClient(aData.client);
setCallDate(aData.callDate);
setLongDistance(aData.longDistance);
setTimeCallBegin(aData.timeCallBegin);
setTimeCallEnd(aData.timeCallEnd);
setCallNoFrom(aData.callNoFrom);
setCallNoTo(aData.callNoTo);
}
Data::~Data() {}
void Data::setClient(const Person& person) {
client = person;
}
void Data::setCallDate(string date) {
callDate = date;
}
void Data::setLongDistance(bool longD) {
longDistance = longD;
}
void Data::setTimeCallBegin(string begin) {
timeCallBegin = begin;
}
void Data::setTimeCallEnd(string end) {
timeCallEnd = end;
}
void Data::setCallNoFrom(string from) {
callNoFrom = from;
}
void Data::setCallNoTo(string to) {
callNoTo = to;
}
Person Data::getClient()const {
return client;
}
string Data::getCallDate()const {
return callDate;
}
bool Data::getLongDistance()const {
return longDistance;
}
string Data::getTimeCallBegin()const {
return timeCallBegin;
}
string Data::getTimeCallEnd()const {
return timeCallEnd;
}
string Data::getCallNoFrom()const {
return callNoFrom;
}
string Data::getCallNoTo()const {
return callNoTo;
}
Data Data::operator=(const Data& aData) {
client = aData.client;
callDate = aData.callDate;
longDistance = aData.longDistance;
timeCallBegin = aData.timeCallBegin;
timeCallEnd = aData.timeCallEnd;
callNoFrom = aData.callNoFrom;
callNoTo = aData.callNoTo;
return *this;
}
//DataParser.h
#pragma once
#include<iostream>
#include<string>
#include \"Data.h\"
using namespace std;
//separates the information from a file to store in Data.h
class DataParser {
private:
Data record;
public:
DataParser();
DataParser(const Data&);
DataParser(const DataParser&);
DataParser(string);
~DataParser();
void setRecord(string);
Data getRecord()const;
Data parse(string);
};
//DataParser.cpp
#include<iostream>
#include<fstream>
#include \"Data.h\"
#include \"DataParser.h\"
using namespace std;
DataParser::DataParser() {
record;
}
DataParser::DataParser(const Data& aData) {
record = aData;
}
DataParser::DataParser(const DataParser& aDataParser) {
record = aDataParser.record;
}
DataParser::DataParser(string line) {
parse(line);
}
DataParser::~DataParser() {}
void DataParser::setRecord(string line) {
parse(line);
}
Data DataParser::getRecord()const {
return record;
}
Data DataParser::parse(string line) {
Person client;
string callDate;
bool longDistance;
string timeCallBegin;
string timeCallEnd;
string callNoFrom;
string callNoTo;
string firstName;
string lastName;
string middleName;
string maidenName;
string blank;
firstName = line.substr(0, 25);
middleName = line.substr(26, 50);
lastName = line.substr(51, 100);
maidenName = line.substr(101, 150);
callDate = line.substr(151, 158);
if (line.substr(159, 159) == \"1\")
longDistance = true;
else
longDistance = false;
timeCallBegin = line.substr(160, 165);
timeCallEnd = line.substr(166, 171);
callNoFrom = line.substr(172, 181);
callNoTo = line.substr(182, 191);
blank = line.substr(192, 250);
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;
}
===========================================================================
This is what I have so far
I need the program to give me the following output but it giving me error in the Main.cpp and such, any help would be appreaciated.
Section 5 Output cmd.exe eport Date: 01/26/2015 eport from: TE20150126.tel ast Name First Name Call Date Long From To Mins odriguez Soto Carlos M 01/26/2015N 787-399-2234 787-234-2345 26 6.50 1/19/2015 N 787-234-5643 787-345-1234 38 9.50 2/23/2014787-356-2345 305-456-234567 100.50 Felix G David P erez Roman Grand Total: 131 116.50 C:\\Users\\Carlos\\DocumentsSolution
Sum of Natural Numbers Using while Loop













