Variant №1 1-masala


Download 88.75 Kb.
Sana17.06.2023
Hajmi88.75 Kb.
#1534377
Bog'liq
Mustaqil ish 2


Fan: Algoritmik tillar va dasturlash Guruh 21.06 2022-2023-o’quv yili

Variant № 1
1-masala. F(x)= funksiyaning qiymatini hisoblovchi metod yarating. Delegat yordamida funksiyaning x=10 dagi qiymatini chiqarib beruvchi dastur tuzing.
Masalaning C# dagi matni:
using System;

namespace Mustaqil_ish_2
{
delegate double Funksiya(double x);
class Y
{
public static double natija(double x)
{
return Math.Sqrt(Math.Log(x,3)+x*x);
}
}
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("x ni kiriting:");
double x=double.Parse(Console.ReadLine());
try
{
if(x<=0) throw new Exception();
Funksiya a=new Funksiya(Y.natija);
Console.WriteLine(a(x));
}
catch
{
Console.WriteLine("x noldan katta bo'lishi kerak");
}
Console.ReadKey(true);
}
}

Natija:

2-masala. A={“Salom”,”Olma”,”Bahor”,”Yaxshi”,”Tosh”,”Inson”,”Baxo”,”Besh”} massiv, n va k butun son berilgan. Massivning n indeksli elementining oxirgi harfini k indeksli elementining oxirfi harfi bilan almashtiruvchi lambda ifoda yarating va undan foydalanib almashtirishni bajaruvchi dastur tuzing.
Masalaning C# dagi matni:
using System;

namespace Mustaqil_ish2
{
class Program
{
public static void Main(string[] args)
{
string[] A=new string[8];
A[0]="Salom";
A[1]="Olma";
A[2]="Bahor";
A[3]="Yaxshi";
A[4]="Tosh";
A[5]="Inson";
A[6]="Bxo";
A[7]="Besh";

try
{
Console.Write("n=");
int n=int.Parse(Console.ReadLine());
Console.Write("k=");
int k=int.Parse(Console.ReadLine());
char a1=A[n][A[n].Length-1];;
char a2=A[k][A[k].Length-1];
A[n]=A[n].Remove(A[n].Length-1)+a2;
A[k]=A[k].Remove(A[k].Length-1)+a1;
Console.WriteLine("Bajarildi: {0}...{1}",A[n],A[k]);
}
catch
{
Console.WriteLine("xato");
}
Console.ReadKey(true);

}
}
}


Natija:


3-masala. A ixtiyoriy haqiqiy son berilgan. Agar berilgan son musbat son bo’lsa uning kvadrat ildizini chiqaruvchi dastur tuzing, aks xolda, throw operatori yordamida yangi istisno yaratilsin va catch blokida “Musbat son kiritilmadi!” yozuvi chiqarilsin. Dasturda anonim metoddan foydalaning.
Masalaning C# dagi matni:
using System;

namespace Mustaqil_ish_2
{
delegate double D(double A);
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("A ni kiriting:");
double A=double.Parse(Console.ReadLine());
try
{
if(A<0) throw new Exception();
D a=delegate(double x)
{
return Math.Sqrt(x);
};
Console.WriteLine(a(A));

}
catch


{
Console.WriteLine("Musbat son kiritilmadi.");
}
Console.ReadKey(true);
}
}

Natija:

4-masala. Formaga bitta DataTimePicker, bitta Label va bitta Button elementlarini joylang. Button1 tugmasi bosilganda joriy yilning birinchi shanba kuni sanasini dataTimePicker da chiqaruvchi va shu sanani “kun.oy.yil” fotmatida (masalan: 31.12.2022) label1 ga yozuvchi dastur tuzing.
Masalaning C# dagi matni:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Mustaqil_ish_2
{

public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
DateTime a=DateTime.Now;
a=new DateTime(a.Year,1,1);
switch(a.DayOfWeek.ToString())
{
case "Monday": a=a.AddDays(5);break;
case "Tuesday": a=a.AddDays(4);break;
case "Wednesday": a=a.AddDays(3);break;
case "Thursday": a=a.AddDays(2);break;
case "Friday": a=a.AddDays(1);break;
case "Sunday": a=a.AddDays(6);break;
}
dateTimePicker1.Value=a;
label1.Text=a.Day+"."+a.Month+"."+a.Year;
}

}
}
Natija:




5-masala. Formaga bitta Label va bitta Button elementlarini joylang.Button1 tugma bosilganda label1 ning orqa foni sariqqa bo’yaladigan dastur tuzing.
Masalaning C# dagi matni:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Mustaqil_ish_2
{

public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
label1.BackColor=Color.Yellow;
}
}
}
Natija:


6-masala. 4 ta parametrli 5 ta elementdan iborat ro’yxat yarating(List<> yordamida).Ro’yxatni chiqaruvchi dastur tuzing.
Masalaning C# dagi matni:
using System;
using System.Collections;
using System.Collections.Generic;

namespace Mustaqil_ish2
{
class Program
{
public static void Main(string[] args)
{
List a=new List();
a.Add(new D{FIO="Odilov Omadbek",Fakultet="Matematika-Informatika",Yunalish="Amaliy matematika",Guruh="21.06"});
a.Add(new D{FIO="Mamasharipov Fayzullo",Fakultet="Matematika-Informatika",Yunalish="Amaliy matematika",Guruh="21.07"});
a.Add(new D{FIO="Nuriddinov Nurbek",Fakultet="Matematika-Informatika",Yunalish="Amaliy matematika",Guruh="21.08"});
a.Add(new D{FIO="Abdurahimova Maftuna",Fakultet="Matematika-Informatika",Yunalish="Matematika(rus)",Guruh="21.05"});
a.Add(new D{FIO="Odilova Anora ",Fakultet="Pedagogika psixologiya",Yunalish="Amaliy psixologiya",Guruh="21.19"});
foreach(var b in a)
{
Console.WriteLine(b.FIO+" || "+b.Fakultet+" || "+b.Yunalish+" || "+b.Guruh);
}
Console.ReadKey(true);

}
}
class D


{
public string FIO{get;set;}
public string Fakultet{get;set;}
public string Yunalish{get;set;}
public string Guruh{get;set;}

}
}
Natija:




Bajardi:Davronbek Abdujabborov Qabul qildi:E.Islomov

Download 88.75 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling