Programming with C#

QUESTION 1      

The following UML diagram describes an abstract class Customer. This class is to be used as part of a Company's inventory system. The inventory system will contain many different types of customers.  A separate subclass of Customer will be written for each type of customer. Once a customer is created, their identification will never change.

Using the given information and the UML diagram below you are to write the C# code for the Customer class only.

 

Customer {abstract}

 

 

-identification : string

-name : string

-address : string

 

 

+Customer(id : string, name : string, address : string)

+GetIdentification(): string

+GetName(): string

+SetName(name : string)

+GetBillingType():BillingType {abstract}

 

QUESTION 2                                                                                                

Write a method using the method header below.

   public void Reverse( double [] values, int start, int finish){ 

This method will reverse the elements in an array between a lower index position and an upper index position.

So given the following array declaration

                double [] data = {8.5, 12.0, 23.2, 18.0, 15.5, 5.0, 10.5};

following a call to the method Reverse(data, 2, 5); the contents of data would be

                {8.5, 12.0, 5.0, 15.5, 18.0, 23.2, 10.5}

Assume that you have already written a method called swap that swaps two elements in an array; the elements identified by the two index values passed as parameters:

Swap(array, oneIndex, otherIndex)

QUESTION 3                                                                                    

(a)          Write a method, IsVowel, which returns the value true if the supplied lowercase character is a vowel, otherwise return false. Use the following method heading.

                ///

      /// pre: ch is a lowercase alhpabethic character

                ///                           'a' <= ch <= 'z'

                ///

                /// post: returns true is ch is a vowel, otherwise false

      ///

      ///

      /// true if ch is in {'a', 'e', 'i', 'o', 'u'}

public bool IsVowel(char ch)

Note: only the lowercase letters, a, e, i, o, u are vowels. There is no need to include the XML comment in your answer.

(b)          In the formulation of a test plan for the method isVowel, what would be two (2) obvious test categories to include in the test plan?

QUESTION 4                                                                                                     

A common operation on a list is to find the "largest" value in a list.  Write an algorithm which will find the "second largest" value in a list. You can assume that the list will contain at least 2 values and that no value is duplicated.  Do not write C# code as your answer, but the algorithm should be at a level of detail that would lend itself to implementation in C# or any other programming language.

The algorithm should not make use of any supplied functionality, e.g. C# Array class methods such as Sort etc. It is also assumed that this algorithm would be implemented as a method which returns the location of the second largest value of the list and that the order of the values within the list is unchanged. This means that one cannot simply sort the array in ascending order and return (list.Length-2) as it is assume that the list will be passed by reference to this method.

 

 

 

 

 

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.