Strings in C++: A tricky problem

M

M Maloney

Hey all,
I was wondering if anyone could help me with this problem I
have:
Given a text file like this:

8
=ABC
18.00 Dr Who: Underworld
18.30 Collectors
19.00 News
19.30 The 7.30 Report
20.00 Catalyst
=Seven
18.00 Seven News
18.30 Today Tonight
19.00 Home and Away
19.30 My Restaurant Rules
20.30 **END
=31
19.00 Other
20.00 **END


I have to produce a program guide like this:
+-------+-------+-------+-----­--+-------+-------+
| | 18.00 | 18.30 | 19.00 | 19.30 | 20.00 |
+-------+-------+-------+-----­--+-------+-------+
| ABC | Dr Wh | Colle | News | The 7 | Catal |
+-------+-------+-------+-----­--+-------+-------+
| Seven | Seven | Today | Home | My Restaurant |
+-------+-------+-------+-----­--+-------+-------+
| 31 | | Other | |
+-------+---------------+-----­----------+-------+


Some features to note: channel names are right-justified with a
cell, everything else is leftjustified;
cell content is truncated to fit cell width; ‘+' is only used in row
separators where there is a ‘|' above or below; channel content may
not fill an entire row.


The description file contains:
• a line containing a single integer specifying the cell width;
thereafter
• lines beginning with ‘=' start a new channel and have the channel
name following the ‘='
• other lines have a time of the form integer.integer followed by a
programme name; time resolution will not be finer than half-hour
increments
• lines are separated with the conventional ASCII LF character


A programme runs from its specified starting time until the start
of the next programme or for half-an-hour if there is no next
programme. The special entry ‘**END' may be used to terminate a
programme entry before the start of the next programme or to given the
last programme of the day a running time of more than half-an-hour,
e.g. a programme may run from 5.30 to 6.00 but the next programme may
not start until 7.00. Programme entries may span more than one column.


Cell width includes the closing but not the opening character so the
above table has a cell width of 8. A table of cell width w with n
columns will have a total line length of n*w+1. The first column
contains the channel names. The first row contains the times. The
ASCII characters ‘-', ‘|' and ‘+' should be used to build the table;
‘+' should be used in the row separator when there
is a ‘|' above or below. At least one space should appear on either
side of ‘|' characters. Depending on the justification sometimes at
most one space should appear.


Each column is half an hour, but a programme may run for longer,
thus consuming two or more columns


I am having great difficulty making this work in good C++ O-O
style. If anyone could help me out, that would be greatly appreciated.
Even giving me some skeleton code, or describing how I should begin
would be fine.
Thanks in advance.
 
D

Dave Townsend

M Maloney said:
Hey all,
I was wondering if anyone could help me with this problem I
have:
Given a text file like this:

8
=ABC
18.00 Dr Who: Underworld
18.30 Collectors
19.00 News
19.30 The 7.30 Report
20.00 Catalyst
=Seven
18.00 Seven News
18.30 Today Tonight
19.00 Home and Away
19.30 My Restaurant Rules
20.30 **END
=31
19.00 Other
20.00 **END


I have to produce a program guide like this:
+-------+-------+-------+-----­--+-------+-------+
| | 18.00 | 18.30 | 19.00 | 19.30 | 20.00 |
+-------+-------+-------+-----­--+-------+-------+
| ABC | Dr Wh | Colle | News | The 7 | Catal |
+-------+-------+-------+-----­--+-------+-------+
| Seven | Seven | Today | Home | My Restaurant |
+-------+-------+-------+-----­--+-------+-------+
| 31 | | Other | |
+-------+---------------+-----­----------+-------+


Some features to note: channel names are right-justified with a
cell, everything else is leftjustified;
cell content is truncated to fit cell width; '+' is only used in row
separators where there is a '|' above or below; channel content may
not fill an entire row.


The description file contains:
. a line containing a single integer specifying the cell width;
thereafter
. lines beginning with '=' start a new channel and have the channel
name following the '='
. other lines have a time of the form integer.integer followed by a
programme name; time resolution will not be finer than half-hour
increments
. lines are separated with the conventional ASCII LF character


A programme runs from its specified starting time until the start
of the next programme or for half-an-hour if there is no next
programme. The special entry '**END' may be used to terminate a
programme entry before the start of the next programme or to given the
last programme of the day a running time of more than half-an-hour,
e.g. a programme may run from 5.30 to 6.00 but the next programme may
not start until 7.00. Programme entries may span more than one column.


Cell width includes the closing but not the opening character so the
above table has a cell width of 8. A table of cell width w with n
columns will have a total line length of n*w+1. The first column
contains the channel names. The first row contains the times. The
ASCII characters '-', '|' and '+' should be used to build the table;
'+' should be used in the row separator when there
is a '|' above or below. At least one space should appear on either
side of '|' characters. Depending on the justification sometimes at
most one space should appear.


Each column is half an hour, but a programme may run for longer,
thus consuming two or more columns


I am having great difficulty making this work in good C++ O-O
style. If anyone could help me out, that would be greatly appreciated.
Even giving me some skeleton code, or describing how I should begin
would be fine.
Thanks in advance.

You haven't made the slightest effort to solve the problem yourself, nobody
on this list is going to do your homework for you. Why don't you try the
simplest thing first - output the half-hour slots and get them correctly
formatted.
After you get comfortable with strings, you will probably figure out
yourself what
you have to do to get the programs to align up with the times - or at least
you'd have
something to post then the members of the list would gladly help you.
 
M

M Maloney

Dave Townsend said:
You haven't made the slightest effort to solve the problem yourself, nobody
on this list is going to do your homework for you. Why don't you try the
simplest thing first - output the half-hour slots and get them correctly
formatted.
After you get comfortable with strings, you will probably figure out
yourself what
you have to do to get the programs to align up with the times - or at least
you'd have
something to post then the members of the list would gladly help you.

Yeh, thanks mate, I have made an effort, I just didn't post it
because I didn't think it worthwhile because it wasn't in O-O style.
Thanks for your help though
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top