Вы находитесь на странице: 1из 106

Программы для экзамена по программированию

УКАЗАТЕЛИ
2
#include <stdio.h>
// задание по переворачиванию числовой последовательности с помощью поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t,j,i;// создаем переменные i для счета с начала и j для счета с конца последовательности
for(i = 0,j=n-1; i < j;i++,j--) // меняем местами i и j
{
t=*(A+i);
*(A+i)=*(A+j);
*(A+j)=t;
}
for(int x = 0; x < n;x++)// выводим на экран получившийся трэш
{
printf("%d ", *(A+x));
}
}

3
#include <stdio.h>
// задание по вычислению суммы числовой последовательности с помощью поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t = 0,j,i;
for(i = 0; i < n;i++)
{
t= *(A+i)+t;

}
printf("Suma chisel = %d\n",t);
}
4
#include <stdio.h>
// задание по вычислению суммы четных чисел в числовой последовательности с помощью
поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t = 0,j,i;
for(i = 0; i < n;i++)
{
if(*(A+i)%2 == 0)
{
t= *(A+i)+t;
}
}
printf("Suma chetnih chisel = %d\n",t);
}
5
#include <stdio.h>
// задание по вычислению суммы нечетных чисел в числовой последовательности с помощью
поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t = 0,j,i;
for(i = 0; i < n;i++)
{
if(*(A+i)%2 != 0)
{
t= *(A+i)+t;
}
}
if(n == 1){printf("Suma nechetnih chisel = %d\n",n);}
else{
printf("Suma nechetnih chisel = %d\n",t);}
}
6
#include <stdio.h>
// задание по вычислению произведения четных чисел в числовой последовательности с помощью
поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t = 1,j,i;
for(i = 0; i < n;i++)
{
if(*(A+i)%2 == 0)
{
t= *(A+i)*t;
}
}
printf("Proizvedenie chetnih chisel = %d\n",t);
}
7
#include <stdio.h>
// задание по вычислению произведения нечетных чисел в числовой последовательности с
помощью поинтеров
int main()
{
int n;
printf("Vvedite chislo chisel:\n");
scanf("%d",&n);
printf("\n______________________________\n");
int A[n];// создаем числовую последовательность
for(int z = 0;z<n;z++) // вписываем в неё наши числа
{
scanf("%d",&*(A+z));
}
int t = 1,j,i;
for(i = 0; i < n;i++)
{
if(*(A+i)%2 != 0)
{
t= *(A+i)*t;
}
}
printf("Proizvedenie nechetnih chisel = %d\n",t);
}
8
#include <stdio.h>
//программа которыая должна была считывать элементы массива но считывает индекс:(
int main()
{
int t = 0,i;
int A[10]={1};

if(sizeof(*(A+1)) == 1)
{
for(i = 0;i<10;i++)
{
t=sizeof(*(A+i))+t;
}
printf("The number of elemrnts in array %d",t);
}
else if(sizeof(*(A+1)) == 4)
{
for(i = 0;i<10;i++)
{
t=((sizeof(*(A+i)))/4)+t;
}
printf("The number of elemrnts in array %d", t);
}

else if(sizeof(*(A+1)) == 8)
{
for(i = 0;i<10;i++)
{
t=((sizeof(*(A+i)))/8)+t;
}
printf("The number of elemrnts in array %d", t);
}
else
{
for(i = 0;i<10;i++)
{
t=((sizeof(*(A+i)))/2)+t;
}
printf("The number of elemrnts in array %d", t);
}
return 0;
}
9
10
#include <stdio.h>
//программа которыая вычисляет максимальное и минимально число в векторе
int main()
{
int A[5]={4,5,21,2,6};
int *pA;
int i,result,tmp;
pA=A;
result=*A;
for(i = 0;i<5;i++)
{
tmp=*(A+i);
if(result<tmp)
{
result=tmp;
}
}
printf("Max element of array = %d",result);
result=*A;
for(i = 0;i<5;i++)
{
tmp=*(A+i);
if(result>tmp)
{
result=tmp;
}
}
printf("\nMin element of array = %d",result);}
13
#include <stdio.h>
//программа которыая вставляет символ после кождой буквы
int main()
{
char w ='W';
char A[256];
printf("Vvedite text\n ");
scanf("%s",A);
char *pA;
pA=A;
char t;
for(int i = 0; i<strlen(A);i++)
{
printf("%c%c",*(pA+i),w);
}
}

14
#include<stdio.h>
//функция подсчитываюзая количество символов в тексте
int strlength(const char A[256])
{
char *pA;
pA = A;
int counter =0;
while(*pA != '\0')
{
if(*pA == ' '){counter--;}
counter++;
pA++;
}
return counter;
}
int main()
{
char A[256];
gets(A);
int result=strlength(A);
printf("%d",result);
}

15
#include<stdio.h>
#include<string.h>
//функция сравнивающая две строки по коду
int fusdas(const char A[256],const char A1[256])
{
char *pA;
char *pA1;
pA = A;
pA1 = A1;
int tmp1 = 0;
int tmp2 = 0;
while(*pA != '\0')
{
tmp1 = *pA + tmp1;
*pA++;
}
while(*pA1 != '\0')
{
tmp2 = *pA1 + tmp2;
*pA1++;
}
int result= tmp1-tmp2;
return result;
}
int main ()
{
char A[256];
char A1[256];
gets(A);
printf("\n''''''''''''''''''''''''''''''''''''''''''''''''''\n");
gets(A1);
int i=fusdas(A,A1);
if (i<0)
{
printf("\n%s < %s\n",A,A1);
}
else if (i>0)
{
printf("\n%s > %s\n",A,A1);
}
else
{
printf("\n%s = %s\n",A,A1);
}

}
17
#include<stdio.h>
#include<string.h>
//программа превращающая маленькие буквы в польшие и наоборот
int main ()
{
char A[256];
printf("Vvedite text\n");
gets(A);
char *pA;
pA = A;
for(int i=0;i<strlen(A);i++)
{
*(pA+i)^=32;
printf("%c", *(pA+i));
}}
18
20
#include <stdio.h>
//программа, находящая символ с саммым большим кодом
// и символ с самым маленьким кодом
int main()
{ char A[256];
printf("Enter your text \n");
gets(A);
char * pA;
char * p1A;
pA = A;
p1A = A;
char tmp,result,tmp1,result1;
result1 = *p1A;
result = *pA;
while(*pA != '\0')
{tmp = *pA;
if (result<tmp)
{ result = tmp;
}
pA++;
}
while(*p1A != '\0')
{ tmp1 = *p1A;
if (result1>tmp1)
{ result1 = tmp1;
}
p1A++;
} printf("the symbol with the biggest code is \'%c\'\n",result);
printf("the symbol with the smallest code is \'%c\'\n",result1);
return 0;}
#include <stdio.h>
//программа, находящая самое большое четное число
int main()
{
int n,i,t,r;
printf("Quantity of numbers = ");
scanf("%d",&n);
int A[n];
printf("Enter your numbers = ");
for ( i = 0;i< n; i++)
{
scanf("%d",A+i);
}
printf("Your numbers = ");
for (i = 0;i< n; i++)
{
printf("%d ",*(A+i));
}
int * pA;
pA =A;
r = *pA;
for(i = 0;i<n;i++)
{
t = *(pA+i);
if (r<t && (t%2) == 0)
{
r=t;
}
}
printf("\nthe biggest even number is %d\n",r);
return 0;
}

#include <stdio.h>
//программа, находящая самое меленькое нечетное число
int main()
{ int n,i,t,r;
printf("Quantity of numbers = ");
scanf("%d",&n);
int A[n];
printf("Enter your numbers = ");
for ( i = 0;i< n; i++)
{ scanf("%d",A+i);
}
printf("Your numbers = ");
for (i = 0;i< n; i++)
{ printf("%d ",*(A+i));
}
int * pA;
pA =A;
r = *pA;
for(i = 0;i<n;i++)
{ t = *(pA+i);
if (r>t && (t%2) != 0)
{ r=t; }
}
printf("\nthe smallest uneven number is %d\n",r);
return 0;}

23
#include <stdio.h>
//программа, находящая первый символ с четным кодом
int main()
{
char A[256];
char result;
char *pA;
pA = A;
gets(pA);
for(int i = 0;i<strlen(pA);i++)
{
result=*(pA+i);
if((result%2)==0)
{
i=strlen(pA);
}
}
if ((result%2) != 0)
{
printf("The symbol with even code does not exist");
}
else
{
printf("the first symbol with even code is \'%c\'\n",result);
}}
19
#include <stdio.h>
//программа, превращающая строку чисел в число
int main()
{
char w = ' ';
char A[256];
char *pA;
pA = A;
printf("Enter the string of numbrs\n");
gets(pA);
printf("Your string of numbrs\n");
for(int i = 0; i<strlen(A);i++)
{
printf("%c%c",*(pA+i),w);
}
int result = 0;
for(int i = 0;i<strlen(pA);i++)
{
result = result*10 +(*(pA+i)-48);
}
printf("\nresult = %d\n",result);
printf("square of result = %d",result*result);}
#include <stdio.h>
//программа, находящая последний символ с нечетным кодом
int main()
{
char A[256];
char result;
char *pA;
pA = A;
gets(pA);
int i=strlen(pA);
for(;i>0;i--)
{
result=*(pA+i);
if((result%2)!=0)
{
i=0;
}
}
if ((result%2) == 0)
{
printf("The symbol with uneven code does not exist");
}
else
{
printf("the last symbol with uneven code is \'%c\'\n",result);
}}
#include <stdio.h>
//программа, находящая, что больше четных или не четных чисел в массиве
int main()
{
int n,i,even=0,uneven=0,t;
printf("Enter lenght of array of numbers \n");
scanf("%d",&n);
int A[n];
int *pA;
pA = A;
printf("Enter numbers in array \n");
for (i=0;i<n;i++)
{
scanf("%d",pA+i);
}
for (i=0;i<n;i++)
{
t=*(pA+i);
if((t%2)==0)
{
even++;
} else
{
uneven++;
}
}
printf("even = %d \nuneven = %d",even, uneven);
if(even>uneven){printf("\neven > uneven\n");}
else if(even<uneven){printf("\neven < uneven\n");}
else {printf("\neven = uneven\n");}
}
#include <stdio.h>
//программа, проверяющая делится ли числа из массива на 6
// или не делятся ли они на 11
int main()
{
int n,i,t,div6=0,ndiv11=0;
printf("Enter lenght of array of numbers \n");
scanf("%d",&n);
int A[n];
int *pA;
pA = A;
printf("Enter numbers in array \n");
for (i=0;i<n;i++)
{
scanf("%d",pA+i);
}
for (i=0;i<n;i++)
{
t=*(pA+i);
if((t%6)==0)
{
div6++;
}
if((t%11)!=0)
{
ndiv11++;
}

}
printf("Quantity of numbers dividing on 6 is %d\n",div6);
printf("Quantity of numbers not dividing on 11 is %d\n",ndiv11);
}
#include <stdio.h>
//функция копирующая, одну строку в другую ьез использования strcpy(A,B);
char * stringcopy(char A[256],const char B[256])
{
char *pA,*pB;
pA=A;
pB=B;
while(*pA!='\0')
{
*pA=*pB;
pA++;
pB++;
}
return pA;
}

int main()
{
char A[256];
char B[256];
printf("vvedi posledovatelnost A \n");
gets(A);
printf("vvedi posledovatelnost B \n");
gets(B);
stringcopy(A,B);

printf("\n%s",A);

}
#include <stdio.h>//***** (надо повторить)
//функция копирующая, код символов в другой массив
int * stringcopy(int B[256],const char A[256])
{
char *pA;
int *pB;
pA=A;
pB=B;
while(*pA!='\0')
{
*pB=*pA;
pA++;
pB++;
}
return pB;
}

int main()
{
char A[256];
int B[256] ;
int *ppB = B;
printf("vvedi posledovatelnost A \n");
gets(A);
printf("\n");
stringcopy(B,A);
while(*ppB !='\0')
{
printf("%d ",*ppB);
++ppB;
}
}
#include <stdio.h>//******** (надо проверить у учителя)
//программа меняющая местами четные индексы и нечетные индексы массива символов

int main()
{
char t;
char A[256];
char i = 0;
char *pA;
pA=A;
printf("vvedi posledovatelnost A \n");
gets(pA);

printf("\n");
while(*pA !=strlen(pA))
{
if(i%2==0){
t=*(pA+i);
*(pA+i)=*(pA+(i+1));
*(pA+(i+1))=t;}
i++;
}
printf("New posledovatelnost : %s \n", A);
}

#include <stdio.h>//******** (надо проверить у учителя)


//программа меняющая местами четные индексы и нечетные индексы массива чисел

int main()
{
int t,n;
printf("Enter size of array \n");
scanf("%d",&n);
int A[256];
int i;
int *pA;
pA=A;
printf("vvedi posledovatelnost A \n");
for (i=0;i<n;i++)
{
scanf("%d",pA+i);
}

printf("\n");
for(i=0;i<n;i= i+2)
{
t=*(pA+i);
*(pA+i)=*(pA+(i+1));
*(pA+(i+1))=t;

}
printf("new posledovatelnost \n");
for(i=0;i<n;i++)
{
printf("%d ",*(pA+i));
}
}
КЛАССЫ
1
#include<iostream>
using namespace std;
//класс треугольников
class TRIANGLE
{
private:
double a,b,c;
public:
TRIANGLE(double a, double b, double c)
{
this->a=a;
this->b=b;
this->c=c;
}
void outputen()
{
cout<<"Storona a ="<<a<<endl;
cout<<"Storona b ="<<b<<endl;
cout<<"Storona c ="<<c<<endl;
}
void proverka()
{
if (a==b && a==c && b == c )
{
cout<<"Treugilnik ravnostoriniy"<<endl<<endl;
}
else if(a==b||a==c|| b == c)
{
cout<<"Treugillnik ravnobedreniy"<<endl<<endl;
}
else
{
cout<<"Treugillnik proizvilniy"<<endl<<endl;
}
}
void SetStoriny()
{
cout<<"Vvedi storinu a"<<endl;
cin>>a;
cout<<"Vvedi storinu b"<<endl;
cin>>b;
cout<<"Vvedi storinu c"<<endl;
cin>>c;
}

TRIANGLE (const TRIANGLE &other)


{
this->a = other.a;
this->b = other.b;
this->c = other.c;
}
~TRIANGLE ()
{
cout<<"konec programmi"<<endl;
}
};

int main()
{

TRIANGLE *obj1= new TRIANGLE(0,0,0);


TRIANGLE *pobj1 = obj1;
pobj1->SetStoriny();
cout<< "\nORIGINAL\n";
pobj1->outputen();
pobj1->proverka();
TRIANGLE *obj2 = new TRIANGLE(*obj1);
TRIANGLE &pobj2 = *obj2;
cout<< "\nCOPIIA\n";
pobj2.outputen();
pobj2.proverka();}
3
//класс RECTANGLE

#include<iostream>
#include <math.h>
using namespace std;
//класс RECTANGLE
class RECTANGLE
{
private:
double a,b;
public:
RECTANGLE(double a,double b)
{
this->a = a;
this->b = b;
}
void vvod()
{
cout <<"vvedite storonu preamougolnika \'a\' " <<endl;
cin>>a;
cout <<"vvedite storonu preamougolnika \'b\' " <<endl;
cin>>b;
}

void vivod()
{
cout <<"storona preamougolnika \'a\' =" <<a<<endl;
cout <<"storona preamougolnika \'b\' =" <<b<<endl;
}

RECTANGLE(const RECTANGLE &other)


{
this-> a = other.a;
this-> b = other.b;
}
void Ploshadi_Preamougolnika()
{
double tmp;
tmp = a*b;
cout<<"ploshad\' Preamougolnika = " <<tmp<<endl;
}
void Dlina_Diagolali()
{
double tmp;
tmp = sqrt(a*a+b*b);
cout<<"Dlina diagonali Preamougolnika = " <<tmp<<endl;

void Ploshadi_Treugolnika_iz_Preamougolnika()
{
double c,tmp,p,DEL_b;
DEL_b = b/2;
c = sqrt(pow(a,2)+pow(DEL_b,2));
p = (a + DEL_b + c)/2;
tmp = sqrt(p * (p - a) * (p - DEL_b) * (p - c));
cout<<"Ploshad\' Treugolnika iz Preamougolnika = "<<tmp<<endl;
//cout<<"storona \'a\' Treugolnika iz Preamougolnika = "<<a<<endl;
//cout<<"storona \'b\' Treugolnika iz Preamougolnika = "<<DEL_b<<endl;
//cout<<"storona \'c\' Treugolnika iz Preamougolnika = "<<c<<endl;
//cout<<"p = "<<p<<endl;

~RECTANGLE()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
RECTANGLE *obj1 = new RECTANGLE(0,0);
RECTANGLE *Pobj1 = obj1;
Pobj1->vvod();
cout<<"ORIGINAL "<<endl;
Pobj1->vivod();
Pobj1->Ploshadi_Preamougolnika();
Pobj1->Dlina_Diagolali();
Pobj1->Ploshadi_Treugolnika_iz_Preamougolnika();
RECTANGLE *obj2 = new RECTANGLE(*obj1);
RECTANGLE &Sobj2 = *obj2;
Sobj2.vvod();
cout<<"COPIA "<<endl;
Sobj2.vivod();
Sobj2.Ploshadi_Preamougolnika();
Sobj2.Dlina_Diagolali();
Sobj2.Ploshadi_Treugolnika_iz_Preamougolnika();}
4
// класс Quadrilateral

#include<iostream>
#include <math.h>
using namespace std;
//класс Quadrilateral
class Quadrilateral
{
private:
double a,b,c,d;
public:
Quadrilateral(double a, double b, double c, double d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
}
void vvod()
{
cout << "Vvedi storonu \'a\'" << endl;
cin>>a;
cout << "Vvedi storonu \'b\'" << endl;
cin>>b;
cout << "Vvedi storonu \'c\'" << endl;
cin>>c;
cout << "Vvedi storonu \'d\'" << endl;
cin>>d;
}
void vivod()
{
cout<<"Storona \'a\' = "<<a<<endl;
cout<<"Storona \'b\' = "<<a<<endl;
cout<<"Storona \'c\' = "<<a<<endl;
cout<<"Storona \'d\' = "<<a<<endl;
}
Quadrilateral (const Quadrilateral &other)
{
this->a = other.a;
this->b = other.b;
this->c = other.c;
this->d = other.d;
}
void proverka()
{
if(a == b && b == c && c == d)
{
cout<<"eto qwadrat"<<endl;
}
else if(a == c && b == d)
{
cout<<"eto premougolnik"<<endl;
}
else
{
cout<<"SHO ZA TRASH"<<endl;
}
}
~Quadrilateral()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
Quadrilateral *ob1 = new Quadrilateral(0,0,0,0);
Quadrilateral *Pob1 = ob1;
cout<<"ORIGINAL"<<endl;
Pob1->vvod();
Pob1->vivod();
Pob1->proverka();
Quadrilateral *ob2 = new Quadrilateral(*ob1);
Quadrilateral &Sob2 = * ob2;
cout<<"COPIA"<<endl;
Sob2.vvod();
Sob2.vivod();
Sob2.proverka();}
7
//класс Circumference

#include<iostream>
#include <math.h>
using namespace std;
//класс Circumference
class Circumference
{
private:
double x,y,r;
public:
void vvod()
{
cout << "Vvedite coordinatu \'x\'" << endl;
cin>>x;
cout << "Vvedite coordinatu \'y\'" << endl;
cin>>y;
cout << "Vvedite radius okrujnosti \'y\'" << endl;
cin>>r;

}
Circumference(double x, double y, double r)
{
this->x = x;
this->y = y;
this->r = r;

}
void vivod()
{
cout<<"Center okrusnosti ( "<<x<<", "<<y<<")"<<endl;
cout<<"Radius okrujnosti = "<<r<<endl;
}
Circumference (const Circumference &other)
{
this->x = other.x;
this->y = other.y;
this->r = other.r;
}
void tochka_na_okrujnosti(double t_x,double t_y)
{
double tmp;
tmp = sqrt((t_x - x) * (t_x - x) + (t_y - y) * (t_y - y));
if (tmp<r)
{
cout<<"Tochka prinadlejit okrujnosti"<<endl;
}
else
{
cout<<"Tochka ne prinadlejit okrujnosti"<<endl;
}

}
~Circumference()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
int a,b;
Circumference *ob1 = new Circumference(0,0,0);
Circumference *Pob1 = ob1;
cout<<"ORIGINAL"<<endl;
Pob1->vvod();
Pob1->vivod();
cout<< "Vvedite coordinaty drugoi tochki "<<endl;
cout<<"x = \n";
cin>>a;
cout<<"y = \n";
cin>>b;
Pob1->tochka_na_okrujnosti(a,b);
Circumference *ob2 = new Circumference(*ob1);
Circumference &Sob2 = * ob2;
cout<<"COPIA"<<endl;
Sob2.vvod();
Sob2.vivod();
Sob2.tochka_na_okrujnosti(a,b);}
8
9
//класс Calendardate
//если вы это читаете то значит я забыл переделать эту программу
//пожалуйста переделайте эту программу за меня )
#include<iostream>
#include <math.h>
using namespace std;
//класс Calendardate
class Calendardate
{
private:
double dd,yy,mm;
public:
void vvod()
{
cout << "Vvedite den\'" << endl;
cin>>dd;
cout << "Vvedite meseaz\'" << endl;
cin>>mm;
cout << "Vvedite GOD\'" << endl;
cin>>yy;

}
Calendardate(double dd, double yy, double mm)
{
this->dd = dd;
this->yy = yy;
this->mm = mm;

}
void vivod()
{ if (dd<=0||dd>=31||mm>=12||mm<=0)
{
cout<<"Data nekorektna, zapustite programmu zanovo ";
}
else
{
cout<<"Vasha data : "<<(dd<10?"0":"")<<dd<<"."<<(mm<10?"0":"")<<mm<<"."<<(yy<0?-
yy:yy)<<endl;
}

}
Calendardate (const Calendardate &other)
{
this->dd = other.dd;
this->yy = other.yy;
this->mm = other.mm;
}
void VremeaGODa()
{
if(mm == 12||mm == 1|| mm == 2)
{
cout<<"Vremea goda : Zima"<<endl;
}
else if(mm == 3||mm == 4|| mm == 5)
{
cout<<"Vremea goda : Vesna"<<endl;
}
else if(mm == 6||mm == 7|| mm == 8)
{
cout<<"Vremea goda : Leto"<<endl;
}
else if (mm == 9|| mm == 10|| mm == 11)
{
cout<<"Vremea goda : Oseni"<<endl;
}
else
{
cout << "...";
}
}
~Calendardate()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Calendardate *ob1 = new Calendardate(0,0,0);
Calendardate * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Pob1->VremeaGODa();
cout<<"copia\n";
Calendardate *ob2 = new Calendardate(*ob1);
Calendardate &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
Sob1.VremeaGODa();

8
9
//класс Calendardate, вычисляющий следующую дату
//(программа некоректна, она не учитывает месяцы с 28-и и днями)

#include <iostream>
#include <math.h>
using namespace std;
//класс Calendardate
class Calendardate
{
private:
int dd,yy,mm;
public:
void vvod()
{
cout << "Vvedite den\'" << endl;
cin>>dd;
cout << "Vvedite meseaz" << endl;
cin>>mm;
cout << "Vvedite GOD" << endl;
cin>>yy;

}
Calendardate(double dd, double yy, double mm)
{
this->dd = dd;
this->yy = yy;
this->mm = mm;

}
void vivod()
{
int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
if (dd<0||dd>days[mm-1]||mm>12||mm<0)
{
cout<<"Data nekorektna, zapustite programmu zanovo \n";
}
else
{
cout<<"Vasha data : "<<(dd<10?"0":"")<<dd<<"."<<(mm<10?"0":"")<<mm<<"."<<(yy<0?-
yy:yy)<<endl;
}

}
Calendardate (const Calendardate &other)
{
this->dd = other.dd;
this->yy = other.yy;
this->mm = other.mm;
}
void SledData()
{
int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};

if (dd<0 ||dd>days[mm-1]||mm>12||mm<0)
{
cout<<" ";
}
else
{

if(dd+1 >days[mm-1])
{
if (mm+1>12)
{

cout<<"Sleduiushaia Data : "<<"01."<<"01."<<yy+1<<endl;

}
else
{
cout<<"Sleduiushaia Data : "<<"01"<<"."<<mm+1<<"."<<yy<<endl;
}
}
else
{
cout<<"Sleduiushaia Data : "<<dd+1<<"."<<mm<<"."<<yy<<endl;
}
}
}
~Calendardate()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Calendardate *ob1 = new Calendardate(0,0,0);
Calendardate * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Pob1->SledData();
cout<<"copia\n";
Calendardate *ob2 = new Calendardate(*ob1);
Calendardate &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
Sob1.SledData();

}
10
11
//класс Vector, с вычитанием векторов

#include <iostream>
#include <math.h>
using namespace std;
//класс Vector
class Vector
{
private:
double v1,v2,v3;
public:
void vvod()
{
cout << "Vvedite coordinatu po x :" << endl;
cin>>v1;
cout << "Vvedite coordinatu po y :" << endl;
cin>>v2;
cout << "Vvedite coordinatu po z :" << endl;
cin>>v3;

}
Vector(double v1, double v2, double v3)
{
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;

}
void vivod()
{
cout<<"U nas est\' vektor s coordinatami : V("<<v1<<","<<v2<<","<<v3<<")"<<endl;

}
Vector (const Vector &other)
{
this->v1 = other.v1;
this->v2 = other.v2;
this->v3 = other.v3;
}
void Vychitanie_Vectorov(double vect1, double vect2, double vect3)
{
double tmp;
tmp = v1 - vect1;
cout<<"Raznost\' vektorov = ( "<<tmp<<",";
tmp = v2 - vect2;
cout<<tmp<<",";
tmp = v3 - vect3;
cout<<tmp<<")"<<endl;
}
~Vector()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Vector *ob1 = new Vector(0,0,0);
Vector * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();

double a,b,c;
cout <<"Vvedite 3 coordinaty drugogo vektora dlea vichitania :"<<endl;
cin>>a;
cin>>b;
cin>>c;
Pob1->Vychitanie_Vectorov(a,b,c);
cout<<"copia\n";
Vector *ob2 = new Vector(*ob1);
Vector &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
Sob1.Vychitanie_Vectorov(a,b,c);

10
11
//класс Vector, с умножением на скалярную величину

#include <iostream>
#include <math.h>
using namespace std;
//класс Vector
class Vector
{
private:
double v1,v2,v3;
public:
void vvod()
{
cout << "Vvedite coordinatu po x :" << endl;
cin>>v1;
cout << "Vvedite coordinatu po y :" << endl;
cin>>v2;
cout << "Vvedite coordinatu po z :" << endl;
cin>>v3;

}
Vector(double v1, double v2, double v3)
{
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;

}
void vivod()
{
cout<<"U nas est\' vektor s coordinatami : V("<<v1<<","<<v2<<","<<v3<<")"<<endl;

}
Vector (const Vector &other)
{
this->v1 = other.v1;
this->v2 = other.v2;
this->v3 = other.v3;
}
void Proizvedenie_so_skalearom(double x)
{
double tmp;
tmp = v1 * x;
cout<<"Proizvedenie so skalearom = ("<<tmp<<",";
tmp = v2 * x;
cout<<tmp<<",";
tmp = v3 * x;
cout<<tmp<<")"<<endl;
}
~Vector()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Vector *ob1 = new Vector(0,0,0);
Vector * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();

double a;
cout <<"Vvedite skalearnuiu velichinu :"<<endl;
cin>>a;
Pob1->Proizvedenie_so_skalearom(a);
cout<<"copia\n";
Vector *ob2 = new Vector(*ob1);
Vector &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
Sob1.Proizvedenie_so_skalearom(a);
}

//класс Vector, с остатком от деления на число

#include <iostream>
#include <math.h>
using namespace std;
//класс Vector
class Vector
{
private:
int v1,v2,v3;
public:
void vvod()
{
cout << "Vvedite coordinatu po x :" << endl;
cin>>v1;
cout << "Vvedite coordinatu po y :" << endl;
cin>>v2;
cout << "Vvedite coordinatu po z :" << endl;
cin>>v3;

}
Vector(int v1, int v2, int v3)
{
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;
}
void vivod()
{
cout<<"U nas est\' vektor s coordinatami : V("<<v1<<","<<v2<<","<<v3<<")"<<endl;

}
Vector (const Vector &other)
{
this->v1 = other.v1;
this->v2 = other.v2;
this->v3 = other.v3;
}
void Delenie_vektora_na_chislo(int x)
{
double tmp;
tmp = (((double)v1 / (double)x)*10) - ((v1 /x)*10);
cout<<"Ostatok Posle deleniia = ("<<tmp<<",";
tmp = (((double)v2 / (double)x)*10) - ((v2 /x)*10);
cout<<tmp<<",";
tmp = (((double)v3 / (double)x)*10) - ((v3 /x)*10);
cout<<tmp<<")"<<endl;
}
~Vector()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Vector *ob1 = new Vector(0,0,0);
Vector * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();

int a;
cout <<"Vvedite chislo dlea delenia :"<<endl;
cin>>a;
Pob1->Delenie_vektora_na_chislo(a);
cout<<"copia\n";
Vector *ob2 = new Vector(*ob1);
Vector &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
Sob1.Delenie_vektora_na_chislo(a);
}

//класс Vector, с перегрузкой оператора '+'

#include <iostream>
#include <math.h>
using namespace std;
//класс Vector
class Vector
{
private:
double v1,v2,v3;
public:
void vvod()
{
cout << "Vvedite coordinatu po x :" << endl;
cin>>v1;
cout << "Vvedite coordinatu po y :" << endl;
cin>>v2;
cout << "Vvedite coordinatu po z :" << endl;
cin>>v3;

}
Vector()
{
v1 = 0;
v2 = 0;
v3 = 0;

}
Vector(double v1, double v2, double v3)
{
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;

}
void vivod()
{
cout<<"vektor s coordinatami : V("<<v1<<","<<v2<<","<<v3<<")"<<endl;

}
Vector (const Vector &other)
{
this->v1 = other.v1;
this->v2 = other.v2;
this->v3 = other.v3;
}
Vector operator+(Vector &other);

~Vector()
{
cout<<"Konez programmy"<<endl;
}

};

Vector Vector::operator+(Vector &other)


{
Vector tmp;
tmp.v1 = v1 + other.v1;
tmp.v2 = v2 + other.v2;
tmp.v3 = v3 + other.v3;
return tmp;
}

int main() and


{
cout<<"original\n";
Vector *ob1 = new Vector(0,0,0);
Vector * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
cout<<"copia\n";
Vector *ob2 = new Vector(*ob1);
Vector &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
cout<<"poluchaem iz summi vectorov\n";
Vector obj3 = *Pob1 + Sob1;
obj3.vivod();

//класс Vector, с перегрузкой оператора '*' для умножения на скаляр

#include <iostream>
#include <math.h>
using namespace std;
//класс Vector
class Vector
{
private:
double v1,v2,v3;
public:
void vvod()
{
cout << "Vvedite coordinatu po x :" << endl;
cin>>v1;
cout << "Vvedite coordinatu po y :" << endl;
cin>>v2;
cout << "Vvedite coordinatu po z :" << endl;
cin>>v3;
}
Vector()
{
v1 = 0;
v2 = 0;
v3 = 0;

}
Vector(double v1, double v2, double v3)
{
this->v1 = v1;
this->v2 = v2;
this->v3 = v3;

}
void vivod()
{
cout<<"vektor s coordinatami : V("<<v1<<","<<v2<<","<<v3<<")"<<endl;

}
Vector (const Vector &other)
{
this->v1 = other.v1;
this->v2 = other.v2;
this->v3 = other.v3;
}
Vector operator*(int);

~Vector()
{
cout<<"Konez programmy"<<endl;
}

};
Vector Vector::operator*(int x)
{
Vector tmp;
tmp.v1 = v1 * x;
tmp.v2 = v2 * x;
tmp.v3 = v3 * x;
return tmp;
}

int main()
{
cout<<"original\n";
Vector *ob1 = new Vector(0,0,0);
Vector * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
cout<<"copia\n";
Vector *ob2 = new Vector(*ob1);
Vector &Sob1 = *ob2;
Sob1.vvod();
Sob1.vivod();
cout<<"Vedite scalearnuiu velichinu"<<endl;
int scalear;
cin>>scalear;
cout<<"poluchaem iz proizvedenia na scalear\n";
Vector obj3 = *Pob1 * scalear;
obj3.vivod();}

//класс Calendardate с пергрузкой оператора '<'


//(программа некоректна, она не учитывает месяцы с 28-и и днями)

#include <iostream>
#include <math.h>
using namespace std;
//класс Calendardate
class Calendardate
{
private:
int dd,yy,mm;
public:
void vvod()
{
cout << "Vvedite den\'" << endl;
cin>>dd;
cout << "Vvedite meseaz" << endl;
cin>>mm;
cout << "Vvedite GOD" << endl;
cin>>yy;

}
Calendardate(double dd, double yy, double mm)
{
this->dd = dd;
this->yy = yy;
this->mm = mm;

}
void vivod()

{
int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
if (dd<0||dd>days[mm-1]||mm>12||mm<0)
{
cout<<"Data nekorektna, zapustite programmu zanovo ";
}
else
{
cout<<(dd<10?"0":"")<<dd<<"."<<(mm<10?"0":"")<<mm<<"."<<(yy<0?-yy:yy);
}

}
Calendardate (const Calendardate &other)
{
this->dd = other.dd;
this->yy = other.yy;
this->mm = other.mm;
}

bool operator<(Calendardate &other);


~Calendardate()
{
cout<<"Konez programmy"<<endl;
}

};

bool Calendardate::operator<(Calendardate &other)


{
int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
if (dd<0||dd>days[mm-1]||mm>12||mm<0)
{
cout<<"\n";
}
else
{
if (yy == other.yy)
{
if(mm == other.mm)
{
return (dd < other.dd);
}
else
{
return (mm < other.mm);
}
}
else
{
return (yy < other.yy);
}
}
}

int main()
{
cout<<"original\n";
Calendardate *ob1 = new Calendardate(0,0,0);
Calendardate * Pob1 = ob1;
Pob1->vvod();
cout<<"Vasha pervaia data : ";
Pob1->vivod();
cout<<"\ncopia\n";
Calendardate *ob2 = new Calendardate(*ob1);
Calendardate &Sob2 = *ob2;
Sob2.vvod();
cout<<"Vasha vtoraia data : ";
Sob2.vivod();
cout<<endl;
Pob1->vivod();
cout<<" < ";
Sob2.vivod();
cout<<" ? : ";
if (*Pob1 < Sob2)
{
cout<<"TRUE"<<endl;
}
else
{
cout<<"FALSE"<<endl;
}

//класс Calendardate с пергрузкой оператора '!='


//(программа некоректна)

#include <iostream>
#include <math.h>
using namespace std;
//класс Calendardate
class Calendardate
{
private:
int dd,yy,mm;
public:
void vvod()
{
cout << "Vvedite den\'" << endl;
cin>>dd;
cout << "Vvedite meseaz" << endl;
cin>>mm;
cout << "Vvedite GOD" << endl;
cin>>yy;

}
Calendardate(double dd, double yy, double mm)
{
this->dd = dd;
this->yy = yy;
this->mm = mm;

}
void vivod()

{
int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
if (dd<0||dd>days[mm-1]||mm>12||mm<0)
{
cout<<"Data nekorektna, zapustite programmu zanovo ";
}
else
{
cout<<(dd<10?"0":"")<<dd<<"."<<(mm<10?"0":"")<<mm<<"."<<(yy<0?-yy:yy);
}

}
Calendardate (const Calendardate &other)
{
this->dd = other.dd;
this->yy = other.yy;
this->mm = other.mm;
}

bool operator!=(Calendardate &other);


~Calendardate()
{
cout<<"Konez programmy"<<endl;
}

};

bool Calendardate::operator!=(Calendardate &other)


{
if(dd != other.dd || mm != other.mm || yy != other.yy)
{
return true;
}
else
{
return false;
}
}

int main()
{
cout<<"original\n";
Calendardate *ob1 = new Calendardate(0,0,0);
Calendardate * Pob1 = ob1;
Pob1->vvod();
cout<<"Vasha pervaia data : ";
Pob1->vivod();
cout<<"\ncopia\n";
Calendardate *ob2 = new Calendardate(*ob1);
Calendardate &Sob2 = *ob2;
Sob2.vvod();
cout<<"Vasha vtoraia data : ";
Sob2.vivod();
cout<<endl;
Pob1->vivod();
cout<<" != ";
Sob2.vivod();
cout<<" ? : ";
if (*Pob1 != Sob2)
{
cout<<"TRUE"<<endl;
}
else
{
cout<<"FALSE"<<endl;
}

//КЛАСС Mychar со вставкой одной строки в другую

#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
//класс MyChar
class Mychar
{
private:
char A[50];
public:
Mychar()
{
cout<<"raboteam";
}
void vvod()
{

cout<<"Vvedite posledovatel\'nost\' simvolov po poreadku:";


gets(A);
}
Mychar(char ar[])
{
for(int i=0;i<50;i++)
{
A[i]=ar[i];
}

}
void vivod()
{
cout <<"Nasha stroka :";
for(int i=0;i<strlen(A);i++)
{
cout << A[i]<<" ";
}
cout <<"\n";
}
Mychar (const Mychar &other)
{
for(int i=0;i<50;i++)
{
A[i]=other.A[i];
}
}

void Vstavka_Odnoi_posledov_v_druguiu(Mychar &other)


{
for(int i = 0;i<50;i++)
{
A[i] = other.A[i];
}
cout<<"\nPosle vstavki poluchaem : ";
for(int i = 0;i<50;i++)
{
cout<<A[i]<<" ";
}
cout<<"\n";
}

~Mychar()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Mychar *ob1 = new Mychar ();
Mychar * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Mychar *ob2 = new Mychar(*ob1);
Mychar &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();

Pob1->Vstavka_Odnoi_posledov_v_druguiu(Sob2);
}

//КЛАСС Mychar со сравнением одной строки с другой


// советую тщательно проверить (эта программа может работать некоректно)

#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
//класс MyChar
class Mychar
{
private:
char A[50];
public:
Mychar()
{
cout<<"\nPrivet, eta programma sravnivaet dve stroki i viviodit samuiu bol\'shuiu \n";
}
void vvod()
{

cout<<"Vvedite posledovatel\'nost\' simvolov:";


gets(A);
}
Mychar(char ar[])
{
for(int i=0;i<50;i++)
{
A[i]=ar[i];
}

}
void vivod()
{
cout <<"Nasha stroka :";
for(int i=0;i<strlen(A);i++)
{
cout << A[i]<<" ";
}
cout <<"\n";
}
Mychar (const Mychar &other)
{
for(int i=0;i<50;i++)
{
A[i]=other.A[i];
}
}

void Sravnenie_dlin_strok(Mychar &other)


{

cout<<"\n samaia bolshaia stroka : ";


if(strlen(A)>strlen(other.A))
{
for(int i=0;i<strlen(A);i++)
{
cout << A[i]<<" ";
}
}
else
{
for(int i=0;i<strlen(other.A);i++)
{
cout << other.A[i]<<" ";
}

}
cout<<"\n";
}

~Mychar()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Mychar *ob1 = new Mychar ();
Mychar * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Mychar *ob2 = new Mychar(*ob1);
Mychar &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();

Pob1->Sravnenie_dlin_strok(Sob2);}
//КЛАСС Mychar с перегрузкой оператора '-'
// которая должен быть унарным по описанию брынзана,
// но я сделал её бинарной
// если что её можно передалать в унарную
// советую тщательно проверить (эта программа может работать некоректно)

#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
//класс MyChar
class Mychar
{
private:
char A[50];
public:
Mychar()
{
cout<<"\nPrivet, eta programma sravnivaet dve stroki i viviodit samuiu bol\'shuiu \n";
}
void vvod()
{

cout<<"Vvedite posledovatel\'nost\' simvolov:";


gets(A);
}
Mychar(char ar[])
{
for(int i=0;i<50;i++)
{
A[i]=ar[i];
}
}
void vivod()
{
cout <<"Nasha stroka :";
for(int i=0;i<strlen(A);i++)
{
cout << A[i]<<" ";
}
cout <<"\n";
}
Mychar (const Mychar &other)
{
for(int i=0;i<50;i++)
{
A[i]=other.A[i];
}
}

Mychar operator-( int x)


{
for(int i = 0; i<strlen(A);i++)
{
if((A[i] <= 90 && A[i] >= 65) || (A[i] <= 122 && A[i] >= 97)){}
else{
A[i]=A[i+1];

for (int j = i+1; j < strlen(A);j++)


{
A[j]=A[j+1];
}
if((A[i] <= 90 && A[i] >= 65) || (A[i] <= 122 && A[i] >= 97)){}
else{ i--;}
}
}
return A;
}

~Mychar()
{
cout<<"Konez programmy"<<endl;
}

};

int main()
{
cout<<"original\n";
Mychar *ob1 = new Mychar ();
Mychar * Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Mychar *ob2 = new Mychar(*ob1);
Mychar &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
cout<<"\nposle minusa dlea pervoi stroki\n";
Mychar result = *ob1 - 1;
result.vivod();
cout<<"\nposle minusa dlea vtoroi stroki\n";
Mychar result1 = Sob2 - 1;
result1.vivod();
}
//class Equilateraltriangle с перегрузкой оператора '!=' для площадей
#include<iostream>
#include<math.h>
using namespace std;
class Equilateraltriangle
{
private:
double storona;
public:
void vvod ()
{
cout<< "Vvedite storonu ravnostorennego treugolnika : ";
cin>>storona;

}
Equilateraltriangle()
{
storona = 0;
}
Equilateraltriangle(double Storona_treugolnika)
{
storona = Storona_treugolnika;
}
Equilateraltriangle( const Equilateraltriangle &other)
{
this->storona = other.storona;
}

void vivod()
{
cout <<"u nas est\' ravnostoronii treugolnik so storonoi :";
cout<<storona<<endl;
}
bool operator!=(Equilateraltriangle &other);

~Equilateraltriangle()
{
cout<<"konez programmy \n";
}

};

bool Equilateraltriangle::operator!=(Equilateraltriangle &other)


{
double s = (storona * storona * sqrt(3)) / 4;
double s_other = (other.storona * other.storona * sqrt(3)) / 4;
if (s != s_other)
{
return true;
}
else
{
return false;
}
}

int main()
{
Equilateraltriangle *ob1 = new Equilateraltriangle();
Equilateraltriangle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Equilateraltriangle *ob2 = new Equilateraltriangle(*ob1);
Equilateraltriangle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
if (*Pob1 != Sob2)
{
cout<<"TRUE (oni ne ravny)"<<endl;
}
else
{
cout<<"FALSE (oni ravny)"<<endl;
}

}
//class Equilateraltriangle с перегрузкой оператора '+'
#include<iostream>
#include<math.h>
using namespace std;
class Equilateraltriangle
{
private:
double storona;
public:
void vvod ()
{
cout<< "Vvedite storonu ravnostorennego treugolnika : ";
cin>>storona;

}
Equilateraltriangle()
{
storona = 0;
}
Equilateraltriangle(double Storona_treugolnika)
{
storona = Storona_treugolnika;
}
Equilateraltriangle( const Equilateraltriangle &other)
{
this->storona = other.storona;
}

void vivod()
{
cout <<"u nas est\' ravnostoronii treugolnik so storonoi :";
cout<<storona<<endl;
}
double operator+(Equilateraltriangle &other);

~Equilateraltriangle()
{
cout<<"konez programmy \n";
}

};

double Equilateraltriangle::operator+(Equilateraltriangle &other)


{
return storona + other.storona;
}

int main()
{
Equilateraltriangle *ob1 = new Equilateraltriangle();
Equilateraltriangle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Equilateraltriangle *ob2 = new Equilateraltriangle(*ob1);
Equilateraltriangle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Equilateraltriangle ob3 = *Pob1 + Sob2;
cout<<"v sluchae esli berzan imel vvidu slojenie kajdoiu storonu odnogo treugolnika s takoije storonoi
drugogo treugolnika";
cout<<" togda "<<endl;
ob3.vivod();
cout<<"v sluchae esli berzan imel vvidu slojenie vseh storon odnogo treugolnika so vsemi storonami
drugogo treugolnika";
cout << " togda otvet:"<<*Pob1 + Sob2<<endl;}
//class Rectangle с перегрузкой оператора '+' (сложение длин соответствующих сторон
прямоугольника)
#include<iostream>
#include<math.h>
using namespace std;
class Rectangle
{
private:
double storona_A;
double storona_B;
public:
void vvod ()
{
cout<< "Vvedite storonu 'A' preamougolnika : "<<endl;
cin>>storona_A;
cout<< "Vvedite storonu 'B' preamougolnika : "<<endl;
cin>>storona_B;

}
Rectangle()
{
storona_A = 0;
storona_B = 0;
}
Rectangle(double StoronaA,double StoronaB)
{
storona_A = StoronaA;
storona_B = StoronaB;
}
Rectangle( const Rectangle &other)
{
this->storona_A = other.storona_A;
this->storona_B = other.storona_B;
}

void vivod()
{
cout <<"u nas est\' preamougolnik so storonami : A = ";
cout<<storona_A<<", B = "<<storona_B<<endl;
}
Rectangle operator+(Rectangle &other);

~Rectangle()
{
cout<<"konez programmy \n";
}

};

Rectangle Rectangle::operator+(Rectangle &other)


{
Rectangle tmp;
tmp.storona_A = storona_A + other.storona_A;
tmp.storona_B = storona_B + other.storona_B;
return tmp;
}

int main()
{
cout<<"ORIGINAL"<<endl;
Rectangle *ob1 = new Rectangle();
Rectangle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
cout<<"COPIA"<<endl;
Rectangle *ob2 = new Rectangle(*ob1);
Rectangle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Rectangle ob3 = *Pob1 + Sob2;
cout<<"posle slojenia teper\' "<<endl;
ob3.vivod();}
//класс Circumference с перегрузкой оператора + (сложение числа с длиной радиуса)
// нет, я не знаю почему деструктор вызывается два раза( или знаю, но мне лень разбираться )

#include<iostream>
#include <math.h>
using namespace std;
//класс Circumference
class Circumference
{
private:
double x,y,r;
public:
void vvod()
{
cout << "Vvedite coordinatu \'x\'" << endl;
cin>>x;
cout << "Vvedite coordinatu \'y\'" << endl;
cin>>y;
cout << "Vvedite radius okrujnosti " << endl;
cin>>r;

}
Circumference()
{
x = 0;
y = 0;
r = 0;

}
Circumference(double x, double y, double r)
{
this->x = x;
this->y = y;
this->r = r;

}
void vivod()
{
cout<<"Center okrusnosti ( "<<x<<", "<<y<<")"<<endl;
cout<<"Radius okrujnosti = "<<r<<endl;

}
Circumference (const Circumference &other)
{
this->x = other.x;
this->y = other.y;
this->r = other.r;
}
Circumference operator+(double g);

~Circumference()
{
cout<<"Konez programmy"<<endl;
}

};
Circumference Circumference::operator+(double g)
{
Circumference tmp;

tmp.x = x ;
tmp.y = y ;
tmp.r = r + g;
return tmp;
}

int main()
{
Circumference *ob1 = new Circumference();
Circumference *Pob1 = ob1;
cout<<"ORIGINAL"<<endl;
Pob1->vvod();
Pob1->vivod();
Circumference *ob2 = new Circumference(*ob1);
Circumference &Sob2 = * ob2;
cout<<"COPIA"<<endl;
Sob2.vvod();
Sob2.vivod();
int g;
cout << "Vvedite chislo dlea slojenia" << endl;
cin >> g;
Circumference obj3 = *Pob1 + g;
cout<<"posle slojeniia pervoia okrujnost\' imeet "<<endl;
obj3.vivod();
Circumference obj4 = Sob2 + g;
cout<<"posle slojeniia vtoraia okrujnost\' imeet "<<endl;
obj4.vivod(); }
//class Rectangle с определением площади прямоугольника, площади и периметра вписанной
окружности
#include<iostream>
#include<math.h>
#define Pi 3.1415
using namespace std;
class Rectangle
{
private:
double storona_A;
double storona_B;
public:
void vvod ()
{
cout<< "Vvedite storonu 'A' preamougolnika : "<<endl;
cin>>storona_A;
cout<< "Vvedite storonu 'B' preamougolnika : "<<endl;
cin>>storona_B;

}
Rectangle()
{
storona_A = 0;
storona_B = 0;
}
Rectangle(double StoronaA,double StoronaB)
{
storona_A = StoronaA;
storona_B = StoronaB;
}
Rectangle( const Rectangle &other)
{
this->storona_A = other.storona_A;
this->storona_B = other.storona_B;
}

void vivod()
{
cout <<"u nas est\' preamougolnik so storonami : A = ";
cout<<storona_A<<", B = "<<storona_B<<endl;
}

void ploshad_preamougolnika()
{
double s = storona_A * storona_B;
cout<<" plosh\'ad\' nashego preamougolnika = ";
cout<< s<<endl;
}
void ploshad_i_perimetr_vpis_okrujnosti()
{
double radius = (sqrt(pow(storona_A,2)+pow(storona_B,2)))/2;
cout <<"\nradius vpisasoi okrujnosti = "<<radius;
double perimetr = 2*Pi*radius;
cout <<"\nperimetr vpisasoi okrujnosti = "<<perimetr;
double ploshad = Pi*pow(radius, 2);
cout <<"\nploshad vpisasoi okrujnosti = "<<ploshad;
}

~Rectangle()
{
cout<<"konez programmy \n";
}

};
int main()
{
cout<<"ORIGINAL"<<endl;
Rectangle *ob1 = new Rectangle();
Rectangle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Pob1->ploshad_preamougolnika();
Pob1->ploshad_i_perimetr_vpis_okrujnosti();
cout<<"\nCOPIA"<<endl;
Rectangle *ob2 = new Rectangle(*ob1);
Rectangle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Sob2.ploshad_preamougolnika();
Sob2.ploshad_i_perimetr_vpis_okrujnosti();
}

//class Angle с сумой углов в градусах в минутах и секундах


#include<iostream>
#include<math.h>
using namespace std;
class Angle
{
private:
int grad;
int minut;
int sec;
public:
void vvod ()
{
cout<< "Vvedite gradusi ugla : "<<endl;
cin>>grad;
cout<< "Vvedite minuty : "<<endl;
cin>>minut;
cout<< "Vvedite secundy : "<<endl;
cin>>sec;

}
Angle()
{
grad = 0;
minut = 0;
sec = 0;
}
Angle(int gradusi,int minuti,int secundi)
{
grad = gradusi;
minut = minuti;
sec = secundi;
}
Angle( const Angle &other)
{
this->grad = other.grad;
this->minut = other.minut;
this->sec = other.sec;
}

void vivod()
{
if ((minut >= 0 && minut < 60)&&(sec>=0 && sec<60))
{
cout <<"vi vveli : ";
cout<<grad<<" "<<minut<<"\' "<<sec<<"\" "<<endl;
}
else
{
cout<<"\nvi nepomonimaite chto takoe gradusi"<<endl;
}
}

void summa_uglov(Angle &other)


{
if ((minut >= 0 && minut < 60)&&(sec>=0 && sec<60)&&(other.minut >= 0 && other.minut <
60)&&(other.sec>=0 && other.sec<60))
{

int ressec = sec + other.sec;


int resmin = minut + other.minut;
int resgrad = grad+other.grad;
if ( ressec >=60)
{
resmin++;
ressec=ressec - 60;
}

if ( resmin >=60)
{
resgrad++;
resmin = resmin - 60;
}

if ( resgrad >180 )
{
cout<<"\nsumma ne vozmojna( ea tak skazal!!!!)\n";
}
cout<<resgrad<<"grad "<< resmin <<" minut "<<ressec<<" secund "<<endl;
}
else
{
cout<<"!!!";
}
}
~Angle()
{
cout<<"konez programmy \n";
}

};

int main()
{
cout<<"ORIGINAL"<<endl;
Angle *ob1 = new Angle();
Angle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
cout<<"\nCOPIA"<<endl;
Angle *ob2 = new Angle(*ob1);
Angle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Pob1->summa_uglov(Sob2);
}

//class isoscelestriAngle с вычислением площади равнобедренного прямоугольника


#include<iostream>
#include<math.h>
using namespace std;
class isoscelestriAngle
{
private:
double ab;
double c;
public:
void vvod ()
{
cout<< "Vvedite storonu a i b : "<<endl;
cin>>ab;

cout<< "Vvedite storonu c : "<<endl;


cin>>c;

}
isoscelestriAngle()
{
ab = 0;
c = 0;
}
isoscelestriAngle(double A_B,double C)
{
ab = A_B;
c = C;
}
isoscelestriAngle( const isoscelestriAngle &other)
{
this->ab = other.ab;
this->c = other.c;
}

void ploshad_rvnobedr_treugolnika()
{
if (((ab+ab)<c) || ((ab+c)<ab) )
{
cout<<"treugolnik NEVOZMOJEN!!!!!\n";
}
else
{
double ploshad_treugolnika = (c*sqrt((ab*ab) - ((c*c)/4)))/2;
cout<<"\n ploshad treugolnika : "<<ploshad_treugolnika<<endl;
}
}

void vivod()
{
if (((ab+ab)<c) || ((ab+c)<ab) )
{
cout<<"treugolnik NEVOZMOJEN!!!!!\n";
}
else
{
cout<<"u nas est\' treugolnik so storonami a = "<<ab<<",b = "<<ab<<",c = "<<c<<endl;
}
}

~isoscelestriAngle()
{
cout<<"konez programmy \n";
}

};

int main()
{
cout<<"ORIGINAL"<<endl;
isoscelestriAngle *ob1 = new isoscelestriAngle();
isoscelestriAngle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Pob1->ploshad_rvnobedr_treugolnika();
cout<<"\nCOPIA"<<endl;
isoscelestriAngle *ob2 = new isoscelestriAngle(*ob1);
isoscelestriAngle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Sob2.ploshad_rvnobedr_treugolnika();
}

//class triAngle с определением если треугольник прямоугольный


#include<iostream>
#include<math.h>
#define Pi 3.14159
using namespace std;
class triAngle
{
private:
double a;
double b;
double c;
public:
void vvod ()
{
cout<< "Vvedite storonu a : "<<endl;
cin>>a;
cout<< "Vvedite storonu b : "<<endl;
cin>>b;

cout<< "Vvedite storonu c : "<<endl;


cin>>c;

}
triAngle()
{
a = 0;
b = 0;
c = 0;
}
triAngle(double A,double B,double C)
{
a = A;
b = B;
c = C;
}
triAngle( const triAngle &other)
{
this->a = other.a;
this->b = other.b;
this->c = other.c;
}

void vivod()
{
if (((a+b)<c) || ((a+c)<b) || ((c+b)<a) )
{
cout<<"treugolnik NEVOZMOJEN!!!!!\n";
}
else
{
cout<<"u nas est\' treugolnik so storonami a = "<<a<<",b = "<<b<<",c = "<<c<<endl;
}
}

void proverka_na_ugol_90_gradusov()
{
double cosAlph = acos((pow(a,2.0) + pow(c,2.0) - pow(b,2.0)) / (2.0 * a * c))* 180.0/Pi;
double cosBeta = acos((pow(a,2.0) + pow(b,2.0) - pow(c,2.0)) / (2.0 * a * b))* 180.0/Pi;
double cosGama = acos((pow(b,2.0) + pow(c,2.0) - pow(a,2.0)) / (2.0 * c * b))* 180.0/Pi;

if (((int)cosAlph == 90) || ((int)cosBeta == 90) || ((int)cosGama == 90) )


{
cout << " treugolnik preamougolnii "<<endl;
}
else
{
cout << "... ";
}

~triAngle()
{
cout<<"konez programmy \n";
}

};

int main()
{
cout<<"ORIGINAL"<<endl;
triAngle *ob1 = new triAngle();
triAngle *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();
Pob1->proverka_na_ugol_90_gradusov();
cout<<"\nCOPIA"<<endl;
triAngle *ob2 = new triAngle(*ob1);
triAngle &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Sob2.proverka_na_ugol_90_gradusov();
}

//class Poly2 со сложением многочлена


#include<iostream>
#include<math.h>
using namespace std;
class Poly2
{
private:
double a;
double b;
double c;
public:
void vvod ()
{
cout<<"formula mnochlena : a*x^(2) + b * x + c "<<endl;
cout<< "Vvedite kooficient a : "<<endl;
cin>>a;
cout<< "Vvedite kooficient b : "<<endl;
cin>>b;

cout<< "Vvedite kooficient c : "<<endl;


cin>>c;

}
Poly2()
{
a = 0;
b = 0;
c = 0;
}
Poly2(double A,double B,double C)
{
a = A;
b = B;
c = C;
}
Poly2( const Poly2 &other)
{
this->a = other.a;
this->b = other.b;
this->c = other.c;
}

void vivod()
{

cout<<"u nas est\' mnogochlen = "<<a<<"*x^(2)"<<(b>=0?"+":" ")<<b<<"*x"<<(c>=0?"+":"


")<<c<<endl;
}
void slojenie_mnogochlenov(Poly2 &other)
{
Poly2 result;
result.a = a + other.a;
result.b = b + other.b;
result.c = c + other.c;
result.vivod();
}

~Poly2 ( )
{
cout<<"konez programmy \n";
}

};

int main()
{
cout<<"ORIGINAL"<<endl;
Poly2 *ob1 = new Poly2();
Poly2 *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();

cout<<"\nCOPIA"<<endl;
Poly2 *ob2 = new Poly2(*ob1);
Poly2 &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
cout <<"Posle slojenia teper\' "<<endl;
Pob1->slojenie_mnogochlenov( Sob2 );
}
//class Poly2 с умножением двух многочленов первой степени
// вероятнее всего эта программа работает не так как хочет берзан
#include<iostream>
#include<math.h>
using namespace std;
class Poly2
{
private:
double a;
double b;
double c;
public:
void vvod ()
{
cout<<"formula mnochlena : a*x^(2) + b * x + c "<<endl;
cout<< "Vvedite kooficient a : "<<endl;
cin>>a;
cout<< "Vvedite kooficient b : "<<endl;
cin>>b;

cout<< "Vvedite kooficient c : "<<endl;


cin>>c;

}
Poly2()
{
a = 0;
b = 0;
c = 0;
}
Poly2(double A,double B,double C)
{
a = A;
b = B;
c = C;
}
Poly2( const Poly2 &other)
{
this->a = other.a;
this->b = other.b;
this->c = other.c;
}

void vivod()
{

cout<<"u nas est\' mnogochlen = "<<a<<" * x^(2) "<<(b>=0?" + ":" ")<<b<<" * x"<<(c>=0?" + ":"
")<<c<<endl;

}
void umnojenie_dvuh_mnogochlenov_stepeni_1(Poly2 &other)
{
Poly2 result;
result.a = a;
result.b = b * other.b;
result.c = c ;
cout<<result.a<<" * x^(2) ";
cout<<(result.b > 0?" + ":" - ")<<result.b<<" * x^(2) ";
cout<<(result.c > 0?" + ":" - ") <<result.c<<endl;
}

~Poly2 ( )
{
cout<<"konez programmy \n";
}

};

int main()
{
cout<<"ORIGINAL"<<endl;
Poly2 *ob1 = new Poly2();
Poly2 *Pob1 = ob1;
Pob1->vvod();
Pob1->vivod();

cout<<"\nCOPIA"<<endl;
Poly2 *ob2 = new Poly2(*ob1);
Poly2 &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
cout <<"Posle umnojenia dvuh mnogochlenov stepeni 1 "<<endl;
Pob1->umnojenie_dvuh_mnogochlenov_stepeni_1( Sob2 );
}

6
// класс StraightLine с проверкой на паралельность с бисектрисой y=x
// + определение точек пересечения с осью YOX
// + проверка на паралельность с осью ординат( OY )
#include<iostream>
#include<math.h>
using namespace std;

class StraightLine
{
private:
double a;
double b;
double c;
public:
StraightLine ()
{
a = 0;
b = 0;
c = 0;
}
StraightLine ( double a,double b, double c )
{
this-> a = a;
this-> b = b;
this-> c = c;
}
void vvod()
{
cout<<" imeetsea uravnenie a * x + b * y + c = 0"<<endl;
cout<<"Vvedite costantu a"<<endl;
cin>>a;
cout<<"Vvedite costantu b"<<endl;
cin>>b;
cout<<"Vvedite costantu c"<<endl;
cin>>c;
}
void vivod()
{
if(a == 0 && b == 0 )
{
cout<< "uravnenie nevozmojno"<<endl;
}
else
{
cout<<"\n imeetsea sleduiushee uravnenie : ";
cout<< (a < 0? -a : a)<<" * x " ;
if(a < 0)
{
cout<<( b < 0? " + ":" - " )<<( b < 0? -b : b )<<" * y" ;
cout<<( c < 0? " + ":" - " )<<( c < 0? -c : c )<<" = 0 "<<endl ;
}
else
{
cout<<( b < 0? " ":" + " )<< b<<" * y ";
cout<<( c > 0? " + ":" " )<<c<<" = 0 "<<endl ;
}
}

}
void opredelenie_esli_preamaia_paralelna()
{
if ( (abs(a) == abs(b))&&(a != 0 && b != 0 ) )
{
cout<<" preamaia paralelna bisectrisse y = x "<<endl;
}
else
{
cout<<" preamaia NE paralelna bisectrisse y = x "<<endl;
}
}
void peresechenie_s_osiu_koordinat()
{
if(a == 0 && b == 0 )
{
cout<< " ";
}
else
{
if(a == 0)
{
cout <<" ";
}
else
{
double peresechenie_s_OX = -c/a;
cout<<" tochka peresechenia s osiu OX = ( "<<peresechenie_s_OX<<" , 0 )"<<endl;
}
if(b == 0)
{
cout <<" ";
}
else
{
double peresechenie_s_OY = -c/b;
cout<<" tochka peresechenia s osiu OY = ( 0 , "<<peresechenie_s_OY<<" )"<<endl;
}
}
}

void opredelenie_esli_preamaia_paralelna_ordinate()
{
if (b == 0 && a!=0)
{
cout<< "preamaia paralel\'na osi ordinat"<<endl;
}
else
{
cout<< "preamaia NE paralel\'na osi ordinat"<<endl;
}
}
};
int main ()
{
cout<<"ORIGINAL "<<endl;
StraightLine *ob1 = new StraightLine();
StraightLine *Pob1 = ob1;
Pob1 ->vvod();
Pob1 ->vivod();
Pob1 ->opredelenie_esli_preamaia_paralelna();
Pob1 ->peresechenie_s_osiu_koordinat();
Pob1 ->opredelenie_esli_preamaia_paralelna_ordinate();
cout<<"COPIA "<<endl;
StraightLine *ob2 = new StraightLine(*ob1);
StraightLine &Sob2 = *ob2;
Sob2.vvod();
Sob2.vivod();
Sob2.opredelenie_esli_preamaia_paralelna();
Sob2.peresechenie_s_osiu_koordinat();
Sob2.opredelenie_esli_preamaia_paralelna_ordinate();
}

Вам также может понравиться