1: | What are namespaces used for in C# and .NET? |

A: | Namespaces act as containers for classes. They help us organize the classes of our programs and to provide easy access to them (when reused) by outside parties. |

2: | What is the advantage of including the keyword |

A: | It allows us to write short names instead of long, fully-qualified names when we refer to classes in a namespace. This makes it easier to type the names and improves the readability of the source code. |

3: | Which namespace contains classes related to mathematical calculations and console input/output. |

A: | The |

4: | How should comments be applied in the source code? |

A: | Like salt in your food, excessive amounts of comments are as damaging as too few comments. |

5: | Describe a variable of type |

A: | A variable of type int occupies 32 bits of memory and can represent whole numbers between 2147483648 and 2147483647. |

6: | Why are |

A: | The identifiers |

7: | What are the fundamental parts of a method? |

A: | A method header and its method body that is enclosed by curly braces. |

8: | Why is |

A: | Classes generally represent items (tangible or conceptual) so nouns constitute better names for classes than verbs. Verbs, such as |

9: | How do you specify that a method does not return a value? |

A: | By writing the keyword |

10: | How do you specify that a method returns a value of type |

A: | By writing the keyword |

11: | What are arguments (in method calls)? |

A: | The value of a method argument is passed along to the called method. |

12: | What are formal parameters? |

A: | A formal parameter is part of the method header and has a certain value as the execution of the method commences. |

13: | How do arguments and formal parameters relate? |

A: | Each argument of a method call is assigned to its corresponding formal parameter during a method call. |

14: | Does the |

A: | It has the potential (through operator overloading) to perform many different operations, depending on the types involved. We have seen examples of arithmetic addition and |

15: | How can you break down the inner complexities of a class? |

A: | By separating a few complex actions into several simpler actions (methods). |

16: | What is a cohesive method? |

A: | A method that accomplishes one clear task. |

1: | Change the multi-line comments in lines 3 6 to two single line comments. |

2: | Apart from addition and multiplication, allow the user to perform a subtraction. Among other changes, you need to add a |

A: | The following program contains answers to Exercise 1 and 2. The parts related to Exercise 1 and Exercise 2 are marked Ex.1 and Ex.2 respectively. using System; //Ex. 1 //This class finds the sum, product, difference, //min and max of two numbers public class SimpleCalculator { public static void Main() { int x; int y; Console.Write("Enter first number: "); x = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter second number: "); y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The sum is: " + Sum(x, y)); Console.WriteLine("The product is: " + Product(x, y)); Console.WriteLine("The maximum number is: " + Math.Max(x, y)); Console.WriteLine("The minimum number is: " + Math.Min(x, y)); Console.WriteLine("The difference is: " + Subtract(x, y)); //Ex. 2 } // Sum calculates the sum of two int's public static int Sum(int a, int b) { int sumTotal; sumTotal = a + b; return sumTotal; } // Product calculates the product of two int's public static int Product(int a, int b) { int productTotal; productTotal = a * b; return productTotal; } // Ex.2 // Subtract calculates the difference between two int's public static int Subtract(int a, int b) { int difference; difference = a - b; return difference; } } |

3: | Instead of calculating the sum and the product of two numbers, make the program perform the calculations on three numbers. (You can ignore the |

4: | Create two methods called |

A: | The following program constitutes answers to Exercises 3 and 4. It allows the calculations to be performed on three values and implements the using System; //This class finds the sum, product, difference, //min and max of three numbers public class SimpleCalculator { public static void Main() { int x; int y; int z; // Ex.3 Console.Write("Enter first number: "); x = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter second number: "); y = Convert.ToInt32(Console.ReadLine()); // Ex. 3 Console.Write("Enter third number: "); z = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The sum is: " + Sum(x, y, z)); Console.WriteLine("The product is: " + Product(x, y, z)); // Ex. 4 Console.WriteLine("The maximum number is: " + MyMax(x, y, z)); Console.WriteLine("The minimum number is: " + MyMin(x, y, z)); // Ex.3 Console.WriteLine("The difference is: " + Subtract(x, y, z)); } // Ex. 3 // Sum calculates the sum of two int's public static int Sum(int a, int b, int c) { int sumTotal; sumTotal = a + b + c; return sumTotal; } // Ex. 3 // Product calculates the product of two int's public static int Product(int a, int b, int c) { int productTotal; productTotal = a * b * c; return productTotal; } // Ex. 3 // Subtract calculates the difference between two int's public static int Subtract(int a, int b, int c) { int difference; difference = a - b - c; return difference; } //Ex. 4 // Find max value of three parameters public static int MyMax(int a, int b, int c) { int max; max = Math.Max(a, Math.Max(b, c)); return max; } // Ex. 4 // Find min value of three parameters public static int MyMin(int a, int b, int c) { int min; min = Math.Min(a, Math.Min(b, c)); return min; } } |

C Primer Plus (5th Edition)

ISBN: 0672326965

EAN: 2147483647

EAN: 2147483647

Year: 2000

Pages: 286

Pages: 286

Authors: Stephen Prata

Similar book on Amazon

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net