What's new

C & C++ C language [HELP]

velvetred

Eternal Poster
Joined
May 4, 2022
Posts
704
Solutions
17
Reaction
1,244
Points
444
Screenshot (500).png
 

Attachments

Last edited:
C++:
#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();
}
 
C++:
#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 po
 
Patulong po ulit C language po ito

Input a sentence. Display each word and determine the length of each word
 
C++:
#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();
}
 
C++:
#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 po
 

Similar threads

Back
Top