COMM 205 Midterm Concordia University trial exam solution
1. A company purchases notebook and tablet computers for its operations for set prices.
Notebooks cost $1,100 and the tablets cost $450. Write a code fragment that takes the
number of notebooks and tablets as inputs and computes the total cost. The inputs are
provided through the textboxes txtNotebooks and txtTablets. The output should be displayed
in lblTotal. (10 points)
double txtNotebooks, txtTablets, total;
txtNotebooks = 1100;
txtTablets 450;
lblTotal.Text = total.ToString();
2. decimal a = 10m;
double b = a;
The above code has a problem. To correct it you need to usea.
Try-catch
b.
TryParse()
c.
Math class
d.
Casting
3. Which of the following conditions checks if price is between $10 and $20 inclusivelya.
price >= 10 || price <=20;
b.
price >= 10 && price <=20;
c.
20 >= price >= 10;
d.
10 <= price <= 20;
, The switch statement has the following structure:
switch (test variable or expression)
{
case value_1: …
case value_2: …
}
The valid types of test variable (or expression) include all of the
following, except:
a.
string
b.
double
c.
char
d.
int
If quantity has a value of 5, what is the value of discount after these statements are
executed?
switch (quantity) {
case 1: discount = 0; break;
case 2:
case 3:
discount = .1; break;
default:
discount = .2; break;
}
1. A company purchases notebook and tablet computers for its operations for set prices.
Notebooks cost $1,100 and the tablets cost $450. Write a code fragment that takes the
number of notebooks and tablets as inputs and computes the total cost. The inputs are
provided through the textboxes txtNotebooks and txtTablets. The output should be displayed
in lblTotal. (10 points)
double txtNotebooks, txtTablets, total;
txtNotebooks = 1100;
txtTablets 450;
lblTotal.Text = total.ToString();
2. decimal a = 10m;
double b = a;
The above code has a problem. To correct it you need to usea.
Try-catch
b.
TryParse()
c.
Math class
d.
Casting
3. Which of the following conditions checks if price is between $10 and $20 inclusivelya.
price >= 10 || price <=20;
b.
price >= 10 && price <=20;
c.
20 >= price >= 10;
d.
10 <= price <= 20;
, The switch statement has the following structure:
switch (test variable or expression)
{
case value_1: …
case value_2: …
}
The valid types of test variable (or expression) include all of the
following, except:
a.
string
b.
double
c.
char
d.
int
If quantity has a value of 5, what is the value of discount after these statements are
executed?
switch (quantity) {
case 1: discount = 0; break;
case 2:
case 3:
discount = .1; break;
default:
discount = .2; break;
}