C++ Strings PLEASE HELP

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 3
Reputation: aznswti85 is an unknown quantity at this point 
Solved Threads: 0
aznswti85 aznswti85 is offline Offline
Newbie Poster

C++ Strings PLEASE HELP

 
0
  #1
Oct 27th, 2009
I AM HAVING A HARD TIME WITH STRINGS. I DO NOT FULLY UNDERSTAND IT. THIS IS FROM A BASIC INTRO C++ CLASS HW PLEASE HELP THIS IS THE QUESTION

Write a program that uses cin to read a given name (like Louis) and a family name (like Armstrong) into two string variables, given and family. The program then makes assignments to two other string variables: givenFirst and givenLast. To givenFirst it assigns the concatenation of given, a space, and family. To givenLast, it assigns the concatenation of family, a comma followed by a space, and given.

The program then prints on two separate lines the values of givenFirst and givenLast.

So if the user typed in "

HERE'S WHAT I DID.............
int main () {
string given, family;
String givenFirst, givenLast;


cout << “Louis:”;
cin >> given;
cout << “Armistrong:”
cin >> family;

name1=given + “ “ + family;
name2 = givenLast + “,” + givenFirst;

cout << name1 << end1;
cout << name2 << end1;

return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 352
Reputation: dkalita will become famous soon enough dkalita will become famous soon enough 
Solved Threads: 53
dkalita's Avatar
dkalita dkalita is offline Offline
Posting Whiz
 
0
  #2
Oct 27th, 2009
  1. name2 = givenLast + “,” + givenFirst;
givenLast and givenFirst are not initialized.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 73
Reputation: pspwxp fan is an unknown quantity at this point 
Solved Threads: 6
pspwxp fan pspwxp fan is offline Offline
Junior Poster in Training
 
0
  #3
Oct 27th, 2009
First of all, please type in all the code between the CODE tags.

Secondly, you used "String" instead of "string" to initialize givenFirst and givenLast. C++ is case-sensitive, which means that there is a difference between upper-case and lower-case letters.
Last edited by pspwxp fan; Oct 27th, 2009 at 7:30 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: aznswti85 is an unknown quantity at this point 
Solved Threads: 0
aznswti85 aznswti85 is offline Offline
Newbie Poster
 
0
  #4
Oct 27th, 2009
how do i initialize givenFirst and givenLast?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 675
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 100
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster
 
0
  #5
Oct 27th, 2009
Well, what dkalita means is that.... no value is assigned to the variables. givenFirst and givenLast.

Apart from that there are many other mistakes in your program.

Firstly, the declaration of the variables givenFirst is wrong because string should be in the place of String notice the capital 'S'

Apart from that. the variables. name1 and name2 are not declared anywhere.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: aznswti85 is an unknown quantity at this point 
Solved Threads: 0
aznswti85 aznswti85 is offline Offline
Newbie Poster
 
0
  #6
Oct 27th, 2009
Yes i already know about the case sensitive C++ and have fixed that error already but nobody is answering my question. HOW DO I DECLARE A STRING?? HOW DO I FIX WHAT IS WRONG WITH THIS CODE????????????????
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,282
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 158
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
1
  #7
Oct 27th, 2009
>>WHAT IS WRONG WITH THIS CODE?
1) You do not use code tags
2) You haven't included the necessary library
3) I don't think you understand what the question is asking, so
understand it before you write the program.

I'll try to break the question down for you :
  1.  
  2. Write a program that uses cin to read a given name (like Louis) and a family name (like Armstrong) into two string variables, given and family.
  3. //Meaning you have 2 string variables called family and given, and
  4. //you need to ask the user to input a first name and a last name
  5.  
  6. The program then makes assignments to two other string variables: givenFirst and givenLast. To givenFirst it assigns the concatenation of given, a space, and family.
  7. //means that you need 2 other string variables called givenFirst and
  8. //givenLast. And to givenFirst you need to concatenate or add the
  9. //string variable given, a space and the string variable family.
  10. //Here is an example :
  11. string givenFirst = given + " " + family
  12.  
  13. To givenLast, it assigns the concatenation of family, a comma followed by a space, and given.
  14. //same concept as above, try it out.
1) What word becomes shorter if you add a letter to it? 
      [ Solved by : niek_e, Paul Thompson, SgtMe]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
      [*solved by : murtan]
3) What is the 123456789 prime numer?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 21
Reputation: IT seeker is an unknown quantity at this point 
Solved Threads: 0
IT seeker IT seeker is offline Offline
Newbie Poster
 
-1
  #8
Oct 27th, 2009
here is statment write c++ statements the include the headerfiles iostraem and string

see i make wrong or right

#include<iostream>
using namespace std:;( i dont know about std so plz explain)
int main()
{
cout<<"a"<<endl
return 0;
}
is it right
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC