0

can sm1 pls explain wat "element+='A' - 'a' " means in dat code

char upper case() { if((element>='a')&&(element<='z')) element+='A' - 'a'; return element; }

24th Apr 2020, 12:15 PM
Azudi kenneth Chinedu
Azudi kenneth Chinedu - avatar
9 odpowiedzi
+ 3
To each letter in computer ASCII value is assigned, computer works on letter as no. , means , a=97, b=98, c=99................ Similarly , A=65,B=66,C=67 Now to convert, a to A in computer We need to substract 32 while to if you don't know exact way then , you can go with, element+='A'-'a' Means element +=(65-97) Means element +=(-32)
24th Apr 2020, 1:16 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 5
Many here can clear your doubt I'm sure, but first, you need to save a full version of the code and share the link instead. Your snippet has missing links, for example, where <element> was defined. Function name should not contain any space, so `char upper case()` does not conform. And please specify a relevant language in your thread tags, you joined many courses it's hard to predict by language context. Follow this guide to share your code link, in case you didn't know 👇 https://www.sololearn.com/post/75089/?ref=app
24th Apr 2020, 12:37 PM
Ipang
+ 4
You're welcome buddy
24th Apr 2020, 1:28 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
'A'-'a' =-32 which can convert any small letter to capital letter , that is let c =element =99 then element+=-32 element =99-32 element =67 char element ='C' and this will change 'j' to 'J'
24th Apr 2020, 1:18 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 2
Hiiii, char 'A' = int 65, char 'a'= int 97 , This part of code works as , any lower case letter 'element ' is converted to upper case , as 32 is subtracted from it's ASCII value . i.e. a=97-32=65 Char 65 == 'A'
24th Apr 2020, 12:47 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 2
Bro you code has , 'A'-'b' which is producing an output of Element +=-33 It is result I for j because of same reason , and Your question has different value, check them again
24th Apr 2020, 1:27 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
0
it's nt still clear to me
24th Apr 2020, 1:11 PM
Azudi kenneth Chinedu
Azudi kenneth Chinedu - avatar
0
#include <iostream> using namespace std; template <class T> class mycontainer{ T element; public: mycontainer(T arg){element=arg;} T increase(){return ++element;} }; template <> class mycontainer <char>{ char element; public: mycontainer(char arg){element=arg;} char uppercase() { if((element>='a')&&(element<='z')) element+='A'-'b'; return element; } }; int main() { mycontainer <int> myint(7); mycontainer <char> mychar('j'); cout<<myint.increase()<<'\n'; cout<<mychar.uppercase(); return 0; } dat is d full code.pls explain wat dat 'A' - 'a' means
24th Apr 2020, 1:17 PM
Azudi kenneth Chinedu
Azudi kenneth Chinedu - avatar
0
tanks for the info guys.it has added more to me
24th Apr 2020, 1:26 PM
Azudi kenneth Chinedu
Azudi kenneth Chinedu - avatar