Приложение а
Исходный код программы 1
1)Main.cpp
#include "my.h"
void main ()
{
clrscr();
float a,b,c,a2,b2,c2,proizved;
test();
input(&a,&b,&c,&a2,&b2,&c2);
calck(a,b,c,a2,b2,c2,&a,&b,&c);
output (a,b,c);
}
void input (float *pa, float *pb, float *pc,float *pa2, float *pb2, float *pc2)
{
printf ("\n vvedite koordinaty pervogo vectora\n");
int er1=scanf ("\n%f %f %f",pa,pb,pc);
printf ("\n vvedite koordinaty vtorogo vectora\n");
er1+=scanf ("\n%f %f %f",pa2,pb2,pc2);
if (er1!=6)
{
printf ("input error1");
if (!getch())
getch();
exit(1);
}
}
void output (float x,float y,float z)
{
printf ("%f, %f, %f",x,y,z);
if (!getch())
getch();
}
2)Calc.cpp
#include <stdio.h>
#include <conio.h>
void calck (float ax, float ay, float az,float bx, float by, float bz, float *pa, float *pb, float *pc)
{
*pa=ay*bz-az*by;
*pb=az*bx-ax*bz;
*pc=ax*by-ay*bx;
}
3)Test.cpp
#include "my.h"
void test ()
{
float ax=1, ay=-2,az=1,bx=2,by=0,bz=-3;
calck(ax,ay,az,bx,by,bz,&ax,&ay,&az);
if ((ax!=6)||(ay!=5)||(az!=4))
{
printf ("Proizoshla oshibka\n Nomer oshibki #504\n Obratites' k razrabotchiku");
exit(1);
}
printf ("Programma zavershila samotestirovanie bez oshibok\n");
}
Приложение б
Исходный код программы 2.
1)Main.cpp
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
unsigned int input ();
unsigned long calc(unsigned int n);
void test();
void test()
{
unsigned long number=0;
unsigned int n=123;
number=calc(n);
if (number!=321)
{
printf ("error calc");
if (!getch())
getch();
exit(1);
}
}
void main()
{
test();
clrscr();
unsigned int n=0;
unsigned long number;
number = 0;
n=input();
number=calc(n);
printf("number = %lu\n", number);
if (!getch())
getch();
}
unsigned int input ()
{
unsigned long b;
b=0;
int flag=1,err=0;
while (flag==1)
{
clrscr();
printf ("vvedite chislo ot 0 do 65535\n");
err=scanf ("%lu",&b);
if (err!=1)
{
printf ("error1 vy vvely ne chislo");
if (!getch())
getch();
exit(1);
}
if ((b<0)||(b>65535))
{
printf ("vvedeno slishkom bolshoe chislo");
if (!getch())
getch();
}
else flag=0;
}
// n=(int)n;
return b;
}
unsigned long calc (unsigned int n)
{
unsigned long number=0;
while ( n !=0)
{
number *= 10;
number += n % 10;
n = n / 10;
}
return number;
}
Приложение в
Исходный код программы 4.
1)Main.cpp
#include "my.h"
void main ()
{
test();
clrscr();
int *A;
int n;
float gm,ar;
A=input(&n);
gm=geom(A,n);
ar=arif (A,n);
output(A,n);
outputp (gm,ar);
perestanov (A,n);
output (A,n);
if (!getch())
getch();
free (A);
}
int* input (int *pn)
{
printf ("\nvvedite kol-vo elementov massiva\n");
scanf ("%d",pn);
int *A;
A=(int*)malloc((*pn)*sizeof(int));
printf ("vvedite element massiva na otrezke [-32768;32767]\n");
int res=0;
for (int i=0;i<*pn;i++)
{
res=scanf("%d",&(A[i]));
if (res!=1)
{
output(1);
}
if ((A[i]>32767)||(A[i]<-32768))
output (3);
}
//realloc(A,sizeof(int));
return (int*)A;
}
void output (int A[],int pn)
{
printf("elementy massiva\n");
for (int i=0; i<pn;i++)
printf("%d\n",A[i]);
//printf("geom=%d\n",gm);
}
void outputp (float gm,float ar)
{
printf("geom=%.2f\n",gm);
printf("geom=%.2f\n",ar);
}
void output (int flag)
{
printf ("error #%d",flag);
if (!getch())
getch();
exit (1);
}
2)Calc.cpp
#include "my.h"
//float geom (int A[],int n);
float geom (int A[],int n)
{
if ((n<1)||(n>32767))
{
output(2);
}
float s=0;
for (int i=0;i<n;i++)
s+=A[i];
s/=2;
return s;
}
//float arif (int A[],int n);
float arif (int A[],int n)
{
if ((n<1)||(n>32767))
{
output(2);
}
float s=0;
for (int i=0;i<n;i++)
s+=A[i];
s/=n;
return s;
}
void perestanov (int A[],int n)
{
if ((n<1)||(n>32767))
{
output(2);
}
int buf;
buf=n%2;
if (buf=1) n--;
for (int i=0;i<n;i+=2)
{
buf=A[i];
A[i]=A[i+1];
A[i+1]=buf;
}
}
3) Test.cpp
#include "my.h"
void test ()
{
int A[3]={1,2,3};
float result;
result=geom(A,3);
result=fabs(result-3.00000);
//printf ("\n%f\n",result);
if (result>(0.000001))
output (4);
result=0;
result=arif(A,3);
//printf ("%f\n",result);
if (fabs(result-2.0)>(0.000001))
output (5);
perestanov(A,3);
if ((A[0]!=2)&&(A[1]!=1)&&(A[2]!=3))
output(6);
printf ("Programma uspeshno zavershila samotestirovanie");
}