0% found this document useful (0 votes)
12 views11 pages

Lab Task 12

1) The document defines classes for Book, Copy, Transportation, Boat, Car, Airplane, Person, Professor, Student to demonstrate abstraction. 2) It shows usage of abstract classes, interfaces, inheritance and polymorphism through methods that output travel modes or personal details. 3) The main method tests output for book details, selecting a vehicle travel mode, refueling, and displaying professor and student personal details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

Lab Task 12

1) The document defines classes for Book, Copy, Transportation, Boat, Car, Airplane, Person, Professor, Student to demonstrate abstraction. 2) It shows usage of abstract classes, interfaces, inheritance and polymorphism through methods that output travel modes or personal details. 3) The main method tests output for book details, selecting a vehicle travel mode, refueling, and displaying professor and student personal details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab Task 12 (Abstraction)

Name: Shaheer Bin Azeem ID: 65646

Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
class Program
{
public abstract class Book
{
public string name;
public string author;
public double price;
public int quantity;
public virtual void Detail()
{
Console.WriteLine(name);
Console.WriteLine(author);
Console.WriteLine(price);
Console.WriteLine(quantity);
}
}
public class Copy : Book
{
public override void Detail()
{
Console.WriteLine(name);
Console.WriteLine(author);
Console.WriteLine(price);
Console.WriteLine(quantity);
}
}
public interface ITravelMode
{
string GetModeOfTravel();

public abstract class Transportation : ITravelMode


{
private readonly string _modeOfTravel;

protected Transportation(string modeOfTravel)


{
_modeOfTravel = modeOfTravel;
}

public string GetModeOfTravel()


{
return _modeOfTravel;
}
}

public class Boat : Transportation


{
public Boat() : base("TRAVEL BY BOAT")
{
}
}

public class Car : Transportation


{
public Car() : base("TRAVEL BY CAR")
{
}
}
public class Refill
{
public void Fuel()
{
Console.WriteLine("Refuel completed");
}
}
public class Airplane : Transportation
{
public Airplane() : base("TRAVEL BY AIR")
{
}
}

public class Person


{
public string FirstName;
public string lastName;

public void display()


{
Console.WriteLine(FirstName);
Console.WriteLine(lastName);
}
}
public class Professopr : Person
{
public int salary;
public void display()
{
Console.WriteLine(FirstName);
Console.WriteLine(lastName);
Console.WriteLine(salary);
}
}
public class Student : Person
{
public int Year;
public void display()
{
Console.WriteLine(FirstName);
Console.WriteLine(lastName);
Console.WriteLine(Year);
}
}
static void Main(string[] args)
{
Console.WriteLine("----------------- TASK 1 -------------");
Console.WriteLine();
Copy C1 = new Copy()
{
name="Untold Story",
author="~AB~",
price=1000,
quantity=65

};
C1.Detail();

Console.WriteLine();
Console.WriteLine("------------------ TASK 2 -------------------");
Console.WriteLine("which vehical you want to use");
Console.WriteLine("1) Car");
Console.WriteLine("2) Boat");
Console.WriteLine("3) Ship");
Console.WriteLine("4) To end");

bool y = true;
while (y==true)
{

int a = int.Parse(Console.ReadLine());
switch (a)
{
case 1:
Car car = new Car();
Console.WriteLine(car.GetModeOfTravel());
break;

case 2:
Boat boat = new Boat();
Console.WriteLine(boat.GetModeOfTravel());
break;

case 3:
Airplane airplane = new Airplane();
Console.WriteLine(airplane.GetModeOfTravel());
break;
case 4:
Console.WriteLine("The program has ended");
y = false;
break;
default:
Console.WriteLine("Select correct option");
break;

}
}
Console.WriteLine();
Console.WriteLine("--------------------- TASK 3 ----------------");
Console.WriteLine();
Console.WriteLine("which vehical you want to use");
Console.WriteLine("1) Car");
Console.WriteLine("2) Boat");
Console.WriteLine("3) Ship");
Console.WriteLine("4) to end");
Console.WriteLine("5) To refill");

bool x = true;
while (x == true)
{

int a = int.Parse(Console.ReadLine());
switch (a)
{
case 1:
Car car = new Car();
Console.WriteLine(car.GetModeOfTravel());
Console.WriteLine("You need to refuel");
break;

case 2:
Boat boat = new Boat();
Console.WriteLine(boat.GetModeOfTravel());
Console.WriteLine("You need to refuel");

break;

case 3:
Airplane airplane = new Airplane();
Console.WriteLine(airplane.GetModeOfTravel());
Console.WriteLine("You need to refuel");

break;
case 4:
Console.WriteLine("The program has ended");
x = false;
break;
case 5:
Refill r1 = new Refill();
r1.Fuel();
break;
default:
Console.WriteLine("Select correct option");
break;
}
}
Console.WriteLine("--------------------- Task 4 ----------------");

Professopr p1 = new Professor();


Console.WriteLine("Professor details");

p1.salary = 10000;
p1.lastName = "Bin Azeem";
p1.FirstName="Shaheer";
p1.display();
Console.WriteLine();
Console.WriteLine("Student details");
Student s1 = new Student();
s1.FirstName = " Shayan";
s1.lastName = "Ali";
s1.Year = 2004;
s1.display();
Console.ReadKey();
}
}
}

You might also like