0% found this document useful (0 votes)
51 views4 pages

Muhammad Osama CSC-18F-076

This C# program defines vehicle, bike, and car classes with properties like model, color, engine, and door. The vehicle class acts as the base class with a calculateSpeed method. Bike and car inherit from vehicle and override calculateSpeed. The main method creates vehicle, bike, and car objects, gets user input, and calls methods on the appropriate object to output vehicle details and simulate starting, running, and stopping a bike or car. Speed values are different for the bike and car calculateSpeed overrides.

Uploaded by

usman ali
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)
51 views4 pages

Muhammad Osama CSC-18F-076

This C# program defines vehicle, bike, and car classes with properties like model, color, engine, and door. The vehicle class acts as the base class with a calculateSpeed method. Bike and car inherit from vehicle and override calculateSpeed. The main method creates vehicle, bike, and car objects, gets user input, and calls methods on the appropriate object to output vehicle details and simulate starting, running, and stopping a bike or car. Speed values are different for the bike and car calculateSpeed overrides.

Uploaded by

usman ali
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/ 4

Muhammad Osama CSC-18F-076

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace task
{
public class vehicle
{
public string model;
public string color;
public string engine;
public string door;

public vehicle()
{

public vehicle(string x, string y, string z, string t)


{
model = x;
color = y;
engine = z;
door = t;

public virtual void calculateSpeed()


{
int x=0;
Console.WriteLine("Speed is = {0}",x);
}
}
public class bike : vehicle
{

public void start()


{
Console.WriteLine("Speed = 0");
}

public void stop()


{
Console.WriteLine("Speed < 0 ");
}

public void run()


{
Console.WriteLine("Bike is moving ");
}

public override void calculateSpeed()


{
Muhammad Osama CSC-18F-076

int x = 500;
Console.WriteLine("Speed is = {0}", x);
}

public class car : vehicle


{
public void start()
{
Console.WriteLine("Speed = 0");
}

public void stop()


{
Console.WriteLine("Speed < 0 ");
}

public void run()


{
Console.WriteLine("Car is moving ");
}

public override void calculateSpeed()


{
int x = 1000;
Console.WriteLine("Speed is = {0}", x);
}
}

class Program
{
static void Main(string[] args)
{
vehicle a = new vehicle("2011", "Yellow", "12121", "0");
vehicle b = new vehicle("2005", "Blue", "4231", "02");
bike c = new bike();
car d = new car();

Console.WriteLine("Enter alphabets for checking the vehicle detail &


operation \n \t m)BIKE \n \t n)CAR");
char z;
z =Convert.ToChar(Console.ReadLine());
switch(z)
{
case 'm':

Console.WriteLine(" BIKE");
Console.WriteLine("\t---------------------");
Console.WriteLine("Model= {0}", a.model);
Console.WriteLine("Color= {0}", a.color);
Console.WriteLine("Engine = {0}", a.engine);
Console.WriteLine("Door = {0}", a.door);
Console.WriteLine("start");
c.start();
Muhammad Osama CSC-18F-076

Console.WriteLine("run ");
c.run();
Console.WriteLine("stop");
c.stop();
Console.WriteLine("override");
c.calculateSpeed();
break;

case 'n':

Console.WriteLine(" CAR");
Console.WriteLine("-------------------------");
Console.WriteLine("Model= {0}", b.model);
Console.WriteLine("Color = {0}", b.color);
Console.WriteLine("Engine = {0}", b.engine);
Console.WriteLine("Door = {0}", b.door);
Console.WriteLine("start");
d.start();
Console.WriteLine(" run");
d.run();
Console.WriteLine("stop ");
d.stop();
Console.WriteLine(" override");
d.calculateSpeed();
break;

default:
Console.WriteLine("You pressed wrong value.");
break;
}

}
}
}
Muhammad Osama CSC-18F-076

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy