473,756 Members | 4,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner help!

I have a question in my class.. hoping to get some help
I need to create a program that will print
firstName middleName lastName
then their initials

User will input:
John Smith Doe

Output:
John
Smith
Doe
JSM

I can easily create the strings and cout the names but having trouble
finding how to print the first letter of each string
(cannot use array)
am I to use ignore function somehow?
can anyone help me????

Feb 5 '06
33 2418
Bo Persson wrote:
The slight advantage of using [] is that not checking the index saves
you some (very small) amount of time.
There's also an argument to be made in terms of clarity.
If your program runs millions of
times a day, that might be worth the risk!


Disagree. If your program runs millions of times a day, that
(efficiency gain) might be worth the *effort* of rigorously verifying
the correctness of the access so that the extra checking provided by
at() is redundant. Any code running millions of time, day in and day
out, is probably too important to accept additional *risk* of undefined
behavior.

A good design and clean implementation by someone who knows what
they're doing (not someone in an introductory programming course, mind
you) should be able to provide convincingly correct invariants when
necessary.

Luke

Feb 5 '06 #21
* Luke Meyers:
Bo Persson wrote:
The slight advantage of using [] is that not checking the index saves
you some (very small) amount of time.


There's also an argument to be made in terms of clarity.
If your program runs millions of
times a day, that might be worth the risk!


Disagree. If your program runs millions of times a day, that
(efficiency gain) might be worth the *effort* of rigorously verifying
the correctness of the access so that the extra checking provided by
at() is redundant. Any code running millions of time, day in and day
out, is probably too important to accept additional *risk* of undefined
behavior.

A good design and clean implementation by someone who knows what
they're doing (not someone in an introductory programming course, mind
you) should be able to provide convincingly correct invariants when
necessary.


I'm sorry, but that's not meaningful in any sense.

IBM did an experiment in coding on paper only, I think that was in
Australia. They'll never do that again.

That's why we we have checked operations such as at(), and that's why we
have testing.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 5 '06 #22
"Luke Meyers" wrote:
Bo Persson wrote:
The slight advantage of using [] is that not checking the index saves
you some (very small) amount of time.


There's also an argument to be made in terms of clarity.
If your program runs millions of
times a day, that might be worth the risk!


Disagree. If your program runs millions of times a day, that
(efficiency gain) might be worth the *effort* of rigorously verifying
the correctness of the access so that the extra checking provided by
at() is redundant. Any code running millions of time, day in and day
out, is probably too important to accept additional *risk* of undefined
behavior.

A good design and clean implementation by someone who knows what
they're doing (not someone in an introductory programming course, mind
you) should be able to provide convincingly correct invariants when
necessary.


The [] is much more clear that at. A well designed language would check for
bounds errors when using the [] notation. It would also have the option of
turning off checking on production builds. All problems solved, nothing to
discuss.
Feb 5 '06 #23
Alf P. Steinbach wrote:
* Luke Meyers:
Bo Persson wrote:
The slight advantage of using [] is that not checking the index saves
you some (very small) amount of time.
There's also an argument to be made in terms of clarity.
If your program runs millions of
times a day, that might be worth the risk!


Disagree. If your program runs millions of times a day, that
(efficiency gain) might be worth the *effort* of rigorously verifying
the correctness of the access so that the extra checking provided by
at() is redundant. Any code running millions of time, day in and day
out, is probably too important to accept additional *risk* of undefined
behavior.

A good design and clean implementation by someone who knows what
they're doing (not someone in an introductory programming course, mind
you) should be able to provide convincingly correct invariants when
necessary.


I'm sorry, but that's not meaningful in any sense.

IBM did an experiment in coding on paper only, I think that was in
Australia. They'll never do that again.


I think you mistook my meaning. I did not say to produce logical
proofs of program correctness (is that the meaning you took?). I said
"convincing ly correct," by which I mean that the invariant "all
unchecked indices are valid," where useful in the context of a specific
time optimization, can generally be provided to an acceptable degree of
confidence within a sufficiently local context. Is that more clear?
Close scrutiny and thorough testing can suffice, when truly expedient.
That's why we we have checked operations such as at(), and that's why we
have testing.


Yes, but in C++, there is an important principle that "you don't pay
for what you don't use." So that's why the unchecked operation is
available.

Luke

Feb 5 '06 #24
osmium wrote:
The [] is much more clear that at.
A reasonable subjective argument can be made for that (or for the
contrary). I would imagine it depends a great deal on the individual
reading the code.
A well designed language would check for
bounds errors when using the [] notation.
This too is very subjective. What do you mean by "well-designed?"
Given that a programming language is created with certain design
principles involved, certain goals to accomplish, is it fair to call
something poorly designed if you disagree with the selection of
principles and goals? In C++, you don't pay (in terms of time and
space cost at runtime) for what you don't use. There's no free lunch
-- you can't have checked access and have it be as fast as unchecked
access. Inside the body of a tight loop, or another
performance-critical context, this overhead may be both unnecessary and
unacceptably expensive.

You might argue that, while unchecked access is a good facility to have
available, checked access should be the common case, and therefore
provide what you see as the clearest syntax. However, remember that
another important design goal of C++ has always been maximal
compatibility with C; it is because C++ is compatible with C that it
has come into such wide use. The vast majority of programming
languages, "well-designed" or not, languish in obscurity. The []
element access syntax comes from arrays, and for arrays it is an
unchecked operation. Hence, the most consistent scheme is to have the
unchecked operations for other containers use the same syntax.

So, with this in mind, do you really feel it's a bad design, or just
disagree with the priorities involved in choosing design criteria?
It would also have the option of
turning off checking on production builds.
That negates much of the benefit. Non-production code is only run on
whatever test cases you invent (and take the time to implement).
Production use is typically far more exhaustive, and as such may
uncover cases not reached in testing. If the access is unchecked in
those cases, you're no better off for having had checked access in your
tests. When you're in a nice, safe testing sandbox, undefined behavior
may take longer to diagnose than a handled error, but for the most part
the result is the same. In production, undefined behavior can be
catastrophic -- for a lot of C++ code, lives depend on not invoking
undefined behavior.

Better to use checked access in general, and make careful use of
unchecked access when a specific optimization need is discovered during
performance analysis. Fortunately, for those who use the STL
effectively and as intended, it's rare to have to use operator[] or
at() in any case -- that's why we have iterators and standard
algorithms. You can bet that your local for_each implementation isn't
using checked access, but it's small and tight and closely-scrutinized,
and it works great 100% of the time.
All problems solved, nothing to discuss.


That's naive (and rather arrogant). You made your points, based on
your subjective opinion; that doesn't entitle you to declare the
discussion closed and take a victory lap.

Luke

Feb 5 '06 #25

Thomas J. Gritzan wrote:
ro**********@gm ail.com schrieb:
In the mean time why not try writing it? Here, I'll get you started:

int main()
{
// PROGRAM GOES HERE.
}


This seems to be a misunderstandin g. The OP did already started to
program, but just posted his assignment. Since he did not quote the
context, you think he was asking for doing his homework.


Well, he has been given several ways to do his original question.
Steinbach gave him one right off the bat. So I don't understand why he
is still posting his assignment; seems to me like he should have tried
the solution given and be well on his way to finishing.

His original question was quite reasonable...

Feb 5 '06 #26
"Luke Meyers" wrote:
osmium wrote:
The [] is much more clear that at.
A reasonable subjective argument can be made for that (or for the
contrary). I would imagine it depends a great deal on the individual
reading the code.


Really? Do you actually know a person who finds at clearer?
A well designed language would check for
bounds errors when using the [] notation.


This too is very subjective. What do you mean by "well-designed?"
Given that a programming language is created with certain design
principles involved, certain goals to accomplish, is it fair to call
something poorly designed if you disagree with the selection of
principles and goals? In C++, you don't pay (in terms of time and
space cost at runtime) for what you don't use. There's no free lunch
-- you can't have checked access and have it be as fast as unchecked
access. Inside the body of a tight loop, or another
performance-critical context, this overhead may be both unnecessary and
unacceptably expensive.

You might argue that, while unchecked access is a good facility to have
available, checked access should be the common case, and therefore
provide what you see as the clearest syntax. However, remember that
another important design goal of C++ has always been maximal
compatibility with C; it is because C++ is compatible with C that it
has come into such wide use. The vast majority of programming
languages, "well-designed" or not, languish in obscurity. The []
element access syntax comes from arrays, and for arrays it is an
unchecked operation. Hence, the most consistent scheme is to have the
unchecked operations for other containers use the same syntax.

So, with this in mind, do you really feel it's a bad design, or just
disagree with the priorities involved in choosing design criteria?
It would also have the option of
turning off checking on production builds.


That negates much of the benefit. Non-production code is only run on
whatever test cases you invent (and take the time to implement).
Production use is typically far more exhaustive, and as such may
uncover cases not reached in testing. If the access is unchecked in
those cases, you're no better off for having had checked access in your
tests. When you're in a nice, safe testing sandbox, undefined behavior
may take longer to diagnose than a handled error, but for the most part
the result is the same. In production, undefined behavior can be
catastrophic -- for a lot of C++ code, lives depend on not invoking
undefined behavior.


What is it you don't understand about optional?
Better to use checked access in general, and make careful use of
unchecked access when a specific optimization need is discovered during
performance analysis. Fortunately, for those who use the STL
effectively and as intended, it's rare to have to use operator[] or
at() in any case -- that's why we have iterators and standard
algorithms.


Do you realize that people actually write mathematical programs and other
programs using random access (games) in C++?

Feb 5 '06 #27
osmium wrote:
"Luke Meyers" wrote:
The [] is much more clear that at. A well designed language would check for
bounds errors when using the [] notation. It would also have the option of
turning off checking on production builds. All problems solved, nothing to
discuss.


An all or nothing bound check is not desirable. How would you
efficiently implement the 2 (non-sense) functions below?
With at and operator[] I can chosse what fits my needs.

char first(const std::string& s) throw (std::exception )
{
return s.at(0);
}

void addOne(std::str ing& s)
{
typedef std::string::si ze_type Size;
for (Size e = s.size(), i = 0; i < e; ++i) {
s[i] += 1; // *)
}
}

*) Certainly Alf agrees to use the operator[] here :-)
Overflow check omitted.

Regards, Stephan
br****@osb-systems.com
Open source rating and billing engine for communication networks.

Feb 5 '06 #28
* Luke Meyers:
Alf P. Steinbach wrote:
* Luke Meyers:
Bo Persson wrote:
> The slight advantage of using [] is that not checking the index saves
> you some (very small) amount of time.

There's also an argument to be made in terms of clarity.

> If your program runs millions of
> times a day, that might be worth the risk!

Disagree. If your program runs millions of times a day, that
(efficiency gain) might be worth the *effort* of rigorously verifying
the correctness of the access so that the extra checking provided by
at() is redundant. Any code running millions of time, day in and day
out, is probably too important to accept additional *risk* of undefined
behavior.

A good design and clean implementation by someone who knows what
they're doing (not someone in an introductory programming course, mind
you) should be able to provide convincingly correct invariants when
necessary.


I'm sorry, but that's not meaningful in any sense.

IBM did an experiment in coding on paper only, I think that was in
Australia. They'll never do that again.


I think you mistook my meaning. I did not say to produce logical
proofs of program correctness (is that the meaning you took?). I said
"convincing ly correct," by which I mean that the invariant "all
unchecked indices are valid," where useful in the context of a specific
time optimization, can generally be provided to an acceptable degree of
confidence within a sufficiently local context. Is that more clear?
Close scrutiny and thorough testing can suffice, when truly expedient.


First rule of optimization: don't do it.

Second rule: don't do it yet.

Third rule: measure first.

IMO teaching irrelevant and mostly problematic low-level optimization
techniques to novices, instead of proper engineering, is very bad.

At least, if unchecked operations are to be recommended, also recommend
measurement to see whether they actually have any positive effect.

That's why we we have checked operations such as at(), and that's why we
have testing.


Yes, but in C++, there is an important principle that "you don't pay
for what you don't use." So that's why the unchecked operation is
available.


The unchecked operations are available for the cases where you either
don't care about correctness, or guarantee it in other ways.

Those are not reasonable requirements for a novice.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 5 '06 #29

Luke Meyers wrote:
osmium wrote:


[snip - no point arguing missing sections since they are correct]
It would also have the option of
turning off checking on production builds.


That negates much of the benefit. Non-production code is only run on
whatever test cases you invent (and take the time to implement).
Production use is typically far more exhaustive, and as such may
uncover cases not reached in testing. If the access is unchecked in
those cases, you're no better off for having had checked access in your
tests. When you're in a nice, safe testing sandbox, undefined behavior
may take longer to diagnose than a handled error, but for the most part
the result is the same. In production, undefined behavior can be
catastrophic -- for a lot of C++ code, lives depend on not invoking
undefined behavior.

Better to use checked access in general, and make careful use of
unchecked access when a specific optimization need is discovered during
performance analysis. Fortunately, for those who use the STL
effectively and as intended, it's rare to have to use operator[] or
at() in any case -- that's why we have iterators and standard
algorithms. You can bet that your local for_each implementation isn't
using checked access, but it's small and tight and closely-scrutinized,
and it works great 100% of the time.


While much of what you say is true I do find that providing
non-production checks to be very benificial. Sometimes when you are in
the middle of development you are not fully aware of all the
concequences of your actions. Placing asserts that are compiled out in
release mode help other developers find those areas that get broken by
code they change or add. For instance in this case you may find that
something you did added length to a vector but you were not aware of
that concequence. Concequently you run into a buffer overrun situation
and without a debug assert telling you what happened and where it could
take you hours or days to find it.

Also you use of iterators as illustration is questionable since
iterators are unchecked. In a situation when you want to be sure never
to overrun it may be more beneficial to use at() then an iterator that
can go past end() into no-man's land.

That said, I never use at(). For one thing it would be a major issue
where I work because the lead dev doesn't like STL to begin with and
thinks its slow and does bounds checking all the time (I know) but also
because he doesn't like exceptions and at() generates exceptions. But
to tell the truth I never used it anyway since it is just so easy to
check for yourself and most of the time you have to anyway. IMHO even
when you don't you should be since exceptions are for exceptional
situations and shouldn't be used for bound checking.

Feb 5 '06 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2871
by: Art | last post by:
NEWBIE ALERT! Esteemed List Participants and Lurkers: (System: P-II 350, 192 meg, Win98 SE, Python 2.2.3, wxPythonWIN32-2.4.1.2-Py22.exe) I'm having a lot of fun getting started with Python ... it is the most elegant and graceful language I have ever used (Fortran, Cobol, Basic, many assemblers, Forth, C, VB, etc.). I don't have the resources or the
3
2987
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
8
2382
by: Grrrbau | last post by:
I'm a beginner. I'm looking for a good C++ book. Someone told me about Lafore's "Object-Oriented Programming in C++". What do you think? Grrrbau
1
2870
by: LRW | last post by:
I was wondering if anyone could recommend some good beginner sites and tutorial sites for writting ASP.Net pages in C#. Things that especially help with datagrids!! And, are there additional newsgroups that focus on C# and ASP.Net? Thanks!! Liam
14
2293
by: z_learning_tester | last post by:
But I can't seem to find the answer. The question is how do you reverse the words in a string? Or how do you reverse the numbers listed in a string? The example is usually something like: Turn this string "1,2,3,4,..." Into "...4,3,2,1" This one seems hard enough let alone trying to turn a string of space-seperated words around(is that even possible? a trick question
3
2192
by: William Foster | last post by:
Good evening all, Microsoft is really starting to annoy me as a new user. I am trying to convert my code from VBA (A very user friendly laguage with generally good help files) to Visual Studio 2005 Visual Basic (A poorly documented language). I am unable to find help for Visual Basic that tells me how to show the Browse Files/Folders dialog box in this system; help shows me 50,000,001 different articles but none of them relate to me,...
10
2427
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type of free IDE. So I discovered that I needed to download a virtual server, so I downloaded OmniSecure and followed the set up instructions as far as I could figure them out. So here is where I'm stuck. 1) While trying to set up and configure...
1
1804
by: Blue_hatter | last post by:
Hey Guys, I'm a newbie to the whole C++ Programming thing as I think I said before in a post. The thing is, I have this idea that might help me to learn at a better pace than I am doing currently. I realise that I learn better if I explain things as I go along. My suggestion is, I start a tutorial as I learn the concepts of the language from the beginning though I'm not exactly a beginner, I've started c++ a couple of months ago and I...
10
2153
by: hamza612 | last post by:
I want to start learning how to program. But I dont know where to start. From what I've heard so far c++ is not a good lang. to learn as a beginner because its very complicated compared to others like python, ruby etc. I would like to know if there is a prerequisite to learning any computer language, is there something I have to learn before learning any computer language, like a basic or core?
22
18151
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
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
8736
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
7285
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
5168
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...
1
3828
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
2
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.