0% found this document useful (0 votes)
38 views

C Sharp Oop Design

The document contains code for two C# classes - ItemType and Program. The ItemType class defines properties for name, cost per day, and deposit of an item. It contains a Display method that prints these property values. The Program class contains a Main method that creates an ItemType object, takes user input to set its property values, and calls Display to output them. It also contains code to calculate the greatest common divisor of two numbers entered by the user, and output their division in simplest fractional form.

Uploaded by

Abhijat Thakare
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

C Sharp Oop Design

The document contains code for two C# classes - ItemType and Program. The ItemType class defines properties for name, cost per day, and deposit of an item. It contains a Display method that prints these property values. The Program class contains a Main method that creates an ItemType object, takes user input to set its property values, and calls Display to output them. It also contains code to calculate the greatest common divisor of two numbers entered by the user, and output their division in simplest fractional form.

Uploaded by

Abhijat Thakare
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Que 1

ItemType.cs

using System;
public class ItemType{

private string _name;


private double _costPerDay;
private double _deposit;

public string Name{


get{
return this._name;
}
set{
this._name = value;
}
}
public double CostPerDay{
get{
return this._costPerDay;
}
set{
this._costPerDay = value;
}
}
public double Deposit{
get{
return this._deposit;
}
set{
this._deposit = value;
}
}

public void Display() {


//fill code here
Console.WriteLine("Item type details");
Console.WriteLine("Name:"+_name);
Console.WriteLine("CostPerDay:"+_costPerDay.ToString("0.00"));
Console.WriteLine("Deposit:"+_deposit.ToString("0.00"));
}
}

Program.cs

using System;
public class Program{
public static void Main(){

ItemType it = new ItemType();


Console.WriteLine("Enter the item type name");
it.Name = Console.ReadLine();
Console.WriteLine("Enter the cost per day");
it.CostPerDay = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the deposit");
it.Deposit = Convert.ToDouble(Console.ReadLine());
it.Display();
}
}
---------------------------------------------------

que2

using System;

public class Program


{
static void Main(string[] args)
{
int num = Convert.ToInt32(Console.ReadLine());
int den=1;
try
{
den = Convert.ToInt32(Console.ReadLine());
}
catch (Exception exe)
{
Console.WriteLine("0");
return;
}
PrintValue(num,den);
}

static void PrintValue(int num, int den)


{
int d = num / den;
int rem = (num % den);
//Console.WriteLine(rem);
if (rem == 0)
{
Console.Write(d);
}
else if (d == 0)
{
//✌ jisme decimal part nhi h
Console.WriteLine(num/Hcf(rem,den) + "/" + (den/Hcf(rem,den)));
}
else // if ((den % rem) != 0)
{
Console.Write(d + " " + (rem / Hcf(rem, den)) + "/" + (den / Hcf(rem,
den)));
}
}

static int Hcf(int rem, int d)


{
int x = rem;
int y = d;
while (x != y)
{
if (x > y)
{
x -= y;
}
else
{
y -= x;
}

}
return y;
}
}

------------------------------------------

Que 3

You might also like