Ifstream file("students txt")


Download 63.14 Kb.
Sana17.06.2023
Hajmi63.14 Kb.
#1527205
Bog'liq
Dasturlash V4


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI
UNIVERSITETINING DASTURIY INJINIRING
FAKULTETI TALABASI LOCHINBEK ALMURADOVNING
DASTURLASH II FANIDAN

LABARATORIYA ISHI

TOSHKENT 2023


1.

Matnli faylda N ta talabaning familiyasi, ismi va yoshi yozilgan. Ushbu
ma'lumotlarni to'plrunga o' zlashtirib, lSilli bo'yicha saralovchi dastur tuzing.

#include
#include
#include
using namespace std;

struct Student {


string last_name;
string first_name;
int age;
};

bool operator<(const Student& a, const Student& b) {


return a.first_name < b.first_name;
}

int main() {


ifstream file("students.txt");
int n;
file >> n;
set students;

for (int i = 0; i < n; i++) {


Student student;
file >> student.last_name >> student.first_name >> student.age;
students.insert(student);
}

for (auto student : students) {


cout << student.first_name << " " << student.last_name << ", " << student.age << endl;
}

return 0;


}


  1. N ta complex son berilgan. Ularning mavhum qismlari tasodifiy toq sonlar bilan to'ldirilsin han1da ushbu N ta coplex sonning yig'indisi topilsin.

#include
using namespace std;
int main(){
complexa(2,0);
int N;
cin>>N;
srand(time(NULL));
complexsum(0,0);
for(int i = 0; i < N; i++){
if((rand()%100+i)%2!=0){
a.imag(rand()%100+i);
sum+=a;
cout<}
}



  1. Complex sinfidan foydalanib, ikkita kompleks sonlarni qo’shing

  2. Slice sinfidan foydalanib valarray massiv elementlari juftlari sonini aniqlang.

  3. gslice sinfidan foydalanib valarray massiv elementlarini 0 indexdan boshlab (2,5) qiymatlar sonida (2,6) qadamdagilar farqi bilan 10 ga to’ldiring.

#include
using namespace std;
int main()
{
cout << "1-topshiriq\n";
complex a(12, 45);
complex b(45, 6);
cout << "a+b" << a + b;
cout << "\n2-topshiriq\n";
valarray arr(10);
for (int i = 0; i < arr.size(); i++)
{
arr[i] = rand() % 10;
}

// Massivni slice'lar orqali juft va toq sonlarga ajratish


valarray even = arr[slice(0, arr.size() / 2, 2)];
valarray odd = arr[slice(1, arr.size() / 2, 2)];

cout << "Array: ";


for (int i = 0; i < arr.size(); i++)
{
cout << arr[i] << " ";
}
cout << endl;
cout << "Even elements: ";
for (int i = 0; i < even.size(); i++)
{
cout << even[i] << " ";
}
cout << endl;
cout<<"\n3-topshiriq\n";
valarray arr1(50);
for (int i = 0; i < 50; i++) {
arr1[i] = i;
}
// gslice obyekti yaratamiz
size_t size = 5;
size_t stride = 6;
valarray lengths {size, size};
valarray strides {stride, stride};
arr1[gslice(0, lengths, strides)]=10;
// Natijani chop etamiz
for (int i = 0; i < size*size; i++) {
cout << arr1[i] << " ";
}
cout << endl;

return 0;


}


Download 63.14 Kb.

Do'stlaringiz bilan baham:




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