Tutorial 3
Tutorial 3
1 : Draw a real picture for class and object. Differentiate class and object in terms of
diagram only.
Perform following tasks.
Task 1: Create a class
Task 2: Add few data members as private
Task 3: Add few methods as public to work on defined data members
Task 4: Create a Demo class with main method.
Task 5: Create at least two objects of a class defined in Task 1 into main method and call
all methods using that object.
Task 6: Write comment for each important portion of code like data members’
declaration, methods, some important logic etc.
Task 7: Summarize above solution in your own few words to visualize the solution to the
end user.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class Q1
{
class p1
{
private int num1;
private int num2;
Output:
2. Define a class Clock with three private integer data members hour,
min and sec. Define a no argument constructor to initialize time value to
12:00:00. Define a three argument constructor to initialize the time.
Define a methods to
1. Increment time to next second.
2. Display the time value.
3. Return the hour (int getHour())
4. Return the minute (int getMinute())
5. Return the seconds (int getSeconds())
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class p2
{
class Clock
{
private int hour;
private int min;
private int sec;
public Clock()
{
hour = 12;
min = 0;
sec = 0;
}
clock1.IncrementTime();
clock2.IncrementTime();
clock1.DisplayTime();
clock2.DisplayTime();
Output:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class p3
{
class Student
{
private string name;
private int age;
private string course;
public Student()
{
student1.Name = "Meet";
student1.Age = 20;
student1.Course = "Mathematics";
Console.WriteLine("Student 1 Information:");
student1.DisplayInfo();
Console.WriteLine("\nStudent 2 Information:");
student2.DisplayInfo();
Console.ReadLine();
}
}
}
Output:
4. Use above program classes and create objects for 5 students and
demonstrate the use student class.
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class p4
{
class Student
{
private string name;
private int age;
private string course;
public Student()
{
student1.Name = "raj";
student1.Age = 20;
student1.Course = "Mathematics";
namespace t3
{
internal class p5
{
class Product
{
int pcode;
String pname, mname;
pcode = pcd;
pname = pnm;
mname = mnm;
}
if (n < 3)
{
Console.WriteLine("Syntax Error\n");
Console.WriteLine("Must Have THREE Arguments\n");
Console.WriteLine("Please, Write as [csc TestProduct ProductCode
ProductName Manufacturer] \n");
}
else
{
int pcd = Convert.ToInt32(args[0]);
String pnm = args[1];
String mnm = args[2];
p.Display();
Console.ReadLine();
}
}
}
}
6. Complete the following code that will generate the given output:
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class p6
{
class Line
{
private double length;
public Line()
{
length = 10;
Console.WriteLine("Object is being created, length = " + length);
}
line.setLength(6);
Console.WriteLine("Length of line : {0}", line.getLength());
Console.ReadLine();
}
}
}
7. Define EnrolmentNo and Name properties for the Student class and
demonstrate use of these properties along with required data members,
methods and constructors.
Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace t3
{
internal class p7
{
class Student
{
public Student()
{
enrolmentNo = 34;
name = "Vadoliya Vivek";
age = 18;
course = "Informmation technology";
}
student1.EnrolmentNo = 1001;
student1.Name = "Mayank";
Console.WriteLine("Student 1 Information:");
student1.DisplayInfo();
Console.WriteLine("\nStudent 2 Information:");
student2.DisplayInfo();
Console.ReadLine();
}
}
}