1) (первые 2 скриншота)
#include <iostream>using std::cout;using std::endl;#include <cstdlib>using std::rand;using std::srand;#include <ctime>using std::time;int main(){ int a[10]; srand(time(0)); for(int i = 0; i < 10; i++) { a[i] = rand() % 101; cout << a[i] << ' '; } cout << endl << endl; for(int i = 0; i < 10; i++) { if(a[i] % 3 == 0 && a[i] > 13) { cout << a[i] << ' '; } } cout << endl; return 0;}
2)
#include <iostream>using std::cout;using std::endl;int main(){ double a[10] = { 1.2, 0.0, -5.8, -0.4, 10.5, 14.6, -6.3, -8.8, -4.1, 0.0 }; int A = 0, B = 3; for(int i = 0; i < 10; i++) { cout << a[i] << ' '; if(a[i] < 0.0) { a[i] += a[A]; } else if(a[i] == 0) { a[i] -= B; } } cout << "\n\na(index) = " << A << ", b = " << B << "\n\n"; for(int i = 0; i < 10; i++) { cout << a[i] << ' '; } cout << endl; return 0;}
class Person(object):
def __init__(self, name = 'Bob', age = 25): #Значения по умолчанию заданы в конструкторе
self._name = name
self._age = age
@property
def name(self): #Свойство, возвращающее значение obj._name
return self._name
def age(self): #Свойство, возвращающее значение obj._age
return self._age
def say_hi(self): #Рандомный метод
print(f'Hi, im {self._name}, im {self._age} yo')
def set_age(self, value): #Метод для изменения значения свойства obj._age
if value in range(1, 101):
self._age = value
else: raise RuntimeError('Bad Argument', f'Cant set age {value}, age must be in range [1, 100]')
Объяснение:
Второй класс попробуй реализовать сам
1) (первые 2 скриншота)
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int main()
{
int a[10];
srand(time(0));
for(int i = 0; i < 10; i++)
{
a[i] = rand() % 101;
cout << a[i] << ' ';
}
cout << endl << endl;
for(int i = 0; i < 10; i++)
{
if(a[i] % 3 == 0 && a[i] > 13)
{
cout << a[i] << ' ';
}
}
cout << endl;
return 0;
}
2)
#include <iostream>
using std::cout;
using std::endl;
int main()
{
double a[10] = { 1.2, 0.0, -5.8, -0.4, 10.5, 14.6, -6.3, -8.8, -4.1, 0.0 };
int A = 0, B = 3;
for(int i = 0; i < 10; i++)
{
cout << a[i] << ' ';
if(a[i] < 0.0)
{
a[i] += a[A];
}
else if(a[i] == 0)
{
a[i] -= B;
}
}
cout << "\n\na(index) = " << A << ", b = " << B << "\n\n";
for(int i = 0; i < 10; i++)
{
cout << a[i] << ' ';
}
cout << endl;
return 0;
}
class Person(object):
def __init__(self, name = 'Bob', age = 25): #Значения по умолчанию заданы в конструкторе
self._name = name
self._age = age
@property
def name(self): #Свойство, возвращающее значение obj._name
return self._name
@property
def age(self): #Свойство, возвращающее значение obj._age
return self._age
def say_hi(self): #Рандомный метод
print(f'Hi, im {self._name}, im {self._age} yo')
def set_age(self, value): #Метод для изменения значения свойства obj._age
if value in range(1, 101):
self._age = value
else: raise RuntimeError('Bad Argument', f'Cant set age {value}, age must be in range [1, 100]')
Объяснение:
Второй класс попробуй реализовать сам