29 de abril de 2009

Projeto I

Um rascunho do meu projeto, os Exercícios 4 e 5 versão 0.2:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

int main(void)
{
FILE *in;
int gdriver = DETECT, gmode, errorcode;
int i,j;
int sign;
int tons;
int num;
float x,y;
float DadosX[300],DadosY[300];
float maxY = 0;//,maxY = 0;
float YScale = 0;//,XScale = 0;
float faixa[17];
float soma = 0;
float yData = 0,Y = 0;
char tipo[40];
char *b;
clrscr();
if ((in = fopen("C:/tc/BIN/clown.pgm", "rt"))== NULL)
{
fprintf(stderr, "Cannot open input file.\n");
return 1;
}
//Ler cabecalho
fgets(tipo,40,in);
printf("%s",tipo);
fgets(tipo,35,in);
printf("%s",tipo);
//Ler numeros
fscanf(in,"%s",&tipo);
x = atof(tipo);
printf("%3.0f ",x);
fscanf(in,"%s",&tipo);
y = atof(tipo);
printf("%3.0f = %3.0f\n",y,x*y);
fscanf(in,"%s",&tipo);
tons = atoi(tipo);
//maxX = tons;
printf("%d\n",tons);

for(j = 0;j <= 16; j++){
faixa[j] = 0;
}//FOR

do{
fscanf(in,"%s",&tipo);
num = atoi(tipo);
if feof(in) break;
if((num >= 0 ) && (num <= 15)) faixa[0]++;
if((num >= 16 ) && (num <= 30)) faixa[1]++;
if((num >= 31 ) && (num <= 45)) faixa[2]++;
if((num >= 46 ) && (num <= 60)) faixa[3]++;
if((num >= 61 ) && (num <= 75)) faixa[4]++;
if((num >= 76 ) && (num <= 90)) faixa[5]++;
if((num >= 91 ) && (num <= 105)) faixa[6]++;
if((num >= 106 ) && (num <= 120)) faixa[7]++;
if((num >= 121 ) && (num <= 135)) faixa[8]++;
if((num >= 136 ) && (num <= 150)) faixa[9]++;
if((num >= 151 ) && (num <= 165)) faixa[10]++;
if((num >= 166 ) && (num <= 180)) faixa[11]++;
if((num >= 181 ) && (num <= 195)) faixa[12]++;
if((num >= 196 ) && (num <= 210)) faixa[13]++;
if((num >= 211 ) && (num <= 225)) faixa[14]++;
if((num >= 226 ) && (num <= 240)) faixa[15]++;
if((num >= 241 ) && (num <= 255)) faixa[16]++;

}while (!feof(in));

printf("\t");

for(j = 0;j <= 16; j++){
if(faixa[j] > maxY ) maxY = faixa[j];
printf("Faixa: %d = %3.0f \t",j+1,faixa[j]);
if(j % 2 == 0) printf("\n\t");
soma = soma + faixa[j];
}//FOR

printf("\nSoma: %3.0f\n",soma);
printf("Maximo em X: %3.0f\n",maxY);
YScale = (400-40)/maxY;
printf("YScale: %f\n",YScale);
getch();
fclose(in);

// inicializar modo grafico
initgraph(&gdriver, &gmode, "C:\\tc\\bgi");
// read result of initialization
errorcode = graphresult();
if (errorcode != grOk) // an error occurred
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); // return with error code
}

//Inicializando grafico
//Linhas
line(40,40-15,40,400);
line(40,400,565,400);
//Setas
line(40-5,40-15,40+5,40-15);
line(40-5,40-15,40,40-15-15);
line(40,40-15-15,40+5,40-15);

line(565,400-5,565,400+5);
line(565,400-5,565+15,400);
line(565+15,400,565,400+5);

j = 15;
for(i = 0;i <= 16; i++){
//Linhas Pequenas
setcolor(7);
line(40+j+7,maxY*YScale+40,40+j+7,maxY*YScale+40+3);
//Numeros legenda
settextstyle(2, 0,4);
gcvt(i+1,sign,b);
outtextxy(40+j+1,maxY*YScale+40+3,b);

settextstyle(2, 0,4);
yData = faixa[i];
if(faixa[i]==0){
setcolor(7);
settextstyle(2, 0,4);
outtextxy(40+j+5,maxY*YScale+40-15,"0");
}else{
//Defindo Y
Y = (maxY*YScale)-((yData - maxY*YScale+40) * (YScale));
//Plotando no grafico
setcolor(i);
if((i == 0)||(i == 7)) setcolor(9);
if((i == 15))setcolor(4);
if((i == 16))setcolor(2);
rectangle(40+j,Y+40-1,40+j+15,maxY*YScale+40);
//Numeros
gcvt(faixa[i],sign,b);
outtextxy(40+j-5,Y+40-15,b);
}//ELSE
j = j + 30;

}//FOR

getch();
closegraph();
return 0;
}

Programação II

Atividades quarta, 29 abril 2009:

1 - Crie uma classe Retângulo. A classe tem atributos altura e largura, onde cada um tem o valor padrão 1. Ela tem métodos que calculam o perímetro e a área do retângulo. Ela tem métodos get/set para altura e largura. Os métodos set devem garantir que altura e largura são números de ponto flutuante maiores que 0.0 e menores que 20.0. Escreva um programa para testar a classe Retângulo.

Baixar Possível Resolução

Para baixar o JCreator clique aqui.