Shape.pdf
322.1 KB
β€2
To register for the premium class of C++, π [@ProgrammingWithFaith_bot] π
β€1
Media is too big
VIEW IN TELEGRAM
β
Pattern Using Loop part one
*
* *
* * *
* * * *
To register for the premium class of C++, π [@ProgrammingWithFaith_bot] π
@ProgrammingWithFaith2018
*
* *
* * *
* * * *
To register for the premium class of C++, π [@ProgrammingWithFaith_bot] π
@ProgrammingWithFaith2018
β€2
β€5π2π₯1π1
C++ Basic 2018 (Batch-2)
Should I post the Entrepreneurship Business Plan assignment? πβ¨ @ProgrammingWithFaith2018
I will post it, but you need to share this channel with other students. We need to reach 750 subscribers first.
@ProgrammingWithFaith2018
@ProgrammingWithFaith2018
β€2
β€4
C++ Basic 2018 (Batch-2)
Photo
using namespace std;
int main() {
char pressAletter;
cout << "Press any character" << endl;
cin >> pressAletter;
switch (pressAletter) {
case 'A':{
int f = 3, g = 4, h, k;
h = (2 * 34/2 + (g++)) - 4 * f+(++f) + 4 / (++g);
k = ++f + g++;
cout << "The value of f is: " << f << endl;
cout << "The value of g is: " << g << endl;
cout << "The value of h is: " << h << endl;
cout << "The value of k is: " << k << endl;
break;}
case 'B':{
int num = 5, i = 30;
do {
num*=4;
i++;
} while (i <= 20);
cout << "The value of a number is: " << num << endl;
break;}
default:
cout << "You do not have this option" << endl;
}
return 0;
}
When we press case "A", it will be executed. Let us compute this:
int f = 3, g = 4, h, k;
h = (2 * 34 / 2 + (g++)) - 4 * f + (++f) + 4 / (++g);
h = (2 * 34 / 2 + 4) - 4 * f + (++f) + 4 / (++g);
h = (38) - (4 * f) + (++f) + (4 / (++g));
h = (38) - 12 + (++f) + 4 / (++g);
h = (38) - 12 + 4 + 4 / 5; // 0.8, but the data type is integer, so it will be 0.
h = (38) - 12 + 4 + 0;
h = 30 - 8 + 0;
h = 30;
k = ++f + g++; // Here, the value of f will increment by one because it is pre-increment: f = 4 + 1 = 5. However, the value of g remains 6 because in the previous line it was incremented twice (once pre-increment and once post-increment), making it 6. Here it is still 6, and after this operation, it will become 7.
k = 5 + 6 = 11.
So finally: h = 30, k = 11, f = 5, g = 7.
When we press B, case "B" will be executed. Let us compute it:
int num = 5, i = 30;
do {
num *= 4;
i++;
} while (i <= 20);
cout << "The value of a number is: " << num << endl;
So, it is a do-while loop; it will enter the loop. num = 5 * 4 = 20; then i will be 31. The check if 31 <= 20 is false, so it will terminate the loop and output: The value of a number is 20.
When we press neither A nor B the default part will be executed "You do not have this option"
1. When we press A, what will be the output of lines 14 and 15?
β A (5 & 7)
2. When we press A, what will be the output of lines 16 and 17?
β D (30 & 11)
3. When we press B, what will be the output of line 28?
β B (20)
4. Neither A nor B.
β D (none)
5. The data types of this program are character and integer.
β D (A & B)
6.β B(ROM)
@ProgrammingWithFaith2018
β€3
To register for the premium class of C++, π [@ProgrammingWithFaith_bot] π
β€2π1
If you have paid for the registration and it is still not approved, DM me @TechnerdGuy.
β€2
To register for the premium class of C++, π [@ProgrammingWithFaith_bot] π
β€4