Private: double real



Yüklə 13,17 Kb.
tarix05.08.2023
ölçüsü13,17 Kb.
#138693
Документ Microsoft Word


1-topshiriq.
#include

class Complex {


private:
double real;
double imag;

public:
Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) {}

// Postfix decrement operator (i--)
Complex operator--(int) {
Complex temp(real, imag);
real--;
imag--;
return temp;
}

// Function to display the complex number


void display() {
std::cout << real << " + " << imag << "i" << std::endl;
}
};

int main() {


Complex num(5.0, 3.0);
std::cout << "Original complex number: ";
num.display();

Complex result = num--; // Postfix decrement


std::cout << "Complex number after decrement: ";
num.display();

std::cout << "Value returned from postfix decrement: ";


result.display();

return 0;


}
2-topshiriq.
#include
#include

int main() {


const int size = 100; // Massiv uzunligi
std::valarray arr(size);

// Massiv elementlarini to'ldiramiz


for (int i = 0; i < size; ++i) {
arr[i] = i;
}

// slice sinfini aniqlash


std::slice mySlice(0, size / 7, 7);

// slice orqali qadamdagilarni 27 tasini topish


std::valarray result = arr[mySlice] + 27;

// Natijalarni ekranga chiqarish


for (int i = 0; i < result.size(); ++i) {
std::cout << result[i] << " ";
}
std::cout << std::endl;

return 0;


}

3-topshiriq.


#include
#include
#include

int main() {


std::map dictionary;

// Lug'atga so'z va uning tarjimasi kiritiladi


std::string word, translation;
char choice;

do {
std::cout << "So'zni kiriting: ";


std::cin >> word;

std::cout << "Tarjimasini kiriting: ";


std::cin >> translation;

dictionary[word] = translation;

std::cout << "Yana so'z kiritasizmi? (h/y): ";
std::cin >> choice;
} while (choice == 'h' || choice == 'H');

// So'zni qidirish tugmasi qo'shish


std::string searchWord;
std::cout << "Qidirish uchun so'zni kiriting: ";
std::cin >> searchWord;

// Qidirish va natijani chiqarish


std::map::iterator iter = dictionary.find(searchWord);
if (iter != dictionary.end()) {
std::cout << "Tarjimasi: " << iter->second << std::endl;
} else {
std::cout << "Bu so'z lug'atda topilmadi." << std::endl;
}

return 0;


}

Yüklə 13,17 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin