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; }
9 ответов
+ 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)
+ 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
+ 4
You're welcome buddy
+ 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'
+ 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'
+ 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
0
it's nt still clear to me
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
0
tanks for the info guys.it has added more to me