Помогите пожалуйста написать программу в C++
{
fun myFun = fun(1, 2,5);
cout<<"Welcome to Online IDE!! Happy Coding :)";
myFun.print();
return 0;
}
Ответы
Відповідь:
C++ code:
#include <iostream>
class Number{
private:
int a,b,c;
int d;
public:
Number();
Number(int,int,int,int);
Number(const Number&);
~Number() = default;
bool check();
void exp();
};
Number::Number(){
a = 0;
b = 0;
c = 0;
d = 0;
}
Number::Number(int a,int b,int c,int d){
this->a = a;
this->b = b;
this->c = c;
this->d = d;
}
Number::Number(const Number& object){
this->a = object.a;
this->b = object.b;
this->c = object.c;
this->d = object.d;
}
bool Number::check(){
return (c - d == b && b - d == a);
}
void Number::exp(){
if(this->check()){
int counter = 0,i = this->a;
std::cout << i << " ";
while(counter <= 15){
i += this->d;
std::cout << i << " ";
counter++;
}
}
else{
std::cout << "This is not a progression" << std::endl;
}
}
int main(){
Number obj(4,12,20,8);
obj.exp();
return 0;
}
using namespace std;
class fun
{
public:
fun(int _a1, int _a2, int _a3)
{
a1 =_a1;
a2 = _a2;
a3 = _a3;
check() ;
}
void print() {
if(isAriph) {
for (int i=1;i<11;i++) std::cout << a3+d*i<< " ";
}
else std::cout << "Это не арифметическая последовательность";
}
private:
int a1, a2, a3, d;
bool isAriph;
void check() {
if((a2-a1) == (a3-a2)) {
isAriph = true;
d = a3-a2;}}
};