MIS Midterm Review

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

int ID = 10;

Which of the following is to create a variable named ID that stores the number 10 as an integer? int ID & ID = 10; int ID = Console.ReadLine(10); string ID = "10"; int ID = 10;

string score = 10.5

Which one here is a wrong command in C#? string score = 10.5 int score = 10 You Answered string score = "10" double score = 10.5

P3

What is the format specifier and precision specifier that changes a number to a percent with three decimal places? (i.e. 75.841%) P3 D3 N3 C3

Write a console application that places double quotes around each word in a string.

(1) WriteLine("Enter a string:"); (2) string mystring = ReadLine(); (3) myString = "\"" + myString.Replace(" ", "\" \"") + "\""; (5) WriteLine($"Added double quotes around words: {myString}");

Write a console application that accepts a string and replaces all occurrences of the string no with yes.

(1) WriteLine("Enter a string:"); (2) string mystring = ReadLine(); (3) myString = myString.Replace("no", "yes"); (5) WriteLine($"Replaced: \"no\" with \"yes\": {myString}");

Write a console application that accepts a string from the user and outputs a string with the characters in reverse order.

(1) WriteLine("Enter a string:"); (2) string mystring = ReadLine(); (3) string reversedString = ""; (4) for (int index = mystring.Length - 1; index >= 0; index--) (5) { (6) reversed string += mystring[index]; (7) } (8) WriteLine($"Reversed: {reversedString}");

False

A defined constant number (e.g., 0.085 as tax rate) can be assigned with a new value later. True of false? True It depends... False

2 3 4

After running the following loop inside a C# program, what will be the output if the variable "number" equals 1? while (number <= 3) { Console.Write($"{++number}, "); //output in one line; } ++1 ++2 ++3 1 2 3 2 3 4 1 2 3 4

1 2 3

After running the following loop inside a C# program, what will be the output if the variable "number" equals 1? while (number <= 3) { Console.Write($"{number++} "); //output in one line; } 1++ 2++ 3++ 1 2 3 2 3 4 1 2 3 4

Three lines of "Congrats" will be shown

After running the following loop inside a C# program, what will be the output if the variable "number" equals 1? while (number <= 3) { Console.WriteLine("Congrats"); ++number; } Four lines of "Congrats" will be shown Three lines of "Congrats" will be shown Two lines of "Congrats" will be shown One line of "Congrats" will be shown

Three lines of "Congrats" will be shown

After running the following loop inside a C# program, what will be the output if the variable "number" equals 1? while (number <= 3) { Console.WriteLine("Congrats"); number++; } Four lines of "Congrats" will be shown Three lines of "Congrats" will be shown Two lines of "Congrats" will be shown Only one line of "Congrats" will be shown

{i} {i} {i}

After running the following loop inside a C# program, what will be the output? for (int i = 0; i < 3; i++) { Console.Write("{i} "); //output in one line; } 0 1 2 1 2 3 {i} {i} {i} {0} {1} {2}

0 1 2

After running the following loop inside a C# program, what will be the output? for (int i = 0; i < 3; i++) { Console.Write($"{i} "); //output in one line; } 0 1 2 1 2 3 {i} {i} {i} {0} {1} {2}

3 2 1

After running the following loop inside a C# program, what will be the output? for (int i = 3; i > 0; i--) { Console.Write($"{i} "); //output in one line; } 0 1 2 1 2 3 3 2 1 i} {i} {i}

the * and / operators have the highest precedence here, followed by %, +, and finally +=. The precedence in the exercise can be illustrated using parentheses as follows: resultVar += (((var1 * var2) + var3 %) (var4 / var5));

By considering operator precedence, list the steps involved in the computation of the following expression: resultVar += var1 * var2 + var3 % var4 / var5;

Which of the following conversions can't be performed implicitly? a. int to short b. short to int c. bool to string d. byte to float

CANNOT: a. int to short c. bool to string

As many as I want

How many "else if" statements can your program contain? Only 1 Up to 5 None As many as I want

(var1 > 10) ^ (var2 > 10)

If you have two integers stored in variables var1 and var2, what Boolean test can you perform to determine whether one or the other (but not both) is greater than 10?

super.smashing.great

In the following code, how would you refer to the name great from code in the namespace fabulous? namespace fabulous { // code in fabulous namespace } namespace super { namespace smashing { // great name defined } }

No, there is no theoretical limit to the size of a string that may be contained in a string

Is the string "supercalifragilisticexpialidocious" too big to fit in a string variable? If so, why?

True

The IF statement in general is more versatile and powerful than ternary operator. True False

False

The following DO-WHILE loop will NOT run the code in the brackets until the condition is FALSE. do { } while (true); True False

False

The following FOR-loop will stop if the "i < length" condition is met. for (int i = 0; i < length; i++) { } True False

True

The following WHILE loop will only run the code inside the brackets if the condition is true. while (true) { } True False

False

The following program is correct. string name = "John"; if (name = "John") { ...; } else { ...; } True False

False

The following program is correct: double gpa = 3.2; if (gpa <= 3.5); { ...; } else { ...; }

False

The following statement is to judge whether a score is between 60 and 80: if (score => 60 && score <= 80) True False

string MyMoney = cash.ToString();

To convert a number variable (called cash) into a string variable (called MyMoney), we should use ____ cash.ToString(); string MyMoney = cash.ToString(); string MyMoney = cash; string MyMoney = cash.ToString;

20

What is the value of howManyShouldIBuy if the user enters 100? 50 40 35 30 20 int itemPrice = Convert.ToInt32(Console.ReadLine()); int howManyShouldIBuy; if (itemPrice < 10) { howManyShouldIBuy = 50; } else if (itemPrice > 10 && itemPrice <= 20) { if (itemPrice == 15) { howManyShouldIBuy = 40; } else if (itemPrice > 15) { howManyShouldIBuy = 35; } else { howManyShouldIBuy = 30; } } else { howManyShouldIBuy = 20; }

20

What is the value of howManyShouldIBuy if the user enters 10? 50 40 35 30 20 int itemPrice = Convert.ToInt32(Console.ReadLine()); int howManyShouldIBuy; if (itemPrice < 10) { howManyShouldIBuy = 50; } else if (itemPrice > 10 && itemPrice <= 20) { if (itemPrice == 15) { howManyShouldIBuy = 40; } else if (itemPrice > 15) { howManyShouldIBuy = 35; } else { howManyShouldIBuy = 30; } } else { howManyShouldIBuy = 20; }

40

What is the value of howManyShouldIBuy if the user enters 15? 50 40 35 30 20 int itemPrice = Convert.ToInt32(Console.ReadLine()); int howManyShouldIBuy; if (itemPrice < 10) { howManyShouldIBuy = 50; } else if (itemPrice > 10 && itemPrice <= 20) { if (itemPrice == 15) { howManyShouldIBuy = 40; } else if (itemPrice > 15) { howManyShouldIBuy = 35; } else { howManyShouldIBuy = 30; } } else { howManyShouldIBuy = 20; }

35

What is the value of howManyShouldIBuy if the user enters 20? 50 40 35 30 20 int itemPrice = Convert.ToInt32(Console.ReadLine()); int howManyShouldIBuy; if (itemPrice < 10) { howManyShouldIBuy = 50; } else if (itemPrice > 10 && itemPrice <= 20) { if (itemPrice == 15) { howManyShouldIBuy = 40; } else if (itemPrice > 15) { howManyShouldIBuy = 35; } else { howManyShouldIBuy = 30; } } else { howManyShouldIBuy = 20; }

the code should be read: int i; for (i = 1; i <= 10; i++) { if ((i % 2) == 0) continue; WriteLine(i); }

What is wrong with the following code? int i; for (i = 1; i <= 10; i++) { if ((i % 2) = 0) continue; WriteLine(i); }

string

What variable type is used to store user input from Console.ReadLine(); string int double char

float

What variable type(s) can be used to store mathematical numbers? bool float string All of the above

Console.WriteLine("How are you doing today?");

Which answer properly displays a sentence, "How are you doing today?" Console.WriteLine("How are you doing today?"); Console.writeline("How are you doing today?"); Console.Writeline(How are you doing today?); Console.WriteLine(How are you doing today?);

Console.WriteLine(pi.ToString("N2"));

Which format specifier transforms the variable (named pi) to have only two decimal places (i.e, 3.14) in the output? Console.ReadLine(pi.ToString("N2")); Console.WriteLine(pi.ToString("P4")); Console.WriteLine(pi.ToString(N3)); Console.WriteLine(pi.ToString("N2"));

99Flake because it starts with a number wrox.com because it contains a full stop

Which of the following is not a legal variable name? myVariableIsGood 99Flake _floor time2GetJiggyWidIt wrox.com

Console.WriteLine("OU won game " + wins + " by " + Score + " points!");

double Score= 21; double wins = 7; Based on these two variables, to compose a quick headline for OU's last football game, which line correctly concatenates the variables as output? Console.WriteLine("OU won game " + wins + " by " + Score + " points!"); Console.WriteLine("OU won game " + wins + by + Score + points!); Console.WriteLine("OU won game " && Wins && " by " && score && " points!"); Console.WriteLine("OU won game " , wins , " by " , Score , " points!");

False

if (itemPrice == 15) This expression can be interpreted as "if variable itemPrice is assigned a value of 15 (then we run the following line...)". True False


Ensembles d'études connexes

SVM, CNN, NLP, LSTM Midterm Study Guide

View Set

ECON 1710 Midterm #2 Multiple Choice

View Set

Chapter 49: Drugs Used to Treat Anemias

View Set

9: Perfect Competition: Videos with Questions

View Set