C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-02-2006, 01:32 PM   #1
Registered User
 
Join Date: Dec 2006
Posts: 3
Strings Program

Hi, I have a code, but I'm having trouble with this program

read in one string which consists of two words Ex. "Computer Science"
call a function makewords() which receives three parameters: a string which holds the original phrase and two strings to hold the two words.

Your function, makewords(), should then check if the 2 new strings are equal to each other, and print the appropriate message saying whether or not they are equal.
print out the two words and their sizes.

call the function matchexact() passing the two strings. matchexact() will determine how many times the corresponding positions in the two strings hold exactly the same characters. The function will print this value.
For example, if the two strings are "marriage" and "gerbil", then the function matchexact will return 2, since the two strings have the same characters in positions 2 and 5.
If the two strings are "starts" and "tarts", then the function will return 0, since the two strings never have the same characters in the same positions.
The main program will then call a function jointhem() which receives the two strings. The function will join the two strings together and print the new string. Ex. if string1 is “bath” and string2 is “water” than the new string is “bathwater”



Code:
#include <iostream>
#include <string>
using namespace std;
void foo(string);

int main()
{
   string string1 = "Computer Science";
   foo(string1);
}


void foo(string x)
{
    cout << x;
}

matchwords( int a ,int b, int c)
limergal is offline   Reply With Quote
Old 12-02-2006, 01:41 PM   #2
Registered User
 
Join Date: Nov 2006
Posts: 86
Im sorry, i would want to help u , but this seems like u didnt try urself and it looks like its homework or somthing.0..
epidemic is offline   Reply With Quote
Old 12-02-2006, 01:52 PM   #3
Registered User
 
Join Date: Dec 2006
Posts: 3
It is Hw, but it says that If I show some effort that any of you guys will be willing to help me understand how to get to accomplishing the task. I started out with a previous way of doing this problem before, but it's totally wrong....

here look at what I did before
Code:
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
strings [50];
string  ("Computer Science");
cout<<"Computer Science";
 
makewords( int a, int b, int c);
 
 }
limergal is offline   Reply With Quote
Old 12-02-2006, 02:20 PM   #4
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Maybe this'll help
Code:
#include<iostream>
#include<string>
using namespace std;

void makewords ( string a, string &b, string &c ) {
    // not quite, but it's a start for you to work on
    b = a;
    c = "word";
}

int main()
{
    string input="Computer Science";
    string first, second;
    makewords( input, first, second );
    cout << first << endl;
    cout << second<< endl;
}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 12-02-2006, 03:24 PM   #5
Registered User
 
Join Date: Dec 2006
Posts: 3
Thank you
limergal is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C Programming 3 03-04-2005 02:46 PM
I need some help with my program please. agentxx04 C Programming 9 09-26-2004 07:51 AM
Somewhat new to c++, adding Prime number and Sqrt featre to program... thynksheraze C++ Programming 3 01-14-2003 10:34 PM
Program to alphabetizes a list of strings... Nutshell C Programming 11 01-24-2002 02:12 AM


All times are GMT -6. The time now is 05:18 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22