You are on page 1of 16

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;

public int Number;


public string HireDate;
public string JobDescrip;
public string Department;

public Employee(string name, double sale, int Num,


string hiredate, string jobdescrip, string department)
{
this.Name = name;
this.MonthlySales = sale;
Number = Num;
HireDate = hiredate;
JobDescrip = jobdescrip;
Department = department;

public double commissionincome()


{
Console.WriteLine();
Console.WriteLine("Name of Employee is " +
Name);
return (MonthlySales * 7) / 100;
}

public double withTax()


{

double Tax, salary, income;


income = (MonthlySales * 7) / 100;
Tax = (income * 24) / 100;
salary = income - Tax;
return salary;
}

public double retirement()


{
double Tax, salary, retire, income;
income = (MonthlySales * 7) / 100;
Tax = (income * 24) / 100;
retire = (income * 10) / 100;
salary = income - Tax - retire;
return salary;
}

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

public void Display()


{
Console.WriteLine("Name of MoterWay : " + Name);
Console.WriteLine("Type of MoterWay : " + Type);
Console.WriteLine("Dirction of MoterWay : " + Direction);
Console.WriteLine("Surface of MoterWay : " + Surface);
Console.WriteLine("Number of lanes in MoterWay : " + Nolanes);
Console.WriteLine("MoterWay have toll or not: " + toll);
Console.WriteLine("Party of MoterWay is: " + Party);
}

public string Return()


{
return Name + "\n" + Type + "\n" + Direction + "\n" + Surface + "\n" +
Nolanes + "\n" + toll + "\n" + 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;

public Car(int year, string make)


{
this.Year = year;
this.Make = make;
speed = 0;
}

public int acceleration()


{
speed = speed + 5;
return speed;
}
public int brake()
{
speed = speed - 5;
return speed;
}
}
class Program
{
static void Main(string[] args)
{
Car car1 = new Car(2020, "Honda");

Console.WriteLine("Acceleration Method---------------: ");


for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i + "-Value: " +
car1.acceleration());

Console.WriteLine("Brake Method----------------------: ");


for (int i = 1; i <= 5; i++)
{
Console.WriteLine(i + "-Value: " + car1.brake());
}
}
}
}

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

// intialize by argument Constructor;


public Population(int population, double births, double
deaths)
{
this.population = population;
NoOfbirths = births;
NoOfdeaths = deaths;
}

public int Popul


{
get { return population; }
set
{
population = value;
}

}
public double NumberOfDeaths
{
get { return NoOfdeaths; }
set
{
NoOfdeaths = value;
}

}
public double NumberOfBirths
{
get { return NoOfbirths; }
set
{
NoOfbirths = value;
}

public double getbirthRate()


{

return NoOfbirths / population;


}
public double getdeathRate()
{
return NoOfdeaths / population;
}

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

public void SetItemNumber(int value)


{

itemNumber = value;

}
public int getItemNumber()
{
return itemNumber;

public void SetQuantity(int value)


{

quantity = value;

}
public int getQuantity()
{

return quantity;

public void SetCost(int value)


{

cost = value;

}
public int getCost()
{

return cost;

public void SetTotalCost()


{

totalCost = quantity * cost;

}
public int getTotalCost()
{

return totalCost;

public void Dispaly()


{
Console.WriteLine("Item Number : " + getItemNumber());
Console.WriteLine("Item Quantity : " + getQuantity());
Console.WriteLine("Item Cost : " + getCost());
Console.WriteLine("Item Toatl Cost : " + getTotalCost());
}

}
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

You might also like