You will get email Reply within few hours

Friday, 26 April 2013

C# week 8

1. (TCOs 1, 6) Which of the following is a type of C# error that results from invalid use of programming language rules? (Points : 5)

      Logic error
      Syntax error
       Runtime error
       Syntax error and runtime error





2. (TCOs 1, 6) Which keyboard function key do we use to compile and run a C# program within Visual Studio.NET? (Points : 5)

       F5
       F11
       F10
       F1



3. (TCOs 1, 6) In the context of object-oriented programming, the Solution Explorer window _____. (Points : 5)

       exposes the properties of the control
       shows the physical components of the program
       lists the events associated with a control
       lists the controls on the form



4. (TCOs 2, 3) The keyword “void” means that a method _____. (Points : 5)

       clears all variables it is passed
       does not return a value
       is invalid
       releases memory after it is called



5. (TCOs 2, 3) Which set of symbols should go in the blanks in the following block of code?

static void main()
___
Console.WriteLine("Hello World!");
___

(Points : 5)

     {}
     ()
     []
     /* */



6. (TCOs 2, 3) Use _____ to accept and ignore any single keypress from the user for purposes such as to keep the window open at the end of your console application.
(Points : 5)

       Console.Read();
       Console.ReadLine();
       Console.ReadChar();
       Console.Read(); or Console.ReadLine();



7. (TCO 4) If the expression (true OP false) evaluates to “true,” then what logical operator does OP represent? (Points : 5)

      AND
      OR
      NOT
      None of the above



8. (TCO 4) C# decision structures include _____ and _____. (Points : 5)

       IF, IF/ELSE
       IF, FOR
       FOR, FOREACH
       FOR, WHILE





9. (TCO 5) What output will this set of statements produce?

            int a = 10;
            while (a <= 10)
            {
                Console.Write("{0}\t", a);
                a--;
            }
            Console.Write("{0}\t", a);

(Points : 5)

       An infinite loop
       An exception
       10
       10 10



10. (TCO 5) Your program keeps asking for input from the user. If there is more input, the user types “Y” after entering the data. If there is no more input, he/she enters “N.” In this context, “Y” and “N” are used as _____. (Points : 5)

       accumulators
       counters
       integer data types
       sentinel values



1. (TCOs 7, 8) Given the following method call, which would be a valid prototype for the calcLetterGrade method?

char letterGrade;
letterGrade = calcLetterGrade(95.5);

(Points : 5)

       public static intcalcLetterGrade(double val);
       public static char calcLetterGrade(double val);
       public static double calcLetterGrade(double val);
       public static char calcLetterGrade(intval);









2. (TCOs 7, 8) Which is a correct heading for a method that returns the difference between two given doubles? (Points : 5)

       public static void CalcDiff(double price1, double price2);
       public static double CalcDiff(double price1 , anotherPrice)
       public static double CalcDiff(double price1 , double price2);
       public static CalcDiff(double price1, double price2);



3. (TCOs 7, 8) Which is a valid overloaded version of the following method?

float DetermineResults(float num1, float num2)

(Points : 5)

       float DetermineResults(double num1, float num2)
       float DetermineTheResults(float num1, float num2)
       void DetermineResults(float num1, float num2)
       double DetermineResults(float num1, float num2)



4. (TCOs 9, 10) Which of the following is not good programming practice? (Points : 5)

       Indenting the statements in the body of each control structure
       Using integer types for loop control variables
       Left-aligning nested repetition structures
       Placing vertical spacing above and below control structures



5. (TCOs 9, 10) A _____ is primarily used to provide descriptive text to let the user know the purpose of another control, such as a textbox. (Points : 5)

       Title
       Label
       Frame
       Button

 6. (TCOs 9, 10) Which of the following statements will retrieve the selected item of comboBoxEntrees and place it in a myString variable called “myStr”? (Points : 5)


       myStringmyStr = comboBoxEntrees.SelectedItem;
       myStringmyStr = comboBoxEntrees.Selection();
       myStringmyStr = comboBoxEntrees.Text;
       myStringmyStr = comboBoxEntrees.getText();




7. (TCOs 11, 12) To delete a specified number of characters from a String, use its _____ method. (Points : 5)

       Delete();
       Concat();
       Insert();
       Remove();



8. (TCOs 11, 12) Given the following declaration, what is/are the value(s) of inches[1,1]?

double[,] inches = { {2.25, 3.25, 4.5, 7.25},
{3.75, 4.75, 3.5, 3.75} };

(Points : 5)

       2.25
       2.25 3.75
       3.25 4.75
       4.75



9. (TCOs 11, 12) Which is not true about a C# array? (Points : 5)

       Its elements do not need to initialized when declared.
       It can be passed to a method for processing.
       It can have multiple dimensions.
       Its indexing starts at 1.



10. (TCO 13) The following C# statement will print out _____.

Console.WriteLine(Directory.GetCurrentDirectory());

(Points : 5)

       the name and path of the current directory
       the name of the current directory
       the path of the current directory
       all of the subdirectories of the current directory



11. (TCO 13) The _____ namespace enables your C# program to work with files and directories. (Points : 5)

       System.FILE.IO
       System.Collections.Generic
       System
       System.IO



12. (TCO 13) Because your C# program needs to read data from a file one character at a time, you choose to use the _____ member of the _____ class. (Points : 5)

       ReadChars(), StreamReader
       ReadChars(), BinaryReader
       ReadChar(), StreamReader
       ReadChar(), BinaryReader





1. (TCO 3) Show the source code for a C# console application called “Area” to display the area of a parking lot with length 203.5 ft. and width 30.5 ft. (Note that area is length times width.)

·  Declare and initialize appropriate variables for length and width.

·  Include at least three descriptive comments.

·  State what your program displays when it runs.

·  State how you would use the debugger to check the values of your variables as your program runs.

(Points : 20)



2. (TCO 5) Using a WHILE loop, write the C# code required to print every fifth integer on its own line, starting with 0 until the number is greater than 500. (i.e., 0, 5, 10, 15, etc.). Describe another type of loop that can also be used to implement this functionality. Which would be more efficient? (Points : 20)



3. (TCO 8) Briefly describe how parameter passing by-value and by-reference are accomplished in memory. Write statement 1 to call method A below. Write statement 2 to call method B. Which method uses pass by-value? Which method uses pass by-reference?

        static void Main()
        {
            double contrib = 2000;
            double diff = 0;
            //statement 1
            //statement 2
        }

              //method A
        public static double calcDifference(double contrib)
        {
            return (5000.00 - contrib);
        }

              //method B
        public static void calcDifference(double contrib, ref double diff)
        {
            diff = 5000 - contrib;
        }

(Points : 20)



4. (TCO 9) Identify an example of one of each of the following GUI design errors in Figure 2:

·  missing the target audience

·  misuse of color

·  misalignment

How could each of the three errors be corrected to improve the user experience?

Image Description

There is a rectangular tan colored windows form that is approximately two and one-half times wider than it is tall. The text of the form as described in the title bar reads Pete’s Pizza. On the windows form titled Pete’s Pizza are a total of 12 control objects scattered throughout the form.

The control that is in the upper-left portion of the form is a label control. The label control is approximately 1 inch from the left edge of the form and 1 inch from the top of the form. The black text on the label control reads Pete’s Pizza and it is underlined and italicized, as well as in bold font. There are no controls under that label.

In the middle part of that form are 4 of the 12 controls. The first control is a listbox control with its background color set to green. The listbox is 4 inches from the top of the form, and 3 inches from the left edge of the form. The listbox contains two items. The first item’s black text reads Pineapple and the second item’s black text reads Onions. Just beneath that listbox and centered under that listbox is a gray button control with black text which reads Order.

Just to the right of the listbox and button previously mentioned are 2 button controls each with their background color set to gray. The first button control is approximately 3 ¾ inches from the top of the form, and one inch to the right of the listbox. That blue text reads Reset on that button. Beneath that button approximately 1 inch below it is the second button. The second button’s black text reads OK. The word OK is all in uppercase. The height of the second button is much taller than the other button.

On the right side of the screen is the remaining set of controls. From approximately 3 and ½ inches from the top of the screen and ½ inch from the 2 previously mentioned buttons is a radiobutton control with the text reading Plain. Just beneath that orphaned radiobutton is a groupbox control with its caption reading "Toppings (choose any)." Inside that groupbox are 5 radiobutton controls. The radiobutton controls text read the following from top to bottom: Anchovies, Pepperoni, Peppers, Onion and Pineapple. The words anchovies and peppers are misspelled. Some of the text of the radiobuttons are different fonts, as well as some are bold and some are not. Some are aligned left and some are not.

 Press the ESC key to close the image description and return to lecture



(Points : 20)



5. (TCO 2) Although the following code compiles and runs, the programmer made some major readability errors. Describe at least three changes that would make it easier for other programmers to read and understand the code.

    class Program
    {
        static void Main() //main
        {
        int a;
        int Integer = 10; // ints
        for(inti = 0;i <Integer;i++) //loop
            {
        a=function(i);
        Console.WriteLine(a);
            }
        Console.Read();
        }
        public static int function(int a) //function
            {
        return (int)(Math.Pow((double)a,2.0));
        }
    }

(Points : 20)

6. (TCO 11) Write a C# program to store an array of integers 10 through 19. Use an appropriate loop to multiply all of the values in the list. Print out the result. (Points : 20) 
Need Solution https://gum.co/wTitd