🔒 Closed C language [HELP]

Status
Not open for further replies.

velvetred

Forum Veteran
Screenshot (500).webp
 
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
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 8
    Replies
  • 1K
    Views
  • 3
    Participants
Last reply from:
velvetred

Online now

Members online
530
Guests online
1,262
Total visitors
1,792

Forum statistics

Threads
2,277,853
Posts
28,979,277
Members
1,229,112
Latest member
rosearugay
Back
Top