473,394 Members | 1,932 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,394 software developers and data experts.

ignore funtiction?

Please help, this is due at 11:59 PM tonite. Thanks

Write a program that reads a person's name from the keyboard in the format
First Middle Last. It should then (1) print each of the names on a separate
line and (2) print the person's initials on the fourth line. Assume that
each person has exactly 3 names, that the first name begins in the first
position on a line (there are no leading blanks) and that the names are
separated from each other by a single blank.

Do not use arrays in this assignment.

SO far i gigured out only how to print out the initials, but i can't figure
out how to get each part of a name as a seperate string. Can any one help me
out? here is my source so far

#include <iostream>
#include <string>
using namespace std;

int main ()
{

char m;
char l;
char f;

cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;

cout<<f<<m<<l<<endl;

return 0;
}


Jul 19 '05 #1
5 7833
"Luis" <ki***@attbi.com> wrote...
Please help, this is due at 11:59 PM tonite. Thanks

Write a program that reads a person's name from the keyboard in the format
First Middle Last. It should then (1) print each of the names on a separate line and (2) print the person's initials on the fourth line. Assume that
each person has exactly 3 names, that the first name begins in the first
position on a line (there are no leading blanks) and that the names are
separated from each other by a single blank.

Do not use arrays in this assignment.

SO far i gigured out only how to print out the initials, but i can't figure out how to get each part of a name as a seperate string. Can any one help me out? here is my source so far

#include <iostream>
#include <string>
using namespace std;

int main ()
{

char m;
char l;
char f;
Declare them as 'string'.

cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;
Drop the 'ignore's.

cout<<f<<m<<l<<endl;
To output each of them on a separate line you need a line
separator between them, don't you?

Now, regarding the initials, what are they? Each initial
is the very first character of each name, right? So, output
the initials by outputting the very first character in each
string.

return 0;
}


Jul 19 '05 #2
"Luis" <ki***@attbi.com> wrote in news:4jpKa.18096$Fy6.5818@sccrnsc03:
Please help, this is due at 11:59 PM tonite. Thanks

Write a program that reads a person's name from the keyboard in the
format First Middle Last. It should then (1) print each of the names
on a separate line and (2) print the person's initials on the fourth
line. Assume that each person has exactly 3 names, that the first name
begins in the first position on a line (there are no leading blanks)
and that the names are separated from each other by a single blank.

Do not use arrays in this assignment.

SO far i gigured out only how to print out the initials, but i can't
figure out how to get each part of a name as a seperate string. Can
any one help me out? here is my source so far

#include <iostream>
#include <string>
using namespace std;

int main ()
{

char m;
char l;
char f;

cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;

cout<<f<<m<<l<<endl;

return 0;
}


Well..... first thing to note is that you're reading into variables of
type 'char'. char can only hold one character. Look up a standard type
named "std::string".
Jul 19 '05 #3
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote...
Andre Kostur wrote:
Luis wrote:
Do not use arrays in this assignment.


Well..... first thing to note is that you're reading into variables of
type 'char'. char can only hold one character.
Look up a standard type named "std::string".


Isn't a std::string an array?


No, it isn't. Are you trolling again?
Jul 19 '05 #4
Ok The way to do it is:

#include <iostream> // for cout, cin, endl functions
#include <string> // to make variables called strings

using namespace std; // using namespaces

int main() // the main function
{ // open the main function
string f; // create a string variable called f (first name)
string m; // create a string variable called m (middle name)
string l; // create a string variable called l (last name)

cin>>f; cin.ignore(0,' '); // input first name, then ends after the " " (space)
cin>>m; cin.ignore(0,' '); // input first name, then ends after the " " (space)
cin>>l; cin.ignore(0,' '); // input last name, hit enter.

cout<<f<<endl<<m<<endl<<l<<endl; // output first name, next line, middle name, next line, last name, next line.
system("pause"); // for windows if you want to pause the programme.
/* cin.get(); */ // remove the /**/ comments from it if you are not using windows and need to pause the programme to view it.
} // end the main function
Jul 17 '06 #5
here's the solution to your problem.


#include <iostream>
#include <string>
using namespace std;

int main()
{
string fi;
string mi;
string last;

cin >> fi >> mi >> last;
cout << fi << endl
<< mi << endl
<< last << endl;
cout << fi.substr(0,1);
cout << mi.substr(0,1);
cout << last.substr(0,1) << endl;
return 0;
}
Jul 29 '06 #6

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

Similar topics

0
by: Thomas Müller | last post by:
Hello! Running my uploadscript on old server, php4.1.2 ignore aborted fileuploads. Now, the same script on new server doesn't ignore broken uploads. If anybody make a upload and abort this the...
6
by: Rob Meade | last post by:
Lo all, I was just running through some code I was writing for a site and when it came to the 'exact phrase' search type I wasn't sure whether that should run through and ignore the words in the...
1
by: Thomas Bartkus | last post by:
The meaning of REPLACE INTO is clear to me. IF the new record presents new key values, then it is inserted as a new record. IF the new record has key values that match a pre-existing record, then...
5
by: Chris Mantoulidis | last post by:
Let's say I have this: std::string s1; std::cin >> s1; This will read s1 from cin until it finds a space (or a newline, whichever comes first). Okay this works. But when I want to continue...
1
by: windandwaves | last post by:
Are you allowed to use the following syntax in Mysql 4.0.17-nt : INSERT DELAYED IGNORE INTO `mytable` ( `ID` , `A` , `B` ) VALUES ("'.session_id().'", "2", ROUND(NOW()/10000) ); I am...
23
by: FrancisC | last post by:
#include <stdio.h> int file_copy( char *oldname, char *newname ); int main() { char source, destination; printf("\nEnter source file: ");
4
by: Jackson Miller | last post by:
I notice that postgres does not support IGNORE. I am currently migrating an app from a MySQL datastore to Postgres, and I would really like to use IGNORE. I am curious if there is a...
1
by: alw0015 | last post by:
I'm working on a piece of code that reads in a time from the user. This time value consists of 3 separate inputs: 1 integer representing hours 1 char representing the ":" 1 integer...
6
by: sandy | last post by:
I seem to ALWAYS need to use cin.ignore in my programs (console apps using Dev C++ for a University course). The problem is that if I don't ignore ENOUGH characters then it's like not having the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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...
0
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...

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.