Lab Tutorial - 3
- Due No Due Date
- Points 10
- Submitting a file upload
Sample Format for file upload.docx
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.
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
- Increment time to next second.
- Display the time value.
- Return the hour (int getHour())
- Return the minute (int getMinute())
- Return the seconds (int getSeconds())
3 : Define a Student class with appropriate data members, property, constructors, methos etc. Define another class called TestStudent within the same .cs file. Also create an object of student class and demonstrate the use of student class.
4 : Use above program classes and create objects for 5 students and demonstrate the use student class.
5 : Rearrange the given code to get the desired output.
using System;
namespace ConsoleApplication
{
class Product
{
public Product(int pcd, String pnm, String mnm)
{
mname = mnm;
}
public void Display()
{
Console.WriteLine("\nManufacturer Name:= " + mname);
}
}
int pcode;
String pname, mname;
Console.WriteLine("\nProduct Code:= " + pcode);
Console.WriteLine("\nProduct Name:= " + pname);
pcode = pcd;
pname = pnm;
public class TestProduct
{
public static void Main(string[] args)
{
int n = args.Length;
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
{
Product p=new Product(pcd,pnm,mnm);
p.Display();
Console.Read();
int pcd = Convert.ToInt32(args[0]);
String pnm = args[1];
String mnm = args[2];
}
}
}
}
Output:
Product Code:= P001
Product Name:= Mouse
Manufacturer Name:= Logitech
6 : Complete the following code that will generate the given output:
Solution:
using System;
namespace LineApplication
{
class Line
{
private double length; // Length of a line
public Line()
{
//………………………………Missing statement-1……………………………….//
//………………………………Missing statement-2……………………………….//
}
public void setLength( double len )
{
//………………………………Missing statement-3……………………………….//
}
public double getLength()
{
//………………………………Missing statement-4……………………………….//
}
}
class TestLine
{
static void Main(string[] args)
{
Line line = new Line();
// set line length
Console.WriteLine("Length of line : {0}", line.getLength());
// set line length
Console.WriteLine("Length of line : {0}", line.getLength());
Console.ReadKey();
}
}
}
Output:
Object is being created, length = 10
Length of line : 10
Length of line : 6
7 : Define EnrolmentNo and Name properties for the Student class and demonstrate use of these properties along with required data members, methods and constructors.
Find Rubric