Задание: Объединить все лабораторные работы в один файл.
Решение:
Блок-схема алгоритма
Начало |
Конец |
fmenu() |
Текст программы
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <locale>
#include <math.h>
#include <ctime>
#include <iomanip>
#include <locale.h>
#include <conio.h>
using namespace std;
void lab1()
{setlocale(0,"");
system("cls");
double a,b,c,x,y;
a=5.7;
b=6.4;
c=3.1;
cout<<"Vvedi x: ";
cin>>x;
y=((sqrt(exp(a*x)+x*x)*log(x*x+b*x+10))/(sin(c*x)+4.2));
cout<<"Dlja x= "<<x<<"Znachenie y= "<<y<<"\n";
system("pause");
system("cls");
}
void lab21()
{setlocale(0,"");
system("cls");
double a,b,x,y;
a=4.6;
b=3.2;
cout<<"Vvedi x: ";
cin>>x;
if(x>+2)
y=sqrt(1+x*sqrt(a*x));
else
y=sin(b*x)+3;
cout<<"Esli x= "<<x<<",togda y= "<<y<<"\n";
system("pause");
system("cls");
}
void lab22()
{setlocale(0,"");
system("cls");
double a=1.8,b=3.3,x,y;
cout<<"Vvedi x: ";
cin>>x;
if(x<=3) y=pow((a*x+1),4);
else if(x>5) y=a*cos((b+x)*(b*x));
else y=1/(2*(x*x)+b*log(x));
cout<<"Esli x= "<<x<<"\n Togda y="<<y<<"\n";
system("pause");
system("cls");
}
void lab23()
{long double a=1.8,b=3.3,y;
int x;
cout<<"Vvedi x= ";
cin>>x;
switch(x)
{case 3:
y=pow((a*(float)x+1),4);
cout<<"Esli x= "<<x<<"\n Togda y="<<y<<endl;
break;
case 4:
y=1/(2*(float)x*(float)x+b*log((float)x));
cout<<"Esli x= "<<x<<"\n Togda y= "<<y<<endl;
break;
case 6:
y=a*cos(pow(b+(float)x,2));
cout<<"Esli x= "<<x<<"\n Togda y= "<<y<<endl;
break;
default:
cout<<"Znachenie x vvedeno neverno\nNazhmite\"Enter\"\n";
}
system("pause");
system("cls");
}
void lab3()
{setlocale(0,"");
system("cls");
double a=4.3,b=5.4,x,y,xn,xk,dx;
int nn; bool n=true;
while(n)
{ cout<<"1-for\n2-while\n3-do while\n4-exit\n";
cin>>nn;
switch(nn)
{ case 1:
cout<<"Vvedi xn\nxn=";
|
cin>>xn;
cout<<"Vvedi xk\nxk= ";
cin>>xk;
cout<<"Vvedi dx\ndx= ";
cin>>dx;
for(x=xn;x<=xk;x=x+dx)
{ y=b*log(a*x*x)+b*(pow(log(x),2));
cout<<x<<" "<<y<<endl;
} system("pause");
break;
case 2:
cout<<"Vvedi xn\nxn= ";
cin>>xn;
cout<<"Vvedi xk\nxk= ";
cin>>xk;
cout<<"Vvedi dx\ndx= ";
cin>>dx;
x=xn;
while(x<=xk)
{ y=b*log(a*x*x)+b*(pow(log(x),2));
cout<<x<<" "<<y<<endl;
x=x+dx;
} system("pause");
break;
case 3:
cout<<"Vvedi xn\nxn= ";
cin>>xn;
cout<<"Vvedi xk\nxk;= ";
cin>>xk;
cout<<"Vvedi dx\ndx= ";
cin>>dx;
x=xn;
do{ y=b*log(a*x*x)+b*(pow(log(x),2));
cout<<x<<" "<<y<<endl;
x=x+dx;
}
while(x<=xk);
break;
case 4: n=false;
default:cout<<"Vvedi 1,2,3,4\n";
}
}
system("pause");
system("cls");
}
void lab4()
{setlocale(LC_ALL, "Russian");
int n;
cout<<"Введи размер массива:";
cin>>n;
int*a=new int[n];
cout<<"Исходный массив: ";
for(int i=0;i<n;i++)
{a[i]=rand()%27+1;
cout<<"a["<<i<<"]= "<<a[i]<<endl;
} cout<<endl;
cout<<"элементы массивабкоторые меньше их индекса:"<<endl;
for(int i=0;i<n;++i)
{if(a[i]<=1)
{cout<<"a["<<i<<"]= "<<a[i]<<endl;
}
}
cout<<endl;
delete[]a;
system("pause");
system("cls");
}
void lab5()
{int A [7] [3];
int i,j,B,C[7], S=0;
for (i=0; i<7; i++)
{ for (j=0; j<3; j++)
{ cout<<"vvedi A["<<i<<"]["<<j<<"]=";
cin>>A[i][j];
}
} cout<<"ishodnaya matrica"<<endl;
for (i=0; i<7; i++)
{ for(j=0; j<3; j++)
cout<<A[i][j]<<" ";
cout<<endl;
} cout<<"proizvedenie strok ishodnoy matricy"<<endl;
for(i=0; i<7; i++)
{ B=1;
for(j=0; j<3; j++)
B=B*A[i][j];
C[i]=B;
cout<<C[i]<<endl;
} for (i=0; i<7; i++)
S=S+C[i];
cout<<"summa proizvedeniy="<<S<<endl;
system("pause");
system("cls");
}
void lab6()
{float x,eps, F, S,N;
int mm,n;
bool m=true;
while (m)
{ cout << "Press 1 to continue "<<"\n"<<"Press 2 to exit"<<"\n";
|
cin >> mm;
F=1,n=1,N=1;
switch (mm)
{ case 1:
cout << "Input x= ";
cin >> x;
cout << "Input eps: ";
cin >> eps;
S = pow(x,n)/N;
while (fabs(S) > eps);
{ F=F+S;
n++;
N=N*n;
S =pow(x,n)/N;
}
cout <<"Esli x="<<x<<","<<"\t"<<"epsilon="<<eps<<"\n"<<"togda F="<<F<<endl;
system("pause");
system("cls");
break;
case 2:
m=false;
break;
default:
cout <<"error"<<endl;
}
}
system("pause");
system("cls");
}
void sam1()
{ setlocale(0," ");
float a,b,c;
double x;
int nn;
while(true)
{cout<<"30-выполнение программы;\n50-выход из программы\n";
cin>>nn;
switch(nn)
{case 30:
cout<<"Введи значение a:";cin>>a;
cout<<"Введи значение b:";cin>>b;
cout<<"Введи значение c:";cin>>c;
if(a==0)
{x=(c)/(b)*(-1);
cout<<"Корень равен"<<x<<endl;}
else
{if((b*b-4*a*c)>0)
{x=(-1*b+sqrt(b*b-4*a*c))/(2*a);
cout<<"Первый корень равен"<<x<<endl;
x=(-1*b-sqrt(b*b-4*a*c))/(2*a);
cout<<"Второй корень равен"<<x<<endl;
}
else if((b*b-4*a*c)==0)
{x=(-1*b+sqrt(b*b-4*a*c))/(2*a);
cout<<"Корень равен"<<x<<endl;}
else
cout<<"Дискриминант меньше 0,корни невещественные"<<endl;
}
break;
case 50: nn=false; break;
default:cout<<"Выбери 30,50\n";
}
}
system("pause");
system("cls");
}
void sam2()
{setlocale(0," ");
int n,f,x;
cout<<"Введи n\nn= ";
cin>>n;
f=1;
for(x=1;x<=n;x++)
f=f*x;
cout<<"факториал"<<n<<"="<<f<<endl;
system("pause");
system("cls");
}
void sam3()
{setlocale(LC_ALL, "Russian");
int n;
cout<<"Введи размер массива:";
cin>>n;
int*a=new int[n];
for(int i=0;i<n;i++)
{a[i]=rand()%50+1;
cout<<"a["<<i<<"]= "<<a[i]<<endl;
}
cout<<"Исходный массив: ";
for(int i=0;i<n;i++)
{cout<<a[i]<<" "<<endl;
} cout<<endl;
for(int i=1;i<n;i++)
{for(int r=0;r<n-i;r++)
{if(a[r]<a[r+1])
|
{int temp=a[r];
a[r]=a[r+1];
a[r+1]=temp;
}
}
}
cout<<"Отсортированный массив:";
for(int i=0;i<n;++i)
{cout<<a[i]<<" ";
}
cout<<endl;
delete[]a;
system("pause");
system("cls");
}
void fmenu()
{bool n=true;
while(n)
{cout<<"\t"<<"1-lab1"<<endl;
cout<<"\t"<<"21-lab21"<<endl;
cout<<"\t"<<"22-lab22"<<endl;
cout<<"\t"<<"23-lab23"<<endl;
cout<<"\t"<<"3-lab3"<<endl;
cout<<"\t"<<"4-lab4"<<endl;
cout<<"\t"<<"5-lab5"<<endl;
cout<<"\t"<<"6-lab6"<<endl;
cout<<"\t"<<"7-sam1"<<endl;
cout<<"\t"<<"8-sam2"<<endl;
cout<<"\t"<<"9-sam3"<<endl;
cout<<"\t"<<"555-exit"<<endl;
int nn;
cin>>nn;
switch(nn)
{case 1: lab1(); break;
case 21: lab21(); break;
case 22: lab22(); break;
case 23: lab23(); break;
case 3: lab3(); break;
case 4: lab4(); break;
case 5: lab5(); break;
case 6: lab6(); break;
case 7: sam1(); break;
case 8: sam2(); break;
case 9: sam3(); break;
case 555: n=false; break;
default: cout<<"error";
}
}
}
int main()
{system ("color E1");
int a;
fmenu();
system("pause");
system("cls");
return 0;
}
Результат