Type definitions
using System;
public enum Direction { Right, Left, Forward };
class Chaharpa
{
private int age;
private int height;
private int cordinates_x;
private int cordinates_y;
public Chaharpa(int a, int b, int x, int y)
{
age = a;
height = b;
cordinates_x = x;
cordinates_y = y;
}
public Chaharpa(int c, int d)
{
age = c;
height = d;
cordinates_x = 0;
cordinates_y = 0;
}
public int Age
{
get { return age; }
}
public int Height
{
get { return height; }
}
public int Cordinates_x
{
get { return cordinates_x; }
set { cordinates_x = value; }
}
public int Cordinates_y
{
get { return cordinates_y; }
set { if (value > 0) cordinates_y = value; }
}
public void Move(Direction direction)
{
if (direction == Direction.Forward)
Cordinates_y++;
else if (direction == Direction.Right)
Cordinates_x++;
else if (direction == Direction.Left)
Cordinates_x--;
}
class horse : Chaharpa
{
public bool is_wild;
public void Jump(int x)
{
x = Cordinates_y;
Cordinates_y += 5;
}
public void Print()
{
Console.WriteLine("Horse Information: Age," + Age + ", Height: " + Height + ", Wild: " + is_wild + ", X: " + Cordinates_x + ", Y: " + Cordinates_y);
}
}
}
Usage
class Program
{
static void Main(string[] args)
{
int age, x, y, minAge = 0;
int height;
bool wild;
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Horse #" + (i + 1));
Console.Write("Enter Age: ");
age = int.Parse(Console.ReadLine());
Console.Write("Enter Height: ");
height = int.Parse(Console.ReadLine());
Console.Write("Enter X: ");
x = int.Parse(Console.ReadLine());
Console.Write("Enter Y: ");
y = int.Parse(Console.ReadLine());
Console.Write("Is Wild: ");
wild = bool.Parse(Console.ReadLine());
minAge = age;
if (minAge > age)
{
minAge = age;
}
}
Console.WriteLine();
horse ob = new horse();
ob.Jump(minAge);
ob.move();
ob.Print();
Console.ReadKey();
}
}
I get these errors in Visual Studio:
'Chaharpa' does not contain a constructor that takes 0 arguments
The type or namespace name 'horse' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'horse' could not be found (are you missing a using directive or an assembly reference?)