Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Last edited:
#include <iostream>
#include <string>
using namespace std;
string Str1, Str2;
void DisplayTheTwoStrings()
{
cout << endl << Str1;
cout << endl << Str2;
}
void DisplayLengthOfTwoStrings()
{
cout << endl << "Length of string1: " << Str1.length();
cout << endl << "Length of string2: " << Str2.length();
}
void ConnectString1ToString2()
{
cout << endl << Str2 << Str1;
}
void ChangeString1ToLowerCase()
{
for (int x = 0; x < Str1.length(); x++)
{
Str1[x] = tolower(Str1[x]);
}
cout << endl << Str1;
}
void ChangeString2ToUpperCase()
{
for (int x = 0; x < Str2.length(); x++)
{
Str2[x] = toupper(Str2[x]);
}
cout << endl << Str2;
}
int main()
{
cout << "Enter string 1: ";
getline (cin,Str1);
cout << endl << "Enter string 2: ";
getline (cin, Str2);
DisplayTheTwoStrings();
DisplayLengthOfTwoStrings();
ConnectString1ToString2();
ChangeString1ToLowerCase();
ChangeString2ToUpperCase();
}
thank you poC++:#include <iostream> #include <string> using namespace std; string Str1, Str2; void DisplayTheTwoStrings() { cout << endl << Str1; cout << endl << Str2; } void DisplayLengthOfTwoStrings() { cout << endl << "Length of string1: " << Str1.length(); cout << endl << "Length of string2: " << Str2.length(); } void ConnectString1ToString2() { cout << endl << Str2 << Str1; } void ChangeString1ToLowerCase() { for (int x = 0; x < Str1.length(); x++) { Str1[x] = tolower(Str1[x]); } cout << endl << Str1; } void ChangeString2ToUpperCase() { for (int x = 0; x < Str2.length(); x++) { Str2[x] = toupper(Str2[x]); } cout << endl << Str2; } int main() { cout << "Enter string 1: "; getline (cin,Str1); cout << endl << "Enter string 2: "; getline (cin, Str2); DisplayTheTwoStrings(); DisplayLengthOfTwoStrings(); ConnectString1ToString2(); ChangeString1ToLowerCase(); ChangeString2ToUpperCase(); }
void ConnectString1ToString2()
{
Str2 = Str2 + Str1;
cout << endl << Str2;
}
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
int main()
{
string Input, buf;
vector<string> words;
cout << "Enter sentence: ";
getline(cin, Input);
stringstream ss(Input);
while (ss >> buf)
{
words.push_back(buf);
}
for (int i = 0; i < words.size(); i++)
{
cout << endl << words[i] << " [length: " << words[i].length() <<"]";
}
getchar();
}
thank you poC++:#include<iostream> #include<string> #include<sstream> #include<vector> using namespace std; int main() { string Input, buf; vector<string> words; cout << "Enter sentence: "; getline(cin, Input); stringstream ss(Input); while (ss >> buf) { words.push_back(buf); } for (int i = 0; i < words.size(); i++) { cout << endl << words[i] << " [length: " << words[i].length() <<"]"; } getchar(); }