I need some help.....

" 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.

This program will have four classes:

1. Person
• string firstName
• string middleName
• string lastName
• string maidenName

2. Data
• Person client
• string callDate
• bool longDistance
• string timeCallBegin
• string timeCallEnd
• string callNoFrom
• string callNoTo

3. Report
• Data * records
• string fileName
• int totalRecords
• float totalMinutes
• float totalAmount

4. DataParser
• Data record

Each of the classes will have the constructors, destructors, accessors, mutators and operators overloading.

Class DataParser will have a constructor that received a String, with the line to be parsed. "

Okay I need some guidance in the right direction. This was assigned even tho up to this point I've yet to be taught the concepts of file streaming. I also don't understand how "DataParser" is suppose to work. I don't even know what parsing means. I take I should relate the Data* records" in the Reports class to the "Data records " in the DataParser in someway? Or just allocate memory and have the pointer "Data * records" point to it in the constructor of the Reports class? I just need some clarification in how i should approach this.
Last edited on
Can you ask you for a sample of the input file? How many percent have you completed?
this is the file that needs to be read
https://www.dropbox.com/s/t0p1phatwgaz0lw/TE20150126.tel?dl=0
All I did so far was make the classes. But I'm still confused over the "Data * records" in Report
and the "DataParser class"
1
2
3
Carlos                   Miguel                   Rodriguez                                         Soto                                              01262015015300015560078739922347872342345                                                           
Felix                    Gabriel                  Perez                                             Roman                                             01192015009020509401478723456437873451234                                                           
David                    Piere                    Soto                                              Colon                                             12232014111340912410578735623453054562345


What are these ridiculous long numbers?

01262015015300015560078739922347872342345
01192015009020509401478723456437873451234
12232014111340912410578735623453054562345


https://www.dropbox.com/s/f2ctgqtc9llgbh2/Project2v2%282%29.pdf?dl=0
scroll the the bottom. Yeah I don't get why it's like that.
This really looks difficult for me. Do you want a certain someone to do it for you?
I just need someone to explain me how to go about it.
This exercise is easy enough for beginners.
The document hints that each field has fixed length.

You just need to use std::getline to get a whole data string, and use std::string::substr to extract each field from the data string.

For example :
1
2
firstName = dataLine.substr(1 - 1, 25);
middleName = dataLine.substr(26 - 1, 25);


After that, the assignment becomes too easy and you can handle it with ease.
Regarding the long numbers:
The records are simply packed together. The first 8 characters are a date, the next character describes whether or not the call was long-distance, then two dates; and finally two phone numbers.

I don't even know what parsing means.
parse: v.: to analyze (a string or text) into logical syntactic components

You're supposed to take a string and split it into usable data. Apparently, a Data object.

Data* records I assume is supposed to reference an array of Data you've produced from the lines of the file using an instance of DataParser.
Last edited on
Could you explain a bit how to read the file and take and store it's data ?
Could you explain a bit how to read the file and take and store it's data ?

Have you learned std::ifstream??
I'm learning about it now to do this but I don't understand it well enough. Like if I have a text file that has the following:
apple
banana
orange

and I want to save the third line (orange) into a string. How do I go about it?
How do I go about it?
1
2
3
4
5
6
7
8
std::ifstream inFile("fruit.txt");
std::string fruit;

std::getline(inFile, fruit); // Stores 'apple'
std::getline(inFile, fruit); // Stores 'banana'
std::getline(inFile, fruit); // Stores 'orange'

std::cout << fruit << std::endl;
Thank you for your help. So you basically have to go through every line ?
Last edited on
So you basically have to go through every line?

Yes, you read each line one by one, then do whatever to the line you have read.
Yes, you read each line one by one, then do whatever to the line you have read.

Okay I think I have some clear insight on how to do this now. One last thing. How about if i want to store each fruit in the following text in a string?

Banana Apple
Grapes Mango


Last edited on
How about if i want to store each fruit in the following text in a string?

You can use traditional inFile >> something;

1
2
3
4
std::ifstream inFile("fruit.txt");
std::string fruit;

while(inFile >> fruit) std::cout << fruit << std::endl;


This always works no matter how many fruits there are in the file.
The
Reports
class has member variables such as
totalRecords
,
totalMinutes
and
totalAmounts
. Does this mean that within the Reports class I should dynamically create an array of
Data
and have the pointer
Data * records
from the Records class point to it ? Then assign values to each using information from the dynamically created array ?
Does this mean I should make two dynamic arrays then ? Since the instructions say
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.
For option 1, you do not know how many reports are, meaning that you will create dynamically the reports
Last edited on
Topic archived. No new replies allowed.