473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Strings in C++: A tricky problem

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
8 1584
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

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

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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
4
by: Bung | last post by:
Hi, I have a tricky sql statment I have to write (tricky for me) and I am stuck. I'm having trouble with the following problem. Table1 (Column a, Column b, Column c) Table2 (Column a, Column...
2
by: M Maloney | last post by:
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
5
by: Danny | last post by:
Hi there I need help with a tricky problem. I have a 2 dimensional array with qualities such as ball size, ball color, ball weight. Now I have to print out all the possible combinations of...
6
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
6
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious......
15
by: I. Myself | last post by:
This is about reading the .ini files which are used in several of our projects. Currently, the actual read of each line of the file is with this statement: fscanf(file, "%s %s", name, value);...
89
by: scroopy | last post by:
Hi, I've always used std::string but I'm having to use a 3rd party library that returns const char*s. Given: char* pString1 = "Blah "; const char* pString2 = "Blah Blah"; How do I append...
28
by: hlubenow | last post by:
Hello, I really like Perl and Python for their flexible lists like @a (Perl) and a (Python), where you can easily store lots of strings or even a whole text-file. Now I'm not a...
3
by: Kalle Anka | last post by:
I'd like to have a couple of arrays of strings where the first strings are the same in all arrays. I tried this: #define COMMON_STRINGS "alfa", "bravo", "charlie" char *firstStrArr =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.