Question # 1: Assignment # 1 (OOP C#)
Question # 1: Assignment # 1 (OOP C#)
Question # 1: Assignment # 1 (OOP C#)
Roll No : 19-NTU-CS-1063
Name : Muhammad Danish
BSCS-2
Question # 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class Park
{
public string Name_of_Park = "Something is wrong";
public string location_of_Park = "Something is wrong";
public string Type_of_Park = "Something is wrong";
public string Facility = "Something is wrong";
public int fee = 0;
public int No_of_Employees = 0;
public int Visitor_in_12_month = 0;
public int Annual_budget = 0;
//Argument Constructor
public Park(string Name, string location, string type, string
facility,
int fee, int NoEmp, int visitor, int Annual_budget)
{
Name_of_Park = Name;
location_of_Park = location;
Type_of_Park = type;
Facility = facility;
this.fee = fee;
No_of_Employees = NoEmp;
Visitor_in_12_month = visitor;
this.Annual_budget = Annual_budget;
}
//Part a
public string NameLocationType()
{
return Name_of_Park + " " + location_of_Park
+ " " + Type_of_Park;
}
//Part b
public string NameLocationFacility()
{
return Name_of_Park + " " +
location_of_Park + " " + Facility;
}
//Part c
public double CostPerVisitor()
{
return Annual_budget / Visitor_in_12_month;
}
//Part d
public double revenue()
{
return Visitor_in_12_month * fee;
}
}
class Program
{
static void Main(string[] args)
{
Park park1 = new Park("Company Park", "Faisalabad",
"Local", "No", 190, 120, 90, 90000);
//Part a
Console.WriteLine("Name of the Park-------- Location of
the park--------- Type of park:");
Console.WriteLine(park1.NameLocationType());
Console.WriteLine();
//Part b
Console.WriteLine("Name of the Park---- Location of the
park ----- Facilities avalible:");
Console.WriteLine(park1.NameLocationFacility());
Console.WriteLine();
//Part c
Console.WriteLine("Cost per Visitor : ");
Console.WriteLine(park1.CostPerVisitor());
Console.WriteLine();
Console.WriteLine("Revenue: ");
Console.WriteLine(park1.revenue());
Console.WriteLine();
}
}
}
ScreenShot
Question # 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class Employee
{
public string Name;
public double MonthlySales;
}
class Program
{
static void Main(string[] args)
{
string name;
double sale;
Console.WriteLine("Enter Name of Employee: ");
name = Console.ReadLine();
Console.WriteLine("Enter Monthly sale of
Employee: ");
sale = Int32.Parse(Console.ReadLine());
Employee FirstEmployee = new Employee(name,
sale, 3294, "1/11/2020", "Manager", "Computer Science");
Console.WriteLine("Comission of Employee is: " +
FirstEmployee.commissionincome());
Console.WriteLine(" After cutting Tax is: " +
FirstEmployee.withTax());
Console.WriteLine(" full And Final Income of
Employee is: " + FirstEmployee.retirement());
}
}
}
ScreenShot
Question # 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class MoterWay
{
public string Name;
public string Type;
public string Direction;
public string Surface;
public int Nolanes;
public bool toll;
public string Party;
public MoterWay(string name, string type, string direction, string surface, int
lanes, bool toll, string party)
{
this.Name = name;
this.Type = type;
this.Direction = direction;
this.Surface = surface;
Nolanes = lanes;
this.toll = toll;
this.Party = party;
}
class Program
{
static void Main(string[] args)
{
MoterWay M1 = new MoterWay("M2-faislabad", "Road", "west", "Concrete", 3,
true, "Under_gov"+"\n\n");
M1.Display();
Console.WriteLine("--------------------------- ---------- Values return
---------------------- ");
Console.WriteLine(M1.Return());
}
}
}
ScreenShot
Question # 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class Car
{
public int Year;
public string Make; //Company/Maker name.
public int speed;
ScreenShot
Question # 5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class Population
{
private int population;
private double NoOfbirths;
private double NoOfdeaths;
//Default constructor;
public Population()
{
population = 50000;
NoOfbirths = 500;
NoOfdeaths = 500;
}
}
public double NumberOfDeaths
{
get { return NoOfdeaths; }
set
{
NoOfdeaths = value;
}
}
public double NumberOfBirths
{
get { return NoOfbirths; }
set
{
NoOfbirths = value;
}
}
class Program
{
static void Main(string[] args)
{
//values by constructor
Population obj1 = new Population(10000, 800, 400);
Console.WriteLine("Birth rate of obj-1 is: " +
obj1.getbirthRate());
Console.WriteLine("Death rate of obj-1 is: " +
obj1.getdeathRate());
Console.WriteLine(" ------------------- ");
// values by setter
Population obj2 = new Population();
obj2.NumberOfBirths = 1000;
obj2.NumberOfDeaths = 5000;
obj2.Popul = 25000;
Console.WriteLine("Birth rate of obj-2 is: " +
obj2.getbirthRate());
Console.WriteLine("Death rate of obj-2 is: " +
obj2.getdeathRate());
}
}
}
ScreenShot
Question # 6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Opp_assignment1063
{
public class Inventory
{
private int itemNumber;
private int quantity;
private int cost;
private int totalCost;
//Default Constructor
public Inventory()
{
itemNumber = 0;
quantity = 0;
cost = 0;
totalCost = 0;
}
//Argument constructor
public Inventory(int ItemNo, int Qnty, int cost)
{
SetItemNumber(ItemNo);
SetQuantity(Qnty);
SetCost(cost);
SetTotalCost();
}
itemNumber = value;
}
public int getItemNumber()
{
return itemNumber;
quantity = value;
}
public int getQuantity()
{
return quantity;
cost = value;
}
public int getCost()
{
return cost;
}
public int getTotalCost()
{
return totalCost;
}
class Program
{
static void Main(string[] args)
{
Inventory item_1 = new Inventory(3333, 400, 7);
item_1.Dispaly();
Console.WriteLine();
Inventory item_2 = new Inventory(5555, 600, 10);
item_2.Dispaly();
}
}
}
ScreenShot