VP Lab Journel 3 Noman

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Visual Programming Lab

SEL 322

Lab Journal # <3>

Student Name: Muhammad Noman


Enrolment No.: 01-235142-048
Class and Section: BS(IT)-5A

Department of Computer Science


BAHRIA UNIVERSITY, ISLAMABAD
Lab #: lab 3

Objectives:

Get to know about classes and some OOP concepts repeated.

Tools Used:

Microsoft Visual Studio

Submission Date: 4-10-2017

Evaluation: Signatures of Lab Engineer:


Task # 1.1:

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);
}

public string Car_name


{
get
{
return car_name;

}
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;
} }

public void display()


{
Console.WriteLine("car name:"+car_name);
Console.WriteLine("car model:"+car_model);
Console.WriteLine("car make:"+car_make);
Console.WriteLine("car type:"+car_type);
Console.WriteLine("car regno:"+regno);
e.display();

}
}

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.WriteLine("enter car name");


string n=Console.ReadLine();
Console.WriteLine("enter car model");
string m = Console.ReadLine();
Console.WriteLine("enter car type");
string t = Console.ReadLine();
Console.WriteLine("enter car horse");
string h = Console.ReadLine();
Console.WriteLine("enter car power");
string p = Console.ReadLine();
Console.WriteLine("enter car regno");
string r = Console.ReadLine();
Console.WriteLine("enter car make");
string make = Console.ReadLine();
Console.WriteLine("enter car engine no");
string eno = Console.ReadLine();
Console.WriteLine("enter car chase no");
string cno = Console.ReadLine();
Console.WriteLine("enter car weight");
string w = Console.ReadLine();
car c = new car(n,m,make,r,t,eno,cno,h,p,w);
c.display();

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 Point(int x, int y)


{
this.x = x;
this.y = y;
}

public int X { get; set; }


public int Y { get; set; }

public void display()


{
Console.WriteLine("( " + X + " , " + Y + ") \n");
}
}
class Triangle
{
private Point p1;
private Point p2;
private Point p3;

public Triangle()
{

public Triangle(Point p1, Point p2, Point p3)


{
this.P1 = p1;
this.P2 = p2;
this.P3 = p3;
}

internal Point P1 { get; set; }


internal Point P2 { get; set; }
internal Point P3 { get; set; }
public void display()
{
Console.WriteLine(" **************Triangle Point ************************ \n");
Console.Write(" P1 is ");
P1.display();
Console.Write(" P2 is ");
P2.display();
Console.Write(" P3 is ");
P3.display();
}
}

static void Main(string[] args)


{
Point s1 = new Point();
s1.X = 4;
s1.Y = 5;
Point s2 = new Point();
s2.X = 7;
s2.Y = 9;
Point s3 = new Point();
s3.X = 8;
s3.Y = 2;
Triangle t1 = new Triangle(s1, s2, s3);
t1.display();
Console.ReadLine();

}
}
}
Result/Output:

Analysis/Conclusion:

How to make constructor and there syntax according to the c#.

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());
}
}

static void Main(string[] args)


{

Rectangle r1 = new Rectangle();


Console.Write(" Enter Length of Rectangle : ");
r1.Len = int.Parse(Console.ReadLine());
Console.Write(" Enter Width of Rectangle : ");
r1.Wid = int.Parse(Console.ReadLine());
Square s1 = new Square();
Display d1 = new Display();
Console.Write(" Enter Length of Square : ");
s1.Length =int.Parse (Console.ReadLine());
Console.Write(" ******Square********** ");
d1.displaysq(s1);
Console.Write(" ******Rectangle********** ");
d1.displayrect(r1);
Console.ReadLine();

} }}
Result/Output:

Analysis/Conclusion:

used different classes and get set and rectangle and square area calculate

You might also like