VP Lab Journel 3 Noman
VP Lab Journel 3 Noman
VP Lab Journel 3 Noman
SEL 322
Objectives:
Tools Used:
Implement Has-a relationship: a) Create a class named engine, which contains engine number, chassis number, horse
power, weight and other necessary engine properties. b) Create another class named Car, which contains Engine
object, car name, model, make, reg. number, car type and other necessary car properties. c) In main method,
instantiate object and read values from user and display them on screen d) Both classes must have default and
parameterized constructor. Car class will have an extra constructor, which takes both class member. Both classes
must have private members and you must use properties to set and get the values of class members.
Procedure/Program:
Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vp
{
class engine
{
string engine_number;
string chassis_number;
string horse;
string power;
string weight;
engine()
{
engine_number = " ";
chassis_number = " ";
horse = " ";
power = " ";
weight = " ";
}
public engine(string e,string c,string h,string p,string w)
{
engine_number = e;
chassis_number = c;
horse = h;
power = p;
weight = w;
}
public string Engine_number
{
get
{
return engine_number;
}
set
{
this.engine_number = value;
}
}
public string Chassis_number
{
get
{
return chassis_number;
}
set
{
this.chassis_number = value;
}
}
public string Horse
{
get
{
return horse;
}
set
{
this.horse = value;
}
}
public string Power
{
get
{
return power;
}
set
{
this.power = value;
}
}
public string Weight
{
get
{
return weight;
}
set
{
this.weight = value;
}
}
public string Engine_number
{
get
{
return engine_number;
}
set
{
this.engine_number = value;
}
}
public void display()
{
Console.WriteLine("engine no: "+engine_number);
Console.WriteLine("Chase no: " + chassis_number);
Console.WriteLine("horse: " + horse);
Console.WriteLine("power: " + power);
Console.WriteLine("weight: " +weight);
}
}
}
Car
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vp
{
public class car
{
engine e;
string car_name;
string car_model;
string car_make;
string regno;
string car_type;
public car()
{
car_model = "";
car_make = "";
car_name = "";
car_type = "";
regno = "";
}
public car(string n,string m,string make,string r,string t)
{
car_model = m;
car_make = make;
car_name = n;
car_type = t;
regno = r;
}
public car(string n, string m, string make, string r, string t,string d, string c, string h,
string p, string w)
{
car_model = m;
car_make = make;
car_name = n;
car_type = t;
regno = r;
e=new engine(d,c,h,p,w);
}
}
set
{
this.car_name = value;
} }
public string Car_model
{
get
{
return car_model;
}
set
{
this.car_model = value;
} }
public string Car_make
{
get
{
return car_make;
}
set
{
this.car_make = value;
} }
public string Car_type
{
get
{
return car_type;
}
set
{
this.car_type = value;
} }
public string Regno
{
get
{
return regno;
}
set
{
this.regno = value;
} }
}
}
Main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vp
{
class Program
{
static void Main(string[] args)
{
Console.ReadLine();
}
}
}
Result/Output:
Analysis/Conclusion:
Get input from user by using set get functions and display it.
Task # 2.1:
Implement following:
Procedure/Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
class Point
{
private int x;
private int y;
public Point()
{
}
public Triangle()
{
}
}
}
Result/Output:
Analysis/Conclusion:
Task # 2.1:
Write a program having three classes: a) Class Square() b) Class Rectangle() c) Class Display() i. First get the length of square
from user, using properties only and then calculate its area and perimeter using CalculateArea() function in square class. ii.
Similarly get the length and width of rectangle from user, using properties only and then calculate its area and perimeter
using CalculateArea() & CalculatePerimeter() function in rectangle class. iii. Display Area and Perimeter of square and
rectangle in Display Class.
Procedure/Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
class Square
{
private int length;
public Square()
{
}
public Square(int len)
{
this.length = len;
}
public int Length { get { return length; } set { length = value; } }
public int CalculateArea()
{
int Area = length * length;
return Area;
}
public int CalP()
{
int Per = 4 * length;
return Per;
}
}
class Rectangle
{
private int length;
private int width;
public Rectangle()
{
}
public Rectangle(int len, int wid)
{
this.length = len;
this.width = wid;
}
public int Len { get { return length; } set { length = value; } }
public int Wid { get {return width;} set { width = value; }}
public int CalculateArea()
{
int Area = Len * Wid ;
return Area;
}
public int CalP()
{
int P = 2*( Len + Wid );
return P;
}
}
class Display
{
public void displaysq(Square s1)
{
Console.WriteLine(" Area of Square =" + s1.CalculateArea());
Console.WriteLine(" Area of Square = " + s1.CalP());
}
public void displayrect(Rectangle r1)
{
Console.WriteLine(" Area of Rectangle is = " + r1.CalculateArea());
Console.WriteLine(" Area of Rectangle is :=" + r1.CalP());
}
}
} }}
Result/Output:
Analysis/Conclusion:
used different classes and get set and rectangle and square area calculate