|
art of bodybuilding
Katılma Tarihi: Eki 2006
Nereden: İstanbul
Mesajlar: 427
|
C++ analog saat bileşeni.
Horloge.h
#ifndef HorlogeH
#define HorlogeH
//---------------------------------------------------------- -----------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
//---------------------------------------------------------- -----------------
class PACKAGE THorloge : public TGraphicControl
{
private:
TTimer *Timer1;
Graphics::TBitmap *Image1;
bool FSec;
bool __fastcall CanResize(int &NewWidth, int &NewHeight);
protected:
void __fastcall Tempo(TObject* Owner);
void __fastcall Paint();
public:
__fastcall THorloge(TComponent* Owner);
virtual __fastcall ~THorloge();
__published:
__property Anchors;
__property ParentShowHint;
__property ShowHint;
__property Visible;
__property bool Seconde = {read=FSec, write=FSec, default=true};
};
//---------------------------------------------------------- -----------------
#endif
Horloge.cpp
#include <vcl.h>
#include <math.h> #pragma hdrstop
#include "Horloge.h"
#pragma package(smart_init)
//---------------------------------------------------------- -----------------
//
static inline void ValidCtrCheck(THorloge *)
{
new THorloge(NULL);
}
//---------------------------------------------------------- -----------------
__fastcall THorloge::THorloge(TComponent* Owner)
: TGraphicControl(Owner)
{
Controls tyle << csOpaque;
Image1 = new Graphics::TBitmap();
Timer1 = new TTimer(NULL);
Timer1->OnTimer = Tempo;
FSec=true;
Width = 120;
Height = 120;
Image1->Width = Width;
Image1->Height = Height;
}
//---------------------------------------------------------- -----------------
__fastcall THorloge::~THorloge()
{
delete Image1;
delete Timer1;
}
//---------------------------------------------------------- -----------------
bool __fastcall THorloge::CanResize(int &NewWidth, int &NewHeight)
{
NewWidth = 120;
NewHeight = 120;
return true;
}
//---------------------------------------------------------- -----------------
void __fastcall THorloge::Tempo(TObject* Sender)
{
Invalidate();
}
//---------------------------------------------------------- -----------------
void __fastcall THorloge: aint()
{
float n,z,u,x0,y0,x1,y1,x2,y2,x3,y3;
TDateTime heure;
TPoint points[4>;
Word wHour, wMinute, wSeconde;
heure = Now();
DecodeTime(heure, wHour, wMinute, wSeconde, NULL);
// Couleur de fond.
Image1->Canvas->Brush->Color = Color;
Image1->Canvas->Pen->Color = Color;
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1- >Height);
// Dessin du cercle.
Image1->Canvas->Pen->Color = clBlack;
Image1->Canvas->Pen->Width = 2;
Image1->Canvas->Ellipse(2,2,118,118);
// Dessin du texte.
Image1->Canvas->Font->Name = "Arial";
Image1->Canvas->Font->Color = clBlack;
Image1->Canvas->Font->Size = 8;
Image1->Canvas->TextOut( 50,80,"CGi");
Image1->Canvas->TextOut( 55,6,"12");
Image1->Canvas->TextOut( 58,101,"6");
Image1->Canvas->TextOut( 8,53,"9");
Image1->Canvas->TextOut( 105,53,"3");
Image1->Canvas->TextOut( 81,13,"1");
Image1->Canvas->TextOut( 97,30,"2");
Image1->Canvas->TextOut( 98,76,"4");
Image1->Canvas->TextOut( 81,94,"5");
Image1->Canvas->TextOut( 33,94,"7");
Image1->Canvas->TextOut( 15,76,"8");
Image1->Canvas->TextOut( 14,30,"10");
Image1->Canvas->TextOut( 32,13,"11");
Image1->Canvas->Pen->Width = 1;
// Dessin aiguille des secondes si FSec à true.
if (FSec)
{
n = wSeconde*200/60;
z = n/100*3.14159;
u = (n+50)/100*3.14159;
x0 = sin(z)*50;
y0 = -cos(z)*50;
x1 = -sin(z)*10;
y1 = cos(z)*10;
x2 = sin(u)*2;
y2 = -cos(u)*2;
x3 = -sin(u)*2;
y3 = cos(u)*2;
points[0> = Point(x1+60,y1+60);
points[1> = Point(x2+60,y2+60);
points[2> = Point(x0+60,y0+60);
points[3> = Point(x3+60,y3+60);
Image1->Canvas->Brush->Color = clRed;
Image1->Canvas->Polygon(points, 3);
}
// Dessin aiguille des minutes.
n = wMinute*200/60 + wSeconde*200/60/60;
z = n/100*3.14159;
u = (n+50)/100*3.14159;
x0 = sin(z)*50;
y0 = -cos(z)*50;
x1 = -sin(z)*10;
y1 = cos(z)*10;
x2 = sin(u)*4;
y2 = -cos(u)*4;
x3 = -sin(u)*4;
y3 = cos(u)*4;
points[0> = Point(x1+60,y1+60);
points[1> = Point(x2+60,y2+60);
points[2> = Point(x0+60,y0+60);
points[3> = Point(x3+60,y3+60);
Image1->Canvas->Brush->Color = clAqua;
Image1->Canvas->Polygon(points, 3);
// Dessin aiguille des heures.
n = wHour*200/12 + wMinute*200/60/12;
z = n/100*3.14159;
u = (n+50)/100*3.14159;
x0 = sin(z)*35;
y0 = -cos(z)*35;
x1 = -sin(z)*10;
y1 = cos(z)*10;
x2 = sin(u)*4;
y2 = -cos(u)*4;
x3 = -sin(u)*4;
y3 = cos(u)*4;
points[0> = Point(x1+60,y1+60);
points[1> = Point(x2+60,y2+60);
points[2> = Point(x0+60,y0+60);
points[3> = Point(x3+60,y3+60);
Image1->Canvas->Brush->Color = clYellow;
Image1->Canvas->Polygon(points, 3);
Canvas->Draw(0,0,Image1);
}
//---------------------------------------------------------- -----------------
namespace Horloge
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1> = {__classid(THorloge)};
RegisterComponents("Beyaz", classes, 0);
}
}
_______________________________________________
sayısal loto programı.
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
void goster();
int kolon[6>;
void main()
{
int n,deger,j,w,m;
do
{
printf("KAC KOLON OYNAMAK ISTERSINIZ?\n");
scanf("%d",&n);
if(n<=0)
printf("KOLON SAYISI 0 veya Daha Kucuk OLAMAZ\n");
}
while(n<=0);
srand(time(NULL));
for(int i=0;i<n;i++)
{
for(j=0;j<6;j++)
{
deger=rand()%49+1;
for(m=0;m<=j;m++);
if(kolon[m>==deger)
deger=rand()%49+1;
else
kolon[j>=deger;
}
goster();
printf("%d.kolon\n",i+1);
for(w=0;w<6;w++)
{
printf("=>%d\t",kolon[w>);
}
printf("\n");
printf("*******************\n");
}
}
void goster()
{
int gec,i,j;
for(i=0;i<5;i++)
{
for(j=i+1;j<6;j++)
{
if(kolon[j><kolon)
{
gec=kolon;
kolon=kolon[j>;
kolon[j>=gec;
}
}
}
}
_____________________________________________
Telefon defteri örnek kodu.
Hepsini Seç#include<stdio.h>
FILE *fp;
char ad[15>,sy[20>,adr[50>,tel[15>,ceptel[20>;
char sec;
main()
{
fp=fopen("BILGILER/TELEFON REHBERI.txt","a");
do
{
printf("\t\t\tBILGILERI DIKKATLI GIRINIZ\n\n");
printf("\t\tADI :");
scanf("%s",&ad);
printf("\t\tSOYADI :");
scanf("%s",&sy);
printf("\t\tADRESI :");
scanf("%s",&adr);
printf("\t\tTELEFONU :");
scanf("%s",&tel);
printf("\t\tCEP TELEFONU :");
scanf("%s",&ceptel);
fprintf(fp,"AD:%s %s\n",ad,sy);
fprintf(fp,"ADRES:%s\nTEL:%s\nCEP TEL:%s\n",adr,tel,ceptel);
printf("\n\n");
printf("\t\tDEVAM ETMEK ISTIYORMUSUNUZ?(E/H)");
fflush(stdin);
sec=getchar();
}
while(sec!='h' && sec!='H');
fclose(fp);
getchar();
}
________________________________________
Taban Kuvvet Bulma!
#include <stdio.h>
double tabankuvveti(int, int);
int main()
{
int e,k;
printf("Shurzan'in kod denmelerine hos glediniz\n\nSimdi lutfen kuvveti hesaplanacak\nTabani gir: ");
scanf("%d",&e);
printf("Ussu gir: ");
scanf(
"%d",&k);
printf("Sonuc: %.f\n", tabankuvveti(e,k));
system ("PAUSE");
return 0;
}
double tabankuvveti(int x, int y)
{
int d;
static double a=1;
if(y==1)
return x;
else
if(y==0)
return 0;
else
for(d=1;d<=y;d++)
a=a*x;
return a;
}
____________________________________________
Maximum Değer!
/*calculates the product of two matrices*/
#include <stdio.h>
#define MAX 8
int main()
{
int a[MAX>[MAX>, b[MAX>[MAX>;
int c[MAX>[MAX> = { 0 };
int ra, ca, rb, cb;
int i, j, k;
printf ("Rows of the first matrice : "); scanf("%d", &ra);
printf ("Columns of the first matrice : "); scanf("%d", &ca);
printf ("Rows of the second matrice : "); scanf("%d", &rb);
printf ("Columns of the second matrice : "); scanf("%d", &cb);
if ( ca != rb) {
printf ("Matrices are not proper for multiplication\n");
return 0; }
printf ("First matrice: \n");
for (i = 0; i < ra; i++) {
for (j = 0; j < ca; j++) {
printf (" [%d,%d>: ",i+1,j+1);
scanf ("%d", &a[j>);
}
}
printf ("Second matrice: \n");
for (j = 0; j < rb; j++) {
for (k = 0; k < cb; k++) {
printf (" [%d,%d>: ",j+1,k+1);
scanf ("%d", &b[j>[k>);
}
}
for (i = 0; i < ra; i++) {
for (j = 0; j < cb; j++) {
for (k = 0; k < ca; k++)
c[j> = c[j> + a[k> * b[k>[j>;
}
}
printf ("Product:\n");
for (i = 0; i < ra; i++) {
for (k = 0; k < cb; k++)
printf ("\t%d",c[k>);
printf ("\n");
}
return 0;
}
_________________________________________________
Kare kök bulan!
#include <iostream.h>
#include <stdlib.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>
int main()
{
double a,b,c,x;
char s;
ilk:
cout<<"\nLutfen bir sayi girin"<<endl;
cin>>x;
a=(x*x);
b=(x*x*x);
c = pow(x,0.5);
cout<<"\nKaresi "<<a<<endl;
cout<<"\nKupu "<<b<<endl;
cout<<"\nKare Koku "<<c;
cout<<"\n\nTekrar islem yapmak istiyor musunuz?(E/H)"<<endl;
cin>>s;
switch (s)
{
case 'e': { goto ilk; break;}
case 'E': { goto ilk; break;}
case 'h': { return 0; break; }
case'H' : { return 0; break;}
default : { printf("Lütfen E veya H girin."); break; }
}
getch();
return 0;
}
NOT: c++ ve dengi bir derleyicide çalıştırmanız gerekir. turbo c de çalışmaz.
______________________________________________
Ortalama Hesaplama!!!
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float a[20>,ortalama,toplam,sayi;
int i,sayi_mik;
char b,secim;
printf("Baslamak icin b ye basiniz :");
scanf("%c",&secim);
clrscr();
while(secim!=b) //programin devamliligi icin
{
printf("Kac sayinin ortalamasini alacaksiniz :");
scanf("%d",&sayi_mik);
for(i=1; i<=sayi_mik; i++)
{
printf("\n%d. degeri giriniz :",i);
scanf("%f",&sayi);
a = a[i-1> + sayi; //girilen sayilari diziye yukler
toplam = a;
}
ortalama = toplam/sayi_mik;
printf("\nGirdiginiz %d sayinin ortalamasi = %.3f" ,sayi_mik, ortalama);
getch();
clrscr();
}
getch();
}
_________________________________________________
Makrolarla çalışmak!!
#include <stdio.h>
#include <stdlib.h>
#define HATALI(A) A*A*A /* Kup icin hatali makro */
#define KUP(A) (A)*(A)*(A) /* Dogusu ... */
#define KARE(A) (A)*(A) /* Karesi icin dogru makro */
#define START 1
#define STOP 9
main()
{
int i,offset;
offset = 5;
printf("shurzan'ın kod denemelerine hoş geldiniz\nBu progr***** makrolarla nasıl çalışılacağına örnektir.\n\n");
for (i = START;i <= STOP;i++) {
printf("%3d in karesi %4d dir, ve kubu ise %6d dir..\n",
i+offset,KARE(i+offset),KUP(i+offset));
printf("%3d in HATALIsi ise %6d dir.\n",i+offset,HATALI(i+offset));
}
system("pause");
}
___________________________________________--
İdeal kilona kavuş
include<stdio.h>
#include<conio.h>
int main(void)
{
int boy,a;
do
{
do{
clrscr();
printf("\n\n\n\n\n\n\n\n\t\t\t IDEAL KILONUZU BULUNUZ\n\n\n\n");
printf("\n\n\n\n\n\n\t\tL�tfen Boyunuzu 140 cm ile 210 cm aras�nda giriniz\n\n");
printf("\n\n\n\t\t\t\t Boyum : ");
scanf("%d",&boy);
}while(boy<140 || boy>210);
if(boy<145)
printf("\n\n\t\t\t\t Kilom : 42");
else if(boy<148)
printf("\n\n\t\t\t\t Kilom : 44");
else if(boy<150)
printf("\n\n\t\t\t\t Kilom : 46,5");
else if(boy<153)
printf("\n\n\t\t\t\t Kilom : 48");
else if(boy<155)
printf("\n\n\t\t\t\t Kilom : 49,5");
else if(boy<158)
printf("\n\n\t\t\t\t Kilom : 51");
else if(boy<160)
printf("\n\n\t\t\t\t Kilom : 52,5");
else if(boy<163)
printf("\n\n\t\t\t\t Kilom : 54");
else if(boy<165)
printf("\n\n\t\t\t\t Kilom : 56,5");
else if(boy<167)
printf("\n\n\t\t\t\t Kilom : 58,5");
else if(boy<170)
printf("\n\n\t\t\t\t Kilom : 60");
else if(boy<172)
printf("\n\n\t\t\t\t Kilom : 62,5");
else if(boy<174)
printf("\n\n\t\t\t\t Kilom : 63,5");
else if(boy<176)
printf("\n\n\t\t\t\t Kilom : 65");
else if(boy<178)
printf("\n\n\t\t\t\t Kilom : 66,5");
else if(boy<180)
printf("\n\n\t\t\t\t Kilom : 68");
else if(boy<183)
printf("\n\n\t\t\t\t Kilom : 70");
else if(boy<186)
printf("\n\n\t\t\t\t Kilom : 72");
else if(boy<188)
printf("\n\n\t\t\t\t Kilom : 73,5");
else if(boy<190)
printf("\n\n\t\t\t\t Kilom : 75");
else if(boy<192)
printf("\n\n\t\t\t\t Kilom : 77");
else if(boy<194)
printf("\n\n\t\t\t\t Kilom : 79");
else if(boy<197)
printf("\n\n\t\t\t\t Kilom : 82");
else if(boy<200)
printf("\n\n\t\t\t\t Kilom : 85");
else if(boy<203)
printf("\n\n\t\t\t\t Kilom : 87");
else if(boy<205)
printf("\n\n\t\t\t\t Kilom : 90");
else if(boy<208)
printf("\n\n\t\t\t\t Kilom : 93");
else
printf("\n\n\t\t\t\t Kilom : 95");
printf("\n\n\n\n\t\t\t Tekrar Denemek Istermisiniz?");
printf("\n\n\n\n\t\t\t\t Evet => 1");
printf("\n\n\n\t\t\t\t Hay�r => 2");
printf("\n\n\n\t\t\t\t Se‡imin : ");
scanf("%d",&a);
}while(a==1);
return 0;
}
______________________________________________
C de çeşitli şekiller çizen ve yazı yazan program.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request autodetection */
int gdriver = DETECT, gmode, errorcode;
int i;
int j;
int k;
int y;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/*C0d3d by -cod3mast3r- */
}
line(0, 0, getmaxx(), getmaxy());
arc(100,200,100,200,100);
setcolor(5);
for(i=0;i<100;i++)
{
for(k=0;k<1000;k++)
for(j=0;j<30000;j++)
{}
setcolor(i);
arc(getmaxx()/2+i,getmaxy()/2+i,0,360,100-i);
}
outtextxy(10,10,"Waaaoooowww what a race !");
for(i=0;i<200;i++)
{
for(k=0;k<1000;k++)
for(j=0;j<30000;j++)
{}
setcolor(i);
arc(getmaxx()/2+i,getmaxy()/2+i,0,360,100-i);
}
/* clean up */
getch();
closegraph();
return 0;
}
__________________
Herkes halâ artis ve ben halâ yönetmenim !
Rekabet etmem, takip edilirim.
|