Hi im really new to c++. Im trying to finish a program.
Write a C++ program that takes a string containing a full name, and outputs each part of the name separately. The name should be in the form of first, middle, and last name separated from each other by a single space. For example, if the name string contains
“John Jacob Schmidt”
then the program would output:
First name: John
Middle name: Jacob
Last name: Schmidt
After you have completed this output the length of each name.
And this is what i have so far.
// Darlene Gail Espiritu
// Name.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string firstName;
string middleName;
string lastName;
string fullName;
first name = "Darlene"; // First Name
cout << firstname.lenght() << endl; // Prints 7
middleName = "Gail"; // Middle Name
cout << middleName.lenght() << endl; // Prints 4
lastName = "Espiritu"; // Last Name
cout << lastName.lenght() << endl; // Prints 8
fullName = firstName + middleName + lastName; // Full Name
cout << fullName.lenght() << endl; // Prints 22
It looks like you are not doing what you are asked to do.
Let me start the program for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <string>
usingnamespace std;
int main() {
string fullName = "John Jacob Jingleheimerschmidt";
string firstName; // ... you fill this in
string middleName; // ... ditto
string lastName; // ... ditto
cout << "length of first name = " << firstName.length() << endl;
cout << "length of middle name = " << middleName.length() << endl;
cout << "length of last name = " << lastName.length() << endl;
};
There are many ways to accomplish the missing part. I don't know what method you are expected to use.
Yeah im not very good in programming :( im really having a hard time with it. anyway with the length of the names, do i need i put a numerical value? She did not specify what method but would you give me an example please?
string has a lot of methods on it that can make this program trivial, but she might not want you to use them. Alternatively, you can write loops to search for spaces.
An example of the latter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
usingnamespace std;
int main() {
string msg = "Hello world!";
string word;
for( int index = 0; index < msg.length(); ++index )
if( msg[ index ] != ' ' )
word += msg[ index ];
elsebreak;
cout << word;
}
Try running the above program and see what it does.
When i try to run the program a box pops out and says this Please specify the name of the executable file to be used for the debug session. And I don't know what to do again.
hi i have this project and i need help with it, maybe someone can help me. please?
im really new and really confused.
"You're working for a company that's building an email list from files of mail messages. They would like you to write a program that reads a file called mail.dat, and that outputs every string containing the @ sign to file addresses.dat. For the purpose of this project, a string is defined as it is by the C++ stream reader-a contiguous sequence of non-whitespace characters.
Given the data:
From: sharon@marzipan.edu
Date: Wed, 13 Aug 2003 17:12:33 EDT
Subject: Re: hi
To: john@meringue.com
John,
Dave's email is dave_smith@icing.org
ttyl,
sharon
Then the program would output on file addresses.dat:
Use meaningful variable names, proper indentation, and appropriate comments. Thoroughly test the program using your own data sets.
and this is what i have so far..and it's not working. im not really good with c++ so if someone can tell me what i am doing wrong it'll be great. thanks
what's the error? what's going wrong?
Apparently the program is correct...
let us know what's the problem...
This one's just a small play around with find and substring methods dude...
don't worry...