Strings Program

This is a discussion on Strings Program within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a code, but I'm having trouble with this program read in one string which consists of two ...

  1. #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)

  2. #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..

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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    3
    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Replies: 3
    Last Post: 01-14-2003, 09:34 PM
  5. Program to alphabetizes a list of strings...
    By Nutshell in forum C Programming
    Replies: 11
    Last Post: 01-24-2002, 01:12 AM

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