22-Amaliy topshiriq
1-vazifa.
using System;
using System.IO;
namespace cFile
{
class Program
{
static void Main(string[] args)
{
string[] a=new string[4];
a[0] = @"E:\salom.txt";
a[1] = @"E:\salom1.txt";
a[2] = @"E:\salom2.txt";
a[3] = @"E:\salom3.txt";
int s=0;
for (int i = 0; i < 4; i++)
{
FileInfo file = new FileInfo(a[i]);
if (file.Exists)
{
s++;
}
}
Console.WriteLine("Joriy katologda berilgan fayillarning "+s+" mavjud");
}
}
}
2-vazifa.
using System;
using System.IO;
namespace cFile
{
class Program
{
static void Main(string[] args)
{
string path = @"E:\Salom.txt";
int i = 0,k=0;
using(StreamReader ou = File.OpenText(path))
{
string S = "";
while ((S = ou.ReadLine()) != null)
{
foreach (var item in S)
{
if((int)item==32)
{k++;}
}k++;
}
}
Console.WriteLine(k);
string[] a=new string[k];
using(StreamReader ou = File.OpenText(path))
{
string S = "";
while ((S = ou.ReadLine()) != null)
{
string[] salom = S.Split(" ");
foreach (string u in salom)
{
a[i]=u;
Console.WriteLine(a[i]);i++;
}
}
}
Console.WriteLine("------------------------------");
for (int j = 0; j < k-1; j++)
{
Console.Write(a[j]+" ");
}
Console.ReadKey();
}
}
}
3-vazifa.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace _3021
{
class Program
{
static void Main(string[] args)
{
string path = @"E:\salom.txt";
string newPath = @"E:\salom1.txt";
FileInfo file = new FileInfo(path);
if (file.Exists)
{
file.CopyTo(newPath);
Console.WriteLine("fayl nusxalandi");
}
Console.ReadKey();
}
}
}
23-Amaliy topshiriq.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace amaliy23
{
class Tavar
{
public string Kompiyuter;
public int Soni;
public string Noutbuk;
public int Soni1;
public string Telefon;
public int Soni2;
public Tavar() : this("hp")
{
}
public Tavar(string Kompiyuter) : this(Kompiyuter, 30 , "asus", 25 ,"samsung" , 50)
{
}
public Tavar(string Kompiyuter , int Soni, string Noutbuk,int Soni1,string Telefon,int Soni2)
{
this.Kompiyuter = Kompiyuter;
this.Soni = Soni;
this.Noutbuk = Noutbuk;
this.Soni1=Soni1;
this.Telefon=Telefon;
this.Soni2=Soni2;
}
public void GetInfo()
{
Console.WriteLine($"Kompiyuter \n Nomi: {Kompiyuter} Soni: {Soni} \nNoutbuk \n Nomi: {Noutbuk} Soni: {Soni1} \nTelefon \n Nomi: {Telefon} Soni:{Soni2}");
}
class Program
{
static void Main(string[] args)
{
int a, b, c;
string x,y,z;
Console.Write("Kompiyuter nomi ");
x=Console.ReadLine();
Console.Write(" Soni nechta ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Noutnbuk nomi ");
y=Console.ReadLine();
Console.Write(" Soni nechta ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Telefon nomi ");
z=Console.ReadLine();
Console.Write(" Soni nechta ");
c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Tavarlar ");
Tavar D= new Tavar(x);
D.GetInfo();
Tavar F=new Tavar(x,a,y,b,z,c);
F.GetInfo();
Console.ReadKey();
}
}
}
}
24-Amaliy topshiriq.
using System;
namespace AX
{
class Point
{
protected int x;
protected int y;
}
class DerivedPoint: Point
{
static void Main()
{
var dpoint = new DerivedPoint();
// Direct access to protected members.
int s=0;
dpoint.x = 30;
dpoint.y = 15;
for (int i = 2; i < dpoint.x; i++)
{
s=0;
for (int j = 1; j < i; j++)
{
if (i%j==0)
{
s+=j;
}
}
if(i==s)
{Console.WriteLine(s);}
}
}
}
}
Do'stlaringiz bilan baham: |