By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Strings in C++: A tricky problem

P: n/a
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 greatt 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.
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
M Maloney wrote:
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 | |
+-------+---------------+---------------+-------+ I am having greatt difficulty making this work in good C++ O-O
style.


Switch to a language like Ruby, with built-in regular expression support,
and output an HTML table. You'l finish before the next sitcom.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #2

P: n/a

Phlip wrote:
M Maloney wrote:
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 | |
+-------+---------------+---------------+-------+
I am having greatt difficulty making this work in good C++ O-O
style.


Switch to a language like Ruby, with built-in regular expression

support, and output an HTML table. You'l finish before the next sitcom.

--
Phlip

http://industrialxp.org/community/bi...UserInterfaces

Thanks for your suggestion, but it has to be done using C++

Jul 23 '05 #3

P: n/a
In article <11*********************@z14g2000cwz.googlegroups. com>,
<ma********@hotmail.com> wrote:
Thanks for your suggestion, but it has to be done using C++


Then consider Boost, which includes regex, which is slated to be in
the next C++ standard (and which is available free now).
--
Mark Ping
em****@soda.CSUA.Berkeley.EDU
Jul 23 '05 #4

P: n/a

M Maloney wrote:
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 | |
+-------+---------------+---------------+-------+
Ok, what you have to do is break down the problem.
First, you need to read the input into a sensible
datastructure. The obvious datastructure would be a
collection of channels. Every time you see a line
starting with =, you add a new channel. Every other
line is converted into a program and added to the last
channel. So, the channel class must contain a name
member and a collection of programs. The program
class contains a name and a time.

After you have done input, you can collect all the
times from all the programs. Put these into a list,
and print the list.
From there it should be easy.


HTH,
Michiel Salters

Jul 23 '05 #5

P: n/a
E. Mark Ping wrote:

Then consider Boost, which includes regex, which is slated to be in
the next C++ standard (and which is available free now).


It's not slated to be in the next C++ standard. It's part of TR1, which
is a technical report. Technical reports don't affect the standard, but
can be used to indicate of possible future directions; that's the
purpose of TR1.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #6

P: n/a
Pete Becker wrote:
E. Mark Ping wrote:

Then consider Boost, which includes regex, which is slated to be in
the next C++ standard (and which is available free now).


It's not slated to be in the next C++ standard. It's part of TR1, which
is a technical report. Technical reports don't affect the standard, but
can be used to indicate of possible future directions; that's the
purpose of TR1.


But all the other languages are doing it.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #7

P: n/a
In article <ib********************@giganews.com>,
Pete Becker <pe********@acm.org> wrote:
E. Mark Ping wrote:

Then consider Boost, which includes regex, which is slated to be in
the next C++ standard (and which is available free now).


It's not slated to be in the next C++ standard. It's part of TR1, which
is a technical report. Technical reports don't affect the standard, but
can be used to indicate of possible future directions; that's the
purpose of TR1.


Ah, on looking back on Herb Sutter's Jan'05 article, I see how I
misinterpreted it. Thanks for the correction.
--
Mark Ping
em****@soda.CSUA.Berkeley.EDU
Jul 23 '05 #8

P: n/a
Thanks very much for your help Michiel, I see now how I should have
been thinking. The rest should be easy for me

Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.