|
Private: double real
|
tarix | 05.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
Dostları ilə paylaş: |
|
|