w3 2


q:\PK\PK_C\WW3_2\ww_3.cpp 1
////////////////////////////////////////////////////////////////////////////////
// file ww_3.cpp
// KOLO
#include "windows.h"
#include
#include
#include
//---------------directives of preprocessor--------------------------------//
//Such a manner is possible, but the way, presented below, is better
#define MY_PI 3.14159265358979323846 //explain define action !!!
#define MY_DOUBLE double
//it is a more preferable way, but during study...
//typedef double MY_DOUBLE;
//const double PI = 3.14159265358979323846;
//---------- function prototypes -----------------------------------------//
void kolo(double *S, double *L, double r);
int main()
{
MY_DOUBLE r = 0.0, area = 0.0, circuit = 0.0;
MY_DOUBLE *ptr1 = NULL;
//input radius
printf("PROGRAM WW3_2: POLE I OBWOD KOLA\n==============================\n\n");
printf("podaj promien r\n");
int ret = scanf("%le", &r);
if(ret <= 0)
{
printf("input data error\n");
exit(1);
}
ptr1 = &area;
//Wydruk wartosci i adresow
printf("\nstan zmiennych do wywolania funkcji kolo()\n");
printf("id\t\t adres\t\t\t wartosc\t\t stan zmiennej\n");
printf("r\t\t %x\t\t %lf\n", &r, r);
printf("area\t\t %x\t\t %lf\n", &area, area);
printf("circit\t\t %x\t\t %lf\n", &circuit, circuit);
printf("ptr1\t\t %x\t\t %x\t\t %lf\n", &ptr1, ptr1, *ptr1);
printf("\n");
//call kolo to compute area, circit
kolo(ptr1, &circuit, r);
//Wydruk wartosci i adresow
printf("\nStan zmiennych po wywolaniu funkcji kolo()\n");
printf("id\t\t adres\t\t\t wartosc\t\t stan zmiennej\n");
printf("r\t\t %x\t\t %lf\n", &r, r);
printf("area\t\t %x\t\t %lf\n", &area, area);
printf("circit\t\t %x\t\t %lf\n", &circuit, circuit);
printf("ptr1\t\t %x\t\t %x\t\t %lf\n", &ptr1, ptr1, *ptr1);
printf("\n");
//hide thread to see display
int ch;
while((ch = getchar()) != EOF)
;
return 0;
}
void kolo(double *S, double *L, double r)
/*======================================================================================
Evaluates: area of circle - S
circuit - L
q:\PK\PK_C\WW3_2\ww_3.cpp 2
IN: radius r
OUT: S - area of circle
L - circuit (2*PI*r)
=======================================================================================*
/
{
*L = 2.0*MY_PI*r;
*S = MY_PI*r*r;
printf("\njestem w funkcji kolo()\n");
printf("Uwaga! adres r jest zmieniony - kopia w steku\n");
printf("id\t\t adres\t\t\t wartosc\t\t stan zmiennej\n");
printf("r\t\t %x\t\t %lf\n", &r, r);
printf("S\t\t %x\t\t %x\t\t %lf\n", &S, S, *S);
printf("L\t\t %x\t\t %x\t\t %lf\n", &L, L, *L);
printf("\n");
}
#undef MY_PI
#undef MY_DOUBLE


Wyszukiwarka

Podobne podstrony:
pca w3
W3, Wiazania atomowe
informatyka II w3
nw asd w3
Optymalizacja w3 a pdf
DROGI w2 w3 tyczenie
Zsbd 2st 1 2 w3 tresc 1 1 kolor
w3 1
W3 Panstwo i polityka fiskalna
w3
w3 4 nowe pol srodki obrotu 14
W3 WYTYCZNE PROJEKTOWANIA RAM STALOWYCH ekran
W3 ?HAWIORALNA TERAPIA MALZENSTW
W3
R W3 przebieg
w3 nowe pol 10(1)
wmat w3
W3 spektrofotometria w podczerwieni

więcej podobnych podstron