2 лаба
5 вариант #include <stdio.h>
#include<iostream.h>
#include<math.h>
#include<string.h>
int inobl(float,float,float,float);
int nomerobl(float,float,float,float);
void vubor(int,char*);
void main(void)
{
float x;
float y;
float a;
float r;
char capital[10];
int nazv;
cout<<"Введите x, y, a, r -->";
cin>>x>>y>>a>>r;
cout<<x<<" "<<y<<" "<<a<<" "<<r<<endl;
if (inobl(x,y,a,r)) cout<<"Номер области: "<<nomerobl(x,y,a,r)<<endl;
else cout<<"Точка вне областей!"<<endl;
cout<<"Введите название месяца"<<endl
<<"(январь-1,февраль-2,март-3,апрель-4,май-5,июнь-6,июль-7,август-8,сентябрь-9,октябрь-10,ноябрь-11,декабрь-12)"<<endl;
cin>>nazv;
vubor(nazv,capital);
cout<<"Сезон года "<<nazv<<" - "<<capital<<endl;
getchar();
}
int inobl(float xf,float yf,float af,float rf)
{
return(((xf*xf+yf*yf<rf*rf)&&(yf<af*xf*xf)&&(xf<0))||((xf*xf+yf*yf>rf*rf)&&(yf>af*xf*xf)&&(xf>0)));
}
int nomerobl(float xf,float yf,float af,float rf)
{
int k;
if ((inobl(xf,yf,af,rf))&&(xf<0)&&(yf<0)) k=0;
if ((inobl(xf,yf,af,rf))&&(xf<0)&&(yf>0)) k=1;
if ((inobl(xf,yf,af,rf))&&(xf>0)&&(yf>0)) k=2;
switch (k)
{
case 0:return(1);
case 1:return(2);
case 2:return(3);
}
}
void vubor(int n,char *ss)
{
switch (n)
{
case 1,2,12: strcpy(ss,"зима");break;
case 3,4,5: strcpy(ss,"весна"); break;
case 6,7,8: strcpy(ss,"лето"); break;
case 9,10,11: strcpy(ss,"осень"); break;
}
}
Добавлено (2006-11-07, 0:16 Am)
---------------------------------------------
3 лаба
7 вариант
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
void draw_window(int x1,int y1,int x2,int y2,int backc,int textc,char header[]);
void error(char s[]);
double f11(double n);
double f12(double n);
double f13(double n);
double f21(double eps1,double m,double q);
double f22(double eps1,double m,double q);
double f23(double eps1,double m,double q);
void main(void)
{ textbackground(BLACK); clrscr();
draw_window(1,1,80,4,GREEN,BLACK,"Zadacha");
cout << "написать программу нахождения наименьшего элемента из серии i*i*i*sin(n+i/n)";
cout << "При заданном m найти решение уравнения Кеплера, принимая за него такое xn, при котором abs|xn-xn-1|<e";
draw_window(40,7,75,20,GREEN,BLACK,"Output");
draw_window(1,7,35,20,GREEN,BLACK,"Input");
cout << "Type n>0) =>";
double n; cin >> n;
if (n<=0) error("Wrong n");
draw_window(40,7,75,20,GREEN,BLACK,"Output");
gotoxy(1,1); cout << "Choose function: " << endl;
gotoxy(1,2); cout << "1-while; 2-while do; 3-for =>";
char t;
cin >> t;
switch (t)
{ case '1': draw_window(40,7,75,20,GREEN,BLACK,"Output");
cout << "F=" << f11(n) << endl; break;
case '2': draw_window(40,7,75,20,GREEN,BLACK,"Output");
cout << "F=" << f12(n) << endl; break;
case '3': draw_window(40,7,75,20,GREEN,BLACK,"Output");
cout << "F=" << f13(n) << endl; break;
default: error("Wrong key");
}
draw_window(1,11,35,20,GREEN,BLACK,"");
gotoxy(1,2); cout << "Type m =>";
double m; cin >> m;
gotoxy(1,3); cout << "Type 0<q<1 =>";
double q; cin >> q;
gotoxy(1,4); cout << "Type eps =>";
double eps1; cin >> eps1;
if ((eps1<=0) || (eps1>=1)) error("Wrong eps");
draw_window(40,11,75,20,GREEN,BLACK,"");
gotoxy(1,1); cout << "Choose function: " << endl;
gotoxy(1,2); cout << "1-while; 2-while do; 3-for =>"; cin >> t;
switch (t)
{ case '1': draw_window(40,11,75,20,GREEN,BLACK,"");
cout << "F2=" << f21(eps1,m,q) << endl; break;
case '2': draw_window(40,11,75,20,GREEN,BLACK,"");
cout << "F2=" << f22(eps1,m,q) << endl; break;
case '3': draw_window(40,11,75,20,GREEN,BLACK,"");
cout << "F2=" << f23(eps1,m,q) << endl; break;
default: error("Wrong key");
}
getchar();
}
void draw_window(int x1,int y1,int x2,int y2,int backc,int textc,char header[])
{ window(x1,y1,x2,y2);
textbackground(backc); textcolor(WHITE); clrscr();
cout << header << endl;
window(x1,y1+1,x2,y2);
textcolor(textc); clrscr();
gotoxy(1,1);
}
void error(char s[])
{ draw_window(10,15,29,19,RED,BLACK,"ERROR!");
cout << s;
getchar();
exit(1);
}
double f11(double n)
{ double i=1; double a,ai,ai1=0;
while (i<=n)
{ ai=ai1;
ai1=i*i*i*sin(n+i/n);
i++;
if (ai1<=ai) a=ai1;
}
return a;
}
double f12(double n)
{ double i=1; double a,ai,ai1=0;
do { ai=ai1;
ai1=i*i*i*sin(n+i/n);
i++;
if (ai1<=ai)
{a=ai1;}
}
while (i!=n+1);
return a;
}
double f13(double n)
{ double i; double a,ai,ai1=0;
for (i=1;i<=n;i++)
{ ai=ai1;
ai1=i*i*i*sin(n+i/n);
if (ai1<=ai)
{a=ai1;}
}
return a;
}
double f21(double eps1,double m,double q)
{ double xi,xi1;
xi=m;
while (fabs(xi-xi1)>eps1)
{ xi1=xi;
xi=m+q*sin(xi1);
}
return xi;
}
double f22(double eps1,double m,double q)
{ double xi,xi1;
xi=m;
do {xi1=xi;
xi=m+q*sin(xi1);
}
while (fabs(xi-xi1)>eps1);
return xi;
}
double f23(double eps1,double m,double q)
{ double xi,xi1,i;
xi=m;
for(;!(fabs(xi-xi1)<eps1);i++)
{ xi1=xi;
xi=m+q*sin(xi1);
}
return xi;
}