Partage
  • Partager sur Facebook
  • Partager sur Twitter

uper to lower letters in c ++?.

    8 novembre 2019 à 14:45:35

    Hello,

    I start with Programming and C ++

    I want to Write a function that reverses talktosonic customer survey a string in-place and upcases every other character.

    "abc" => "CbA"

    a beginner in programming, I try to krogerfeedback survey invert words and turn others into uppercase 


    thanks

    iosman

    -
    Edité par SunnyLord 6 janvier 2020 à 12:15:03

    • Partager sur Facebook
    • Partager sur Twitter
      8 novembre 2019 à 21:49:44

      Hello, it's easy to find a solution online for each function case so here's a example

      I'm not very good in C++ so it can still be better

      // Example program
      using namespace std;//mostly good c++ programmers don't like declaring this 
      //but i prefer because i don't like to use std:: (ex : std::string s = "example")
      #include <iostream>
      #include <string>
      
      //Will upcase every character in difference between the first string and the second
      void upCaseNonDifference(string& str, string str2){
      
      
      for(int i=0;(unsigned)i<str.length();i++){
      
          if (str[i] != str2[i]){
              str[i] = toupper(str[i]);   
      }
          
          
      }   
          
      }
      
      //reverse the string given in parameter
      void reverseStr(string& str) 
      { 
          int n = str.length(); 
        
          // Swap character starting from two 
          // corners 
          for (int i = 0; i < n / 2; i++) 
              swap(str[i], str[n - i - 1]); 
      } 
      
      //upcase the difference between the given string and his reverse
      void reverseAndUpCaseNonDifference(string& str){
          
          string str2 = str;
          reverseStr(str);
          upCaseNonDifference(str,str2);
          
      }
      
      int main()
      {
      
      string s = "this , good , test";
      cout << "Originally :" << s << endl;
      reverseAndUpCaseNonDifference(s);
      cout << "After .... :" << s;
      
      }



      I Edited my code after I noticed that i misunderstood your message.



      -
      Edité par coukil 8 novembre 2019 à 23:26:32

      • Partager sur Facebook
      • Partager sur Twitter

      uper to lower letters in c ++?.

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown