For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

WhatsApp Widget

C# programming language

Select Year: Select a Trimester: Subject:
Length of Test: Weight:
Total Marks:

  1. A  Essay questions.
  2. B  Supplementing the missing piece of code.
  3. C  Writing own code for a given problem.


5 3 Marks each 5 3 Marks each

2 5 Marks each

15 Marks 15 Marks

10 Marks / 40


Objected Oriented Programming 2.5 hours

Section Question Type Number of Number of Marks Questions per question TOTAL MARKS

Section A 15 Marks

Answer all the questions in this section. Explain your answer and give appropriate example. Each question is worth 3 marks.


Indicate whether each of the following C# programming language identifiers is legal or

illegal. If it is legal, indicate whether it is a conventional identifier for a class.


Red = illegal
Green = legal and conventional for a class Blue = legal, but unconventional for a class

a. electricBill b. ElectricBill c. Electric bill d. Static

e. void f. #ssn

g. Ay56we
h. Tickets
i. 212AreaCode
j. heightInCentimeters k. Zip23891
l. Void

  1. How is a named constant different from a variable? How would you create a named constant? Show an example.


By definition, a variable’s value can vary, or change. Sometimes you want to create a named constant (often simply called a constant), an identifier whose contents cannot change. You create a named constant similar to the way you create a named variable, but by using the keyword const. Although there is no requirement to do so, programmers usually name constants using all uppercase letters, inserting underscores for readability. This convention makes constant names stand out so that the reader is less likely to confuse them with changeable variable names. For example, the following declares a constant named TAX_RATE that is assigned a value of 0.06:

const double TAX_RATE = 0.06;

  1. Creating an object requires two steps that are shown in the example below:

Employee myAssistant; myAssistant = new Employee(); What do these statements accomplish?



Defining an Employee object named myAssistant requires two steps-you must declare a reference to the object, and then you must actually set aside enough memory to hold the object. When you declare the myAssistant instance of the Employee class (as in the first statement), you are notifying the compiler that you will use the identifier myAssistant. However, you are not yet setting aside computer memory in which the object named myAssistant can be stored. To allocate the needed memory and instantiate the object, you must use the new operator (as in the second statement).

  1. For a method that accepts a parameter, what are the components of the parameter definition that must be included in the method declaration? Show an example of a method declaration with a parameter.


When you write the declaration for a method that accepts a parameter, you need to include the following items within the method declaration parentheses:
* The type of the parameter
* A local identifier (name) for the parameter

For example, consider a public method named DisplaySalesTax(), which displays the result of multiplying a value that represents a selling price by 7%. The method header for a usable DisplaySalesTax() method could be the following:

public static void DisplaySalesTax(double saleAmount)

  1. Show an example of a class definition that creates a subclass of an existing Employee class, and adds a private double field called commissionRate. What is the total set of fields that an instance of the new class contains?


The class definition provided should be similar to the following:

class CommissionEmployee : Employee

private double commissionRate;

Each CommissionEmployee object automatically contains the data fields of the base class (Employee in this case) plus any new fields that are added (commissionRate in this case).


Section B 15 Marks

1. Australian car rental centre Kayak charges $30 per day plus 15 cents per mile. Write a C# program that prompts the user for and accepts a number of days and miles driven and call method named CarRental to calculate and then display the total rental fee. (3 marks)


2. Complete the segment of C# code that allows a doctor’s staff to enter data about patients and saves the data to a file called Patients.txt. The output should be in the following format: p#, PATIENT_NAME, BALANCE. Create a Patient class that contains fields for ID number, name, and current balance owed to the doctor’s office. (3 marks)


3. Create a program named FindSquareRoot that finds the square root of a user’s input value. The Math class contains a static method named Sqrt() that accepts a double and returns the parameter’s square root. If the user’s entry cannot be converted to a double, display an appropriate message, and set the square root value to 0. Otherwise, test the input number’s value. If it is negative, throw a new Application Exception to which you pass the message “Number can’t be negative.” and again set sqrt to 0. If the input value is a double and not negative, pass it to the Math.Sqrt() method, and display the returned value. (3 marks)


4. Complete the following C# code to find the sum of all elements of an array. (3 marks)


5. Write an example method that overrides the + operator to create a new book whose title is a concatenation of the titles of two books. For example, if the first book’s title is “The Adventures of Tom Sawyer” and the second book’s title is “The Adventures of Huckleberry Finn”, the concatenated title will be “The Adventures of Tom Sawyer and The Adventures of Huckleberry Finn”. Assume the book class is defined as: (3 marks)


Section C 10 Marks

Answer all the questions in this section. Each question is worth (5) marks. Read what is required from each question carefully and answer all parts of the question.

  1. Create an application named PhotoStudio that instantiates objects of three classes named Photo, MattedPhoto, and FramedPhoto and that demonstrates all their methods.

Create a class named Photo that includes fields for width and height in inches and properties for each field. Include a protected field for price and protected method that set price to $3.99 for an 8-inch by 10-inch photo, $5.99 for a 10-inch by 12-inch photo, and $9.99 for any other size. The price field requires a get accessor but no set accessor. Also include a ToString() method that returns a string constructed from the return value of the object’s GetType() method and the values of the fields. (5 marks)

  1. Extend the Photo class (from the question 1) to two more specialized classes: MattedPhoto and FramedPhoto. The MattedPhoto class includes a string field to hold a color, and the FramedPhoto class includes two string fields that hold the frame’s material (such as silver) and style (such as modern). The price for a MattedPhoto increases by $10 over its base cost, and the price for a FramedPhoto increases by $25 over its base cost. Each subclass should include a ToString() method that overrides the parent class version. (5marks)


The post C# programming language appeared first on My Assignment Online.

Hello! Need help with your assignments?

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102