473,836 Members | 1,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1614
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************ *********@z14g2 000cwz.googlegr oups.com>,
<ma********@hot mail.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.CSU A.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************ ********@gigane ws.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.CSU A.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
2442
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 any arbitrary data, even binary data such as photos and movies.They are of course also good for their traditional role of storing and manipulating text." This view of strings is about a decade out of date with modern programmimg practice. From...
4
1914
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 b, Column c) Table3 (Column a, Column b, Column c) Table1 contains a row of value (1, 2, 3)
2
337
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
1638
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 this. assume I have it stored as such i have two dimensional array ball:
6
3507
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 written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to customer_record SETUP PROGRAM
6
2597
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... there's a lot don't fully understand :)
15
5477
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); /* reads two strings from .ini file */ This works, but it does not allow any comments to the right of the two strings.
89
5175
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 the contents of pString2 to pString? (giving "Blah Blah Blah")
28
6079
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 C-professional, just a hobby-programmer trying to teach it myself. I found C rather difficult without those lists (and corresponding string-functions). Slowly getting into C-strings, I thought, what if I take a C-string and
3
1473
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 = {COMMON_STRINGS, "delta", "echo", "foxtrot"}; char *secondStrArr = {COMMON_STRINGS, "golf", "hotel", "india"}; char *thirdStrArr = {COMMON_STRINGS, "juliett", "kilo", "london"};
0
10832
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10248
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.