Navbatda birinchi va oxirgi elementlar o‘rni almashtirilsin


Download 24.56 Kb.
Sana01.05.2023
Hajmi24.56 Kb.
#1418482
Bog'liq
New DOCX Document


Navbatda birinchi va oxirgi elementlar o‘rni almashtirilsin.
#include
#include
#include

using namespace std;


int main() {


vector players {185, 195, 180, 190, 175};
int n = players.size();
cout << "kiritilgan qiymatlar: ";
for (int i = 0; i < n; i++) {
cout << players[i] << " ";
}
cout << endl;
swap(players[0], players[n-1]);
sort(players.begin(), players.end());
cout << "keyin paydo bolgan qiymatlar: ";
for (int i = 0; i < n; i++) {
cout << players[i] << " ";
}
cout << endl;

return 0;


}
Qora oyna
kiritilgan qiymatlar: 185 195 180 190 175
keyin paydo bolgan qiymatlar: 175 180 185 190 195
#include"stdafx.h"
#include
#include
using namespace std;
class People {
public:
string name;
string family;
int age;
};

class Students : public People {


public:
double price;
};

bool compareAge(Students s1, Students s2) {


return s1.age < s2.age;
}
bool compareName(Students s1, Students s2) {
return s1.name < s2.name;}

int main() {


const int NUM_STUDENTS = 5;
Students studentList[NUM_STUDENTS] = {
{"John", "Doe", 20, 100.0},
{"Jane", "Smith", 19, 80.0},
{"Bob", "Johnson", 22, 120.0},
{"Alice", "Lee", 18, 90.0},
{"David", "Kim", 21, 110.0}
};

sort(studentList, studentList + NUM_STUDENTS, compareAge);


cout << "Sorted by age in ascending order:" << endl;


for (int i = 0; i < NUM_STUDENTS; i++) {
cout << studentList[i].name << " " << studentList[i].family << ", " << studentList[i].age << " years old, $" << studentList[i].price << endl;
}
sort(studentList, studentList + NUM_STUDENTS, compareName);

cout << "\nSorted by name in alphabetical order:" << endl;


for (int i = 0; i < NUM_STUDENTS; i++) {
cout << studentList[i].name << " " << studentList[i].family << ", " << studentList[i].age << " years old, $" << studentList[i].price << endl;
}

return 0;


system{"pause");
}

Download 24.56 Kb.

Do'stlaringiz bilan baham:




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