-
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)
-
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..
-
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);
}
-
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;
}
-