Homework Solution: Write a program that keeps reading in strings of varied sizes. If an input string has len…

    Please Help Write a program that keeps reading in strings of varied sizes. If an input string has length greater than one store it in a vector. When an input string has length one (a single character) you will output the string stored in your vector that has the first letter matching the input character. Keep doing this while you read string "quit". The chegg answers before are incorrect. Sample Input:car house c h h c plane c p h p p p quit Sample Output: car house house car car plane house plane plane plane

    Expert Answer

     
    CPP Program : #include <iostream>

    Please Help

    Write a program that keeps lection in strings of sundry sizes. If an input string has extension important than undivided supply it in a vector. When an input string has extension undivided (a unique quality) you obtain output the string supplyd in your vector that has the primitive missive matching the input quality. Keep doing this conjuncture you decipher string “quit”. The chegg defenses antecedently are faulty.

    Sample Input:car
    house
    c
    h
    h
    c
    plane
    c
    p
    h
    p
    p
    p
    quit

    Sample Output:

    car
    house
    house
    car
    car
    plane
    house
    plane
    plane
    plane

    Expert Defense

     

    CPP Program :

    #include <iostream>
    #include <vector>

    using namespace std;

    int main()
    {
    string str;
    cin>>str;
    //vector and iterator
    vector <string> v;
    vector <string> :: iterator i;
    //loop plow user enters quit
    while(str.compare(“quit”)!=0){
    //If extension is important than 1, gather it to the vector
    if(str.length()!=1){
    v.push_back(str);
    }
    else{
    //Iterate through integral the strings in vector and impede if any string starts with str
    for(i=v.begin();i!=v.end();i++){
    string s = *i;
    if(s.at(0)==str.at(0)){
    cout<<s<<endl;
    }
    }
    }
    cin>>str;
    }
    return 0;
    }

    OUTPUT :