Uploaded by Diesel Kapasule

COURSEWORK VARIANT 5 (Autosaved)

advertisement
COURSEWORK VARIANT 5:
1 It’s necessary to create C# program to calculate an expression when x varies from xmin to xmax with dx step. All
values of data must be entered from a file.
z  5 ln( c  x )  sin( x ) 
tg (cx )  cx
ln( c  x )
2 There are three one-dimensional arrays: q , w, r. Each of them has arbitrary amount of elements. It’s necessary to
create C# program to calculate a maximum and minimum elements and their indexes.
3 Create Train class. It has next member variables: destination , price, time. Besides of there are member
functions entering the values of data and to output the data into the screen if an object corresponds to several
demands of customer. The customer would like to select a train of demand destination. A time of train departure
must be less or equal desire time.
4 There is base class animal. It has next member variables: kind, inhabitation, age and weight. There are two derived
classes from class animal: class dog and class horse. Besides of kind, inhabitation, weight and age each dog has an
additional member variable-a breed. The horse also has an additional member variable- a travel speed. Both derived
classes have the functions to enter and to output all data about a dog and about a horse. These data also contain
general data that are in base class.
5 Create a C# program for drawing a rectangle. A pen Color must be DarkCyan. This pen isn't standard because its
width must be equal to 4 pixels and Line Style is DashDotDot. Inside the rectangle must be placed any text. A font is
"Times New Roman". Its size equal to 14. Also create a Hatch Brush. A Hatch Style is DiagonalBrick. A Color is
DarkBlue. This brush to use for drawing ellipse . The sizes of all graphics figures are arbitrary.
TASK 1:
CODE WITH C#
using System;
namespace pro1
{
class MainClass
{
public static void Main(string[] args)
{
double z, xmin, xmax, c=4, x, dx;
string s;
Console.WriteLine("Please enter xmin:");
s = Console.ReadLine();
xmin = Convert.ToDouble(s);
Console.WriteLine("Please enter dx:");
s = Console.ReadLine();
dx = Convert.ToDouble(s);
Console.WriteLine("Please enter xmax:");
s = Console.ReadLine();
xmax = Convert.ToDouble(s);
for (x = xmin; x <= xmax; x += dx)
{
if ((c - x) > 0 && Math.Log(c - x) + Math.Sin(x) > 0)
{
z = Math.Pow(Math.Log(c - x) + Math.Sin(x), 1.0 / 5.0);
Console.WriteLine("xmin={0} , dx={1} , xmax={2} ,the result z={3} ", xmin, dx, xmax, z);
}
else
{
Console.WriteLine(" Z cannot be calculated");
}
}
Console.ReadKey();
}
}
}
TASK 2:
using System;
namespace pro3
{
class MainClass
{
public static void Main(string[] args)
{
int n;
string s;
Console.WriteLine("Enter n");
s = Console.ReadLine();
n = Convert.ToInt32(s);
double[] q = new double[4];
double q_min = q[0];
double imin = 0;
double q_max = q[0];
double imax = 0;
for (int i = 0; i < q.Length; i++)
{
Console.WriteLine("Enter q[{0}]=", i);
s = Console.ReadLine();
q[i] = Convert.ToDouble(s);
if (q[i] > q_min)
{
q_min = q[i];
imin = i;
}
else if (q[i] < q_max)
{
q_max = q[i];
imax = i;
}
}
Console.WriteLine("The minimum of the array is {0} and its index is {1}", q_max, imax);
Console.WriteLine("The maximum of the array is {0} and its index is {1}", q_min, imin);
}
}
}
TASK 3:
using System;
namespace pro2
{
class Train
{
string destination;
double price;
int time;
int Attribute;
public void input()
{
string s;
Console.WriteLine("Please enter the destination of the train :");
destination = Console.ReadLine();
Console.WriteLine("Please enter the price ");
s = Console.ReadLine();
price = Convert.ToDouble(s);
Console.WriteLine("Please enter the time of departure");
s = Console.ReadLine();
time = Convert.ToInt32(s);
}
public void analyses(ref int desire_time, ref double desire_price )
{
if (time <= desire_time && price <= desire_price)
{
Attribute = 1;
}
else
Attribute = 0;
}
public void output()
{
if (Attribute != 0)
{
Console.WriteLine("This train is suitable for you");
Console.WriteLine("The destination is ={0} , price is={1} and the time is
={2}", destination, price, time);
}
else
Console.WriteLine("{0} train isn't suitable for you ",destination);
}
}
class MainClass
{
public static void Main(string[] args)
{
int n;
string s;
Console.WriteLine("Enter the number of trains n=");
s = Console.ReadLine();
n = Convert.ToInt32(s);
Train[] X = new Train[n];
double desire_price;
string destination;
int desire_time;
Console.WriteLine("Enter the destination of the train");
destination= Console.ReadLine();
Console.WriteLine("Enter the desire price of the train");
s = Console.ReadLine();
desire_price = Convert.ToDouble(s);
Console.WriteLine("Enter the time of departure of the train ");
s = Console.ReadLine();
desire_time = Convert.ToInt32(s);
Console.WriteLine("Analysing your input requirements !!!");
for (int i=0;i<X.Length;i++)
{
X[i] = new Train();
X[i].input();
X[i].analyses(ref desire_time, ref desire_price);
X[i].output();
}
}
}
}
TASK 4:
CODE WITH C#
using System;
namespace pro3
{
class Animal
{
protected string kind;
protected double weight;
protected int age;
protected string inhabitation;
}
class Dog: Animal
{
string breed;
public void input()
{
Console.WriteLine("Please enter the kind of the Dog:");
kind = Console.ReadLine();
Console.WriteLine("Please enter the weight of the Dog ");
string s;
s = Console.ReadLine();
weight = Convert.ToDouble(s);
Console.WriteLine("Please enter the age of the dog");
s = Console.ReadLine();
age = Convert.ToInt32(s);
Console.WriteLine("Please enter the inhabitation ");
s = Console.ReadLine();
Console.WriteLine(" Enter the breed of the dog :");
breed = Console.ReadLine();
}
public void output()
{
Console.WriteLine("The kind of the dog is ={0} , its weight is={1} , age={2} , inhabitation =
{3} and the breed is ={4}",kind,weight,age,inhabitation,breed);
}
}
class Horse : Animal
{
double horse_speed;
public void input()
{
string s;
Console.WriteLine("Please enter the kind of Horse");
kind = Console.ReadLine();
Console.WriteLine("Please enter the weight of the horse");
s = Console.ReadLine();
weight = Convert.ToDouble(s);
Console.WriteLine("Please enter the age of the horse");
s = Console.ReadLine();
Console.WriteLine("Please enter the inhabitation of the horse");
inhabitation = Console.ReadLine();
Console.WriteLine("Please enter the speed of the horse");
s = Console.ReadLine();
horse_speed = Convert.ToDouble(s);
}
public void output()
{
Console.WriteLine("The kind of the horse is={0} , weight={1} , age={2} , inhabitation is={3}
and the speed is ={4}",kind,weight,age,inhabitation,horse_speed);
}
}
class MainClass
{
public static void Main(string[] args)
{
Dog d = new Dog();
Console.WriteLine("DOG");
d.input();
d.output();
Horse h = new Horse();
Console.WriteLine("HORSE");
h.input();
h.output();
}
}
}
Download