Question

in c# 1- What is the output for total after the following segment of code executes?...

in c#

1- What is the output for total after the following segment of code executes?
int num = 3, total = 0;
switch (num)
{
               case 1:
               case 2:
                              total = 5;
                              break;
               case 3:
                              total = 10;
                              break;
               case 4:
                              total = total + 3;
                              break;
               case 8:
                              total = total + 6;
                              break;
               default:
                              total = total + 4;
                              break;
}
WriteLine("The value of total is " + total);
The value displayed for total would be . If num had been initialized to 100,  would be displayed. If num was initialized to 1,  would be displayed.

2-

Given the switch statement, which of the following would be the first if statement to replace the first test in the switch?
switch (control)
{
               case 11 :
                              WriteLine("eleven");
                              break;
               case 12 :
                              WriteLine("twelve");
                              break;
               case 16 :
                              WriteLine("sixteen");
                              break;
}

A.if (case = 11)

B.if (case == 11)

C.if (control == 11)

D.if (switch == 11)

E.none of the above

3- Assuming the following declarations:
int a is 5,
   b is 6,
c is 8;
which of the result (true or false) of each of the expressions. Identify the result of each of the expressions.
a. (1 + a) != b; _______________
b. a >= 0; _________________
c. a <= (b * 2); ______________

4-

Assuming the following declarations:

int    a is 5,
  b is 6,
   c is 8;
which of the result (true or false) of each of the expressions. Identify the result of each of the expressions.
a. a == 5; ____________   
b. 7 <= (a + 2); ____________
c. c <= 4; ____________

5- If you were to write switch statements to perform the following evaluation, what selector would be placed inside the parenthesis for each of the following scenarios?  
switch ( ? )
a. __________ Testing string stateName for FL, GA, or MS. Storing 1 in cnt for FL, 2 for GA, 3 for MS
b. ____________ Testing cnt for 1, 5 or 7. Storing 100 in value1 when cnt is 1, storing 10 in value1 when cnt is 5 and storing 1 in value1 when cnt is 7
c. _____________ When middleInitial is equal to the character z, a message should be displayed stating “You’re one in a thousand”; otherwise, check to see if it is equal to the character ‘a’. When it is equal to the character a, display the message “You have the most common initial”. If it’s not equal to ‘a’ or ‘z’ the message should read “Just another initial”.


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:---------

  1. Output for total after the given segment is  10, If num had been initialized to 100, then 4 would be displayed. If num was initialized to 1, then 5 would be displayed.
  2. C.if (control == 11)
  3. a. (1 + a) != b; ==> False
    b. a >= 0; ==> True
    c. a <= (b * 2);  ==> False
  4. a. a == 5;  ==> True
    b. 7 <= (a + 2); ==> True
    c. c <= 4;  ==> True
  5. a. stateName
    b. cnt
    c. middleInitial
Add a comment
Know the answer?
Add Answer to:
in c# 1- What is the output for total after the following segment of code executes?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is the value of  result after the following code executes?   int a = 60; int b...

    What is the value of  result after the following code executes?   int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...

  • C# What is the output of the code segment below? int valueA = 20; int valueB...

    C# What is the output of the code segment below? int valueA = 20; int valueB = 5; int valueC = 8; int result = 1; if (valueA > valueB) result = valueA - valueB; else if (valueA > valueC) result = result + valueB; WriteLine(“{0} is the answer”, result);

  • should be in C language What is the output of the following segment of C code:...

    should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • C++ Program What is the output of the following code fragment?(beta is of type int.) beta...

    C++ Program What is the output of the following code fragment?(beta is of type int.) beta = 5; do { switch (beta) { case 1: cout <<'R'; break; case 2: cout case 4: cout << 'O'; break; case 5: cout << 'L'; } beta--; }while (beta>1); cout <<'X';

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now...

    Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively. The class contains an auto-implemented property Name that holds a contestant’s name. The class contains fields for a talent code (talentCode) and description (talent)....

  • C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2,...

    C# 1.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray.Rank); 2.)Using the following declaration: int [ , ] exampleArray = {{3, 5, 6, 7}, {2, 8, 9, 22}, {1, 0, 4, 11}}; ______________ would be displayed if the following output statement was executed. WriteLine(exampleArray[0, 2]); 3.) Using the following declaration: int [ , ] exampleArray...

  • Please try to explain the answers as well. It will be highly appreciated. Output of the...

    Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32)                 num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT