|
Spring-3 2020
CNS 255 Object Oriented Programming Introduction
FTAP-5 |
|
|
|
|
|
Student Name |
Student ID |
|
|
|
|
Feedback/Comments: |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
Grade: /100
|
FTAP-5
PART 1:
[55 points]
1. You need to do research on the following concepts programming topics:
· Classes and objects
· Abstraction
· Encapsulation
· Polymorphism
2. You need to include in your project report:
· at least 2 resources for academic citation
· demonstrate logical and subtle sequencing of ideas through well-developed paragraphs; transitions are used to enhance organization
· provide a reference list
· minimum 500 words
· use APA style for the assignment: http://owl.english.purdue.edu/owl/resource/560/01/
Insert your report for here:
|
|
PART 2: Analyze C# code and explain it in details:
[15 points]
Analyze the following C# code:
|
using System; namespace ConsoleApplication1 { class Velocity_class { private int distance; private int time;
public int Distance { set { distance = value; } get { return distance; } } public int Time { set { time = value; } get { return time; } }
public double Velocity_calc() { return distance / time; } }
public class Program { public static void Main(string[] args) { try { Velocity_class v1 = new Velocity_class(); v1.Time = 0; v1.Distance = 200; Console.WriteLine(v1.Velocity_calc()); } catch (Exception e) { Console.WriteLine("OOPS"); } } } } |
Now explain the code in details:
(Keywords to use: data fields, methods, access modifiers, class, exception handling, main method, declaration and instantiation of the object, console)
|
Answer:
|
PART 3: Analyze C# program and explain it in details:
[15 points]
Analyze the following GUI:
Analyze the corresponding C# code:
|
using System; using System.Windows.Forms;
namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox3.Enabled = false; }
private void button2_Click(object sender, EventArgs e) { int subs = int.Parse(textBox1.Text) - int.Parse(textBox2.Text); textBox3.Text = subs.ToString(); }
private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = String.Empty; textBox3.Clear(); }
private void button3_Click(object sender, EventArgs e) { this.Close(); } } } |
Now explain the program in details:
(Keywords to use: classes, methods, access modifiers, event handlers, arguments, controls, labels, textboxes, buttons)
|
Answer:
|
PART 4: Write C# code in https://dotnetfiddle.net/UMwTVu according to the tasks given below:
[15 points – each 5 points]
1. Write a C# code to force program to throw an DevideByZeroException error:
|
Answer:
|
2. Write a C# code to force program to throw an FormatException error:
|
Answer:
|
3. Write a C# code to force program to throw an IndexOutOfRangeException error:
|
Answer:
|
Bonus:
[10 points]
Create an application in in https://dotnetfiddle.net/UMwTVu that instantiates objects of two classes named Control and Label, and that demonstrates all their properties.
a) The Control class includes auto-implemented properties for the Text and Size (use corresponding data types). Also, include a display() method that prints the Control’s data field values.
b) Create a child class named Label that includes an auto-implemented property named Color and display() method that prints all Label’s data field values.
c) Declare and instantiate one Control and one Label objects. Display the Control and Label objects’ properties with any random values.
|
Answer:
|