Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
def string_test(s):
    d={"UPPER_CASE":0, "LOWER_CASE":0}
    for c in s:
        if c.isupper():
           d["UPPER_CASE"]+=1
        elif c.islower():
           d["LOWER_CASE"]+=1
        else:
           pass
    print ("Original String : ", s)
    print ("No. of Upper case characters : ", d["UPPER_CASE"])
    print ("No. of Lower case Characters : ", d["LOWER_CASE"])

string_test('The quick Brown Fox')


What I have tried:

I need to convert this code as a C++ code. Also i have to draw a flowchart but i can do it myself. Could you help me to just convert it. Thank you.
Posted
Updated 27-Aug-20 3:01am
v2
Comments
F-ES Sitecore 27-Aug-20 7:58am    
This isn't a code translating service, and if you get someone else to do your homework then you haven't learned anything.

Try
C++
#include <iostream>
#include <string_view>
#include <cctype>

using namespace std;

class Foo
{
  int lco, uco;

public:
  Foo(std::string_view s):lco{},uco{}
  {
    for (const auto & c : s)
      islower(c) ? ++lco : isupper(c) ? ++uco : 0;
  }
  int lower(){return lco;}
  int upper(){return uco;}
};


int main()
{
  std::string_view test{ "The quick Brown Fox" };

  Foo f(test);

  std::cout << "Original String: " << test << endl;
  std::cout << "No. of Upper case characters: " <<  f.upper() << endl;
  std::cout << "No. of Lower case characters: " <<  f.lower() << endl;
}
 
Share this answer
 
Comments
Richard MacCutchan 27-Aug-20 9:11am    
+5 for such elegant code.
CPallini 27-Aug-20 9:57am    
Thank you very much, Richard.
This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be “good code” in the target language – they are based on very different frameworks, and what makes something work in one language does not always “translate” directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work “straight out of the box”.
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it w=from scratch using the original as a “template”. You will get a much, much better result that will save you a lot of time in the long run.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900