Advanced Application Programming Assignment
Advanced Application Programming Assignment
class EvenOdd
{
static void Main()
{
Console.Write("Enter the number of integers: ");
int n = int.Parse(Console.ReadLine());
int evenCount = 0;
int oddCount = 0;
int evenSum = 0;
int oddSum = 0;
if (result == 1)
{
Console.WriteLine($"{numbers[i]} is an even number");
evenCount++;
evenSum += numbers[i];
}
else
{
Console.WriteLine($"{numbers[i]} is an odd number");
oddCount++;
oddSum += numbers[i];
}
}
Advanced Application Programming
Lecturer John Maina
Console.WriteLine($"There are {oddCount} odd numbers and their sum is
{oddSum}");
Console.WriteLine($"There are {evenCount} even numbers and their sum is
{evenSum}");
}
4) Making use of object orientation write a program that stores and evaluates the total
cost for items bought from a supermarket. The cashier should enter the following: -
Product code, Price and Quantity. The total price should be evaluated as follows: -
Total cost = Price * Quantity
If the total cost per item is more than 20,000 there is a discount of 14% on that item
and a discount of 10% on an item whose total cost is between 10,000 and 20,000. No
discount is given on items whose total cost is less than 10,000
NB: The cashier should decide how many Items he/she wants to work with. If he/she
chooses 3, for example, the output should take the format shown below.
Advanced Application Programming
Lecturer John Maina
Item Code Price Quantity Total Cost Discount Net
109 6000 4 24000 3360 20640
201 900 8 7200 0 7200
127 600 20 12000 1200 10800
The total amount payable is 38640
NB: Your class should have constructors (including default constructor) and a
destructor. It should also have properties to set and return price, quantity and total
cost. Set item code to read only. (15 marks)
5) Rewrite the program above making use of arrays only i.e. don’t use object
orientation your program. (10 marks)
6) Write a program that accepts a set of numbers (The user decides how many) and
stores them in array. The program should the sort all the numbers in the array in
ascending order. It should output the numbers in the array before sorting and then
again after sorting. (10 marks)
7) Write a program that accepts two numbers and swaps them. Both input and output
should be done in the main method and the swapping (actual swapping) should be
done in a method called swapNumbers. Output the two numbers in the main method
before and after swapping. (7 marks)
8) Write a (unique) C# program using the concept of object orientation to illustrate the
following concept in Object Oriented programming. Indicate with comments where
each of these concepts/techniques is used in your program. (15 marks)
a) Inheritance.
b) Overloading.
c) Overriding.
d) Encapsulation.
e) Constructors (Including default constructors)
f) Destructor.
g) Properties.
h) Error handling – try catch
class pattern
{
static void Main()
{
int n = 8;
Console.WriteLine();
}
}
}