Need help with quesitons: 1).Create a program in C++ or C# that forces one data
ID: 3797907 • Letter: N
Question
Need help with quesitons:
1).Create a program in C++ or C# that forces one data type to be converted into another (using explicit type conversion). Show the Source code.
2)Do you think the elimination of overloaded operators in a language would be beneficial? Why or why not
3)Assume the following rules of associativity and precedence for expressions:
Precedence:
Highest *, /, not+, –, &, mod–(unary)=, /=, <,<= , >=, >and
Lowest or, xor
Associativity Left to right
Show the order of evaluation of the following expressions by parenthesizing all subexpressions and placing a superscript on the right parenthesis to indicate order.
For example, for the expression a + b * c + d
the order of evaluation would be represented as
((a + (b * c)1)2 + d)3
a. a * b–1 +c
b. a * (b–1) / cmod d
c. (a–b) / c & (d * e / a–3)
d. -a or c = d and e
e. a > b xor c or d <= 17
f. -a + b
Now show the order evaluation of the expression (in a thru f), assuming that there are no precedence rules and all operators associate right to left.
Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int i = 50;
cout<<"Integer i is "<<i<<endl;
char ch = static_cast<char>(i);
cout<<"After explicit conversion of integer i into Character is "<<ch;
return 0;
}
Output:
Character is 2akshay@akshay-Inspiron-3537:~/Chegg$ g++ test.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Integer i is 50
After explicit conversion of integer i into Character is 2
=======================================================================================
2)Ans:
Yes, the elimination of overloaded operators in any language would be beneficial.It will have following advantages
i)It increases and enhances readabilty.
ii)It reduces compiler overhead by reducing ambiguity in operator use.
Because of above reasons java doesnt support operator overloading
======================================================================================
3)
a) a * b–1 +c
(((a * b)1–1)2 +c)3
b)
a * (b–1) / cmod d
( ( ( a * ( b 1 ) 1 ) 2 / c ) 3 mod d ) 4
c)(a–b) / c & (d * e / a–3)
( ( ( a -b ) 1 / c ) 2 & ( ( d * e ) 3 / a ) 4 3 ) 5 ) 6
d. -a or c = d and e
Ans:e ( ( -a ) 1 or ( ( c = d ) 2 and e ) 3 ) 4
e. a > b xor c or d <= 17
Ans: ( ( ( a > b ) 1 xor c ) 3 or ( d <= 17 ) 2 ) 4
f. -a + b
Ans:
( - ( a + b ) 1 ) 2
=======================================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.