|
Сперва прога просит ввести интервал. Далее вывоти плоды своей работы:
- первый столбик –номер эксперимента
- второй столбук - значение финкйии
- третий столбик значение которое получается «напрямую»
- четвёртый столбик - значение которое получается вычислением с помощью рядов
- пятый столбик – машинный ноль
- шестой столбик - количество итераций которое было необходимо для вычисления производной функции до машинного нуля.
Лабороторная работа №2
Задание: написать программу которая просит ввести строку, нарезает эту строку на подстроки и выводит их в обратном порядке.
Текст программы.
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
class stroka
{
char *ch;
int len;
friend int operator == (stroka & a , stroka & b);
friend stroka* Friend0(stroka c);
friend istream& operator >>(istream & in, stroka & a );
friend ostream& operator <<(ostream & out, stroka & a );
public :
stroka(int N=80)
{ch = new char [N];
ch[0]='\0';
}
stroka (const char *s)
{
int j=0;
while (ch[j++]);
ch = new char[len];
ch[len] = '\0';
len--;
for (int i=0;i<len;i++)
ch[i]= s[i];
}
void string1(void)
{ int j=0;
while (ch[j++]);
len = j-1;
}
~stroka (){delete [] ch ;}
} ;
void main()
{ stroka s0,*s1;
cin >> s0;
s0.string1();
cout <<"\n"<<*Friend0(s0);
}
stroka* Friend0(stroka c)
{
stroka *GodDame_Mother_F_1;
stroka *GodDame_Mother_F_2;
stroka *GodDame_Mother_F_;
GodDame_Mother_F_1 = new stroka[c.len];
GodDame_Mother_F_2 = new stroka[c.len];
GodDame_Mother_F_ = new stroka[c.len];
int i=0,j=0,k=-1,h=0,g=0,f=0;
for(i=0;i<=c.len;i++){
if(((c.ch[i]==' '||c.ch[i]=='.')&&((c.ch[i+1]!=' ')||(c.ch[i-1]!=' ')))){
//cout<<c.ch[i]<<"\tI won!!!";
k++;
//j=0;
g=0;
for(k;k<i;k++){
if(c.ch[k]!=' '){
//cout<<c.ch[k];
GodDame_Mother_F_1[0].ch[j++]=c.ch[k];
GodDame_Mother_F_2[0].ch[g++]=c.ch[k];
}
}
h++;
//for(f=0;f<g;f++)cout<<GodDame_Mother_F_2[0].ch[f];
//cout<<'\n';
int s,s1;
for(int d=i;d<c.len;d++){
s1=0;
for(f=0;f<g;f++){
s=0;
if(GodDame_Mother_F_2[0].ch[f]!=c.ch[d+f]){
//cout<<"I won!!!!!";
s=1;
}
if(s!=0){s1=1;}
}
if(s1==0&&GodDame_Mother_F_2[0].ch[f+1]==' '){
cout<<"I won!!!!!";
for(int a=0;a<g;a++)cout<<GodDame_Mother_F_2[0].ch[a];
}
}
}
}
return GodDame_Mother_F_;
}
int operator == (stroka & a,stroka & b)
{ int k=0;
a.string1();
b.string1();
if (a.len!=b.len) k--;
else
for (int i=0;i<a.len;i++)
if (a.ch[i]!=b.ch[i]) {k--;break;}
return k;
}
istream &operator >>(istream &in,stroka & A)
{ cout <<"\n\tInput string : ";
in.getline(A.ch,80,'\n');
return in;
}
ostream &operator <<(ostream &out,stroka & A)
{ out << A.ch;
return out;
}
Результат работы.
Input string : demon13
13 mon de
Лабораторная работа №3
Написать программу с наследованием классов и виртуальными функциями.
Текст программы.
#include <iostream.h>
class complex
{ public :
double x,y;
virtual void fun (int x=0, int y=0)=0;
};
class What_the_hell_we_got: public complex
{ public :
void fun (int x, int y)
{cout<<"\n What_the_hell_we_got "<< x<<"\t"<<y;}
};
class Plusssssss: public complex
{ public :
void fun (int x=0, int y=0)
{cout<<"\n Plusssssss\tx+y ="<< x+y;}
};
class Umnojinia : public What_the_hell_we_got
{public :
void fun (int x)
{cout<<"\n Umnojinia\tx*x ="<< x*x;}
};
class xz : public Plusssssss , public Umnojinia
{public :
void fun (int x)
{cout<<"\n Xzubla\t\tx^3 ="<< x*x*x;}
};
void main (void)
{ What_the_hell_we_got D, *pcom1 = &D;
Plusssssss C2, *pc2 = &C2;
int k,x;
cin>>x>>k;
pcom1 -> fun(k,x);
pc2 -> fun (k,x);
Umnojinia C3, *pc3 = & C3;
pc3 -> fun (x);
pcom1=pc3;
pcom1->fun(k,x);
xz C4, *pc4 = & C4;
pc4 -> fun (x);
}
Результаты работы
3
4
What_the_hell_we_got 4 3
Plusssssss x+y =7
Umnojinia x*x =9
What_the_hell_we_got 4 3
Xzubla x^3 =27
Вводим два числа и смотрим что получится при сложение умножении или возведение в третью степень.
При использовании материалов активная ссылка на источник обязательна.