Malo objasnjenje funkcije...?

Malo objasnjenje funkcije...?

offline
  • Nexara 
  • Novi MyCity građanin
  • Pridružio: 12 Dec 2008
  • Poruke: 21

Rec je o temperaturnom grafiku. Da li neko moze da mi objasni barem jednu od navedenih funkcija?





/* Function definitions */
void get_temps(void)
{
char inbuf[130];
int reading;

printf("\nEnter temperatures, one at a time.\n");
for (reading = 0; reading < READINGS; reading++)
{
printf("\nEnter reading # %d: ", reading + 1);
gets(inbuf);
sscanf(inbuf, "%d", &temps[reading]);
}
}

void table_view(void)
{
int reading, min, max;

clrscr(); /* clear the screen */
printf("Reading\t\tTemperature(F)\n");

for (reading = 0; reading < READINGS; reading++)
printf("%d\t\t\t%d\n", reading + 1, temps[reading]);

min_max(READINGS, temps, &min, &max);
printf("Minimum temperature: %d\n", min);
printf("Maximum temperature: %d\n", max);
printf("Average temperature: %f\n", avg_temp(READINGS, temps));
}

void min_max(int num_vals, int vals[], int *min_val, int *max_val)
{
int reading;

*min_val = *max_val = vals[0];

for (reading = 1; reading < num_vals; reading++)
{
if (vals[reading] < *min_val)
*min_val = vals[reading];
else if (vals[reading] > *max_val)
*max_val = vals[reading];
}
}

float avg_temp(int num_vals, int vals[])
{
int reading, total = 0;

for (reading = 0; reading < num_vals; reading++)
total += vals[reading];

return (float) total/reading; /* reading equals total vals */
}

void graph_view(void)
{
int graphdriver = DETECT, graphmode;
int reading, value;
int maxx, maxy, left, top, right, bottom, width;
int base; /* zero x-axis for graph */
int vscale = 1.5; /* value to scale vertical bar size */
int space = 10; /* spacing between bars */

char fprint[20]; /* formatted text for sprintf */

initgraph(&graphdriver, &graphmode, "..\\bgi");
if (graphresult() < 0) /* make sure initialized OK */
return;

maxx = getmaxx(); /* farthest right you can go */
width = maxx /(READINGS + 1); /* scale and allow for spacing */
maxy = getmaxy() - 100; /* leave room for text */
left = 25;
right = width;
base = maxy / 2; /* allow for neg values below */

for (reading = 0; reading < READINGS; reading++)
{
value = temps[reading] * vscale;
if (value > 0)
{
top = base - value; /* toward top of screen */
bottom = base;
setfillstyle(HATCH_FILL, 1);
}
else
{
top = base;
bottom = base - value; /* toward bottom of screen */
setfillstyle(WIDE_DOT_FILL, 2);
}
bar(left, top, right, bottom);
left +=(width + space); /* space over for next bar */
right +=(width + space); /* right edge of next bar */
}

outtextxy(0, base, "0 -");
outtextxy(10, maxy + 20, "Plot of Temperature Readings");
for (reading = 0; reading < READINGS; reading++)
{
sprintf(fprint, "%d", temps[reading]);
outtextxy((reading *(width + space)) + 25, maxy + 40, fprint);
}

outtextxy(50, maxy+80, "Press any key to continue");

getch(); /* Wait for a key press */

closegraph();
}



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 396 korisnika na forumu :: 2 registrovanih, 1 sakriven i 393 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: nenooo, vlvl