-
برامج في c & ++c
السلام عليكم.....
كيف حالكم يا اعضاء.....نظراً لعدم توفر قسم البرمجة فسوف انزل موضوع في الكمبيوتر.....
و لكن لانشغالي الشديد و عدم توفر الوقت فلن اقدر ان البي الطلبات و انما انزل البرنامج و اكتب عليه اسم البرنامج فقط....
و لكن قد يكون البرنامج في بعض غلط......
اتفقنا ان شاء الله خير..... :36_3_12: :36_3_12:
-
برنامج تذخل فية قيمة الزاوية ويقوم هو بإيجاد جيب الزاوية Sin
Code:
#include <iostream.h>
#include <math.h>
#include <conio.h>
#define PI 3.14159
main()
{
clrscr();
float degree, sine ;
cout << "\t\tSIN\nPlease enter the angle in degrees " ;
cin >> degree ;
sine = sin(degree* PI/ 180) ;
cout << " SIN " << degree <<" = " << sine ;
getch();
}
-
برنامج تذخل فية قيمة الزاوية ويقوم هو بإيجاد جيب تمام الزاوية Cos
Code:
#include <iostream.h>
#include <math.h>
#include <conio.h>
#define PI 3.14159
main()
{
clrscr();
float degree, cose ;
cout << "\t\tCOS\nPlease enter the angle in degrees " ;
cin >> degree ;
cose = cos(degree* PI/ 180) ;
cout << " COS " << degree <<" = " << cose ;
getch();
}
-
برنامج تذخل فية قيمة الزاوية ويقوم هو بإيجاد ظل الزاوية tan
Code:
#include <iostream.h>
#include <math.h>
#include <conio.h>
#define PI 3.14159
main()
{
clrscr();
float degree, tane ;
cout << "\t\tTAN\nPlease enter the angle in degrees " ;
cin >> degree ;
tane = tan(degree* PI/ 180) ;
cout << " TAN " << degree <<" = " << tane ;
getch();
}
-
برنامج يعطيك الأعداد الفردية التي تقع بين الواحد والرقم الذي يطلبة منك في بداية البرنامج
Code:
#include <iostream.h>
main();
{
int i,n ;
cout << "Enter number you want find EVEN to it:\n ";
cin >> n ;
for ( i=1; i<=n; i++ )
{
if (i%2) ;
cout << i << "\t " ;
else continue ;
}
}
-
برنامج يعطيك الأعداد الزوجية التي تقع بين الواحد والرقم الذي يطلبة منك في بداية البرنامج
Code:
#include <iostream.h>
main()
{
int i,n ;
cout << "Enter number you want find EVEN to it:\n" ;
cin >> n ;
for ( i=1; i<=n; i++)
{
if (i%2) continue ;
cout << i << "\t" ;
}
}
-
برنامج يعطيك حجم الدائرة بدلالة قطرها
Code:
#include <iostream.h>
main()
{
float r,area ;
cout << " Enter the radius " ;
cin >> r ;
area =3.14*r*r ;
cout <<'\n'<<"Area = " << area <<" squared unit" ;
}
-
هذا البرنامج يحول الدرجات من سلسيوسي الى فهرينهايت
Code:
#include <iostream.h>
#include <math.h>
main()
{
float celsius,fahrenheit ;
cout << " Please enter the temperature in fahrenheit degrees\n" ;
cin >> fahrenheit ;
celsius = (5.0/9.0)* (fahrenheit -32) ;
cout << "The temperature in celsius = " <<celsius << " Degree" ;
}
-
البرنامج التالي يسمح لك بإذخال كلمة من 10 أحرف ويستخرج لك الحرف الهجائي الأخير من حيت الترتيب الهجائي........ مثل ( hotmail ) الأخير من حيت الترتيب الهجائي هو ( T )
Code:
#include <iostream.h>
main()
{
char c ;
int i, big ;
cout << "Enter your character " ;
cin >> c ;
big = int(c) ;
for(i=1; i<=10; i++)
{
cin >> c ;
if(int(c)>big)
big = int(c) ;
}
cout << "\nThe character that is alphabitically last: " << char(big) ;
}
-
لإيجاد عوامل العدد بمعنى الأعداد التي يقبل العدد القسمة عليها
Code:
#include<iostream.h>
main()
{
int number, counter ;
cout << "PLAESE ENTER A NUMBER " ;
cin >> number ;
if (number<0)
cout << "NEGATIVE NUMBER " ;
else
cout << "THE DIVISIORS OF THE NUMBER ARE: " ;
for (counter=1; counter <= number; counter++)
{
if(number%counter==0)
cout << "\t" << counter ;
}
}
-
برنامج يحسب الـ average
Code:
#include <iostream.h>
main()
{
float *a ;
float sum, average ;
int i, n ;
a = & average ;
cout << "\n \a Please enter the total number of elements: " ;
cin >> n ;
for(i=0; i<n; i++)
{
cout << "a["<< i+1<< "]= " ;
cin >> *(a+i) ;
}
for(i=0; i<n; i++)
sum += *(a+i) ;
average = sum / n ;
cout << "\n Average = "<< average ;
}
-
يحسب أصغر عدد ثم إذخاله
Code:
#include <iostream.h>
#include <conio.h>
main()
{
clrscr();
int x1, x2, x3 ;
cout << "Enter three different integers:\n " ;
cin >> x1>> x2>> x3 ;
if((x1<x2) && (x1<x3))
cout << "The smaller number is " << x1 ;
else if((x2<x1) && (x2<x3))
cout << "The smaller number is " << x2 ;
else if((x3<x1) && (x3<x2))
cout << "The smaller number is " << x3 ;
else cout << "THERE ARE ERROR " ;
getch();
}
-
لإيجاد مساحة المثلث
Code:
#include <iostream.h>
#include <math.h>
main()
{
float a,b,c,s,area ;
cout << "\n Please enter A,B,andC: " ;
cin >> a>> b>> c ;
s = (a+b+c)/2 ;
area =sqrt(s*(s-a)*(s-b)*(s-c)) ;
cout << "\n Area = " << area ;
}
-
لإيجاد المضروب (( الفيكتوريا )) طريقة 1
Code:
#include <iostream.h>
main()
{
int number, counter, fact ;
cout << "\n Please enter a number " ;
cin >> number ;
if (number<0)
cout << " negative number " ;
else
if (number==0)
cout << "Factorial of 0 = 1" ;
else
if (number==0)
cout << "factorial of 0 = 1 " ;
else
fact = 1 ;
for (counter=1; counter<=number; counter++)
{fact = fact *counter ;}
cout << "\n FACTORIAL OF " << number << " = "<< fact ;
}
-
الطريقة التقليدية لإيجاد الفيكتوريا (( المضروب ))
Code:
#include <iostream.h>
main()
{
int factorial = 1, dec = 7 ;
factorial *= dec ;
factorial *= ( --dec) ;
factorial *= ( --dec) ;
factorial *= ( --dec) ;
factorial *= ( --dec) ;
factorial *= ( --dec) ;
factorial *= ( --dec) ;
cout << "The factorial :\n (7)! = " << factorial ;
return 0 ;
}
-
برنامج ثلاتي لإيجاد مساحة كل من المثلت/ الدائرة / المربع
Code:
#include <iostream.h>
#include <math.h>
#include <conio.h>
main()
{ go: clrscr();
int choice ;
float a, b, c, s, area, r ;
/*the main menu*/
cout << " Main menu " ;
cout << " \n 1....Triangle" ;
cout << " \n 2....Circle" ;
cout << " \n 3....Square" ;
cout << " \n Enter your choice " ;
cin >> choice ;
switch(choice)
{
case 1:
cout << " \n Please enter A, B, and C: " ;
cin >> a>> b>> c ;
s = (a+b+c) / 2 ;
area = sqrt(s*(s-a)*(s-b)*(s-c)) ;
cout << " \n Area = " << area ;
break ;
case 2:
cout << "Enter the radius " ;
cin >> r ;
area = 3.14* r* r ;
cout << "\n Area = " << area<< " Squared unit" ;
break ;
case 3:
cout << "Enter the length of the square " ;
cin >> r ;
area = r* r ;
cout << "\n Area = " << area<< " Squared unit" ;
break ;
default:
goto go;
}
getch();
}
-
برنامج يحوّل من المساحة من الأقدام الى نظام الفدان
Code:
#include <iostream.h>
#include <stdio.h>
main()
{
float width ,length ,area ;
cout << "Please enter the width and length in feet\n" ;
cin >> width>> length ;
area = (length *width) /43560 ;
printf("The result area in acres = %8.2f acres" ,area ) ;
}
-
برنامج الساعه
Code:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
#include <stdlib.h>
#define PI 3.14159265359
#define _2PI 2*PI
#define IS_OK_SELECTED(x,y,button) (((x>=200)&&(x<=270)) && ((y>=418)&&(y<=443)) && ((button&1)==1))?1:0
#define IS_CANCEL_SELECTED(x,y,button) (((x>=370)&&(x<=440)) && ((y>=418)&&(y<=443)) && ((button&1)==1))?1:0
#define IS_HRUP_SELECTED(x,y,button) (((x>=238)&&(x<=250)) && ((y>=370)&&(y<=380)) && ((button&1)==1))?1:0
#define IS_HRDN_SELECTED(x,y,button) (((x>=238)&&(x<=250)) && ((y>=381)&&(y<=390)) && ((button&1)==1))?1:0
#define IS_MNUP_SELECTED(x,y,button) (((x>=303)&&(x<=315)) && ((y>=370)&&(y<=380)) && ((button&1)==1))?1:0
#define IS_MNDN_SELECTED(x,y,button) (((x>=303)&&(x<=315)) && ((y>=381)&&(y<=390)) && ((button&1)==1))?1:0
#define IS_SCUP_SELECTED(x,y,button) (((x>=368)&&(x<=380)) && ((y>=370)&&(y<=380)) && ((button&1)==1))?1:0
#define IS_SCDN_SELECTED(x,y,button) (((x>=368)&&(x<=380)) && ((y>=381)&&(y<=390)) && ((button&1)==1))?1:0
#define IS_APUP_SELECTED(x,y,button) (((x>=428)&&(x<=440)) && ((y>=370)&&(y<=380)) && ((button&1)==1))?1:0
#define IS_APDN_SELECTED(x,y,button) (((x>=428)&&(x<=440)) && ((y>=381)&&(y<=390)) && ((button&1)==1))?1:0
class coordinate
{
protected:
int x,y; public:
coordinate()
{
x=y=0;
}
coordinate(int initx,int inity)
{
x = initx;
y = inity;
}
};
class timenow
{
private:
struct time tm;public:
int tellhour(void)
{
gettime(&tm);
return tm.ti_hour;
}
int tellminute(void)
{
gettime(&tm);
return tm.ti_min;
}
int tellsecond(void)
{
gettime(&tm);
return tm.ti_sec;
}
};
class mouse
{
private:
union REGS i,o;
public:
mouse()
{
initmouse();
showmousepointer();
setmouseptrpos(425,320);
restrictmousepointer(1,1,630,478);
}
void initmouse()
{
i.x.ax = 0;
int86(0x33,&i,&o);
if(o.x.ax == 0)
{
cleardevice();
closegraph();
restorecrtmode();
printf("\nMouse driver not installed.\nQuitting...\n");
}
}
void showmousepointer()
{
i.x.ax = 1;
int86(0x33,&i,&o);
}
void setmouseptrpos(int row, int col)
{
i.x.ax = 4;
i.x.cx = col;
i.x.dx = row;
int86(0x33,&i,&o);
}
void hidemousepointer()
{
i.x.ax = 2;
int86(0x33,&i,&o);
}
void getmousepos(int &button, int &x, int &y)
{
i.x.ax = 3;
int86(0x33,&i,&o);
button = o.x.bx;
x = o.x.cx;
y = o.x.dx;
}
void restrictmousepointer(int x1, int y1, int x2, int y2)
{
i.x.ax = 7;
i.x.cx = x1;
i.x.dx = x2;
int86(0x33,&i,&o);
i.x.ax = 8;
i.x.cx = y1;
i.x.dx = y2;
int86(0x33,&i,&o);
}
};
class textbox
{
public:
textbox(int col1,int row1, int col2, int row2)
{
setfillstyle(SOLID_FILL,WHITE);
bar(col1,row1,col2,row2);
setcolor(LIGHTGRAY);
line(col1 + 1,row2-1,col2-1,row2-1);
line(col2-1,row1+1,col2-1,row2-1);
setcolor(DARKGRAY);
line(col1,row1-1,col2,row1-1);
line(col1-1,row1-1,col1-1,row2);
}
};
class BUTTON
{
private:
int row1,col1,row2,col2; public:
BUTTON()
{
}
BUTTON(int col1, int row1,int col2,int row2)
{
this -> col1=col1;
this -> row1=row2;
this -> col2=col2;
this -> row2=row2;
setcolor(BLACK);
rectangle(col1,row1,col2,row2);
setcolor(WHITE);
line(col1,row1,col2,row1);
line(col1,row1,col1,row2);
}
void Select(void)
{
setcolor(WHITE);
settextstyle(SANS_SERIF_FONT,0,1);
setcolor(BLACK);
line(this -> col1, this->row1,this->col2,this->row1);
line(this -> col1, this->row1,this->col1,this->row2);
setcolor(WHITE);
line(this -> col2, this->row1,this->col2,this->row2);
line(this -> col2, this->row2,this->col1,this->row2);
settextstyle(DEFAULT_FONT,0,1);
}
void UnSelect(void)
{
setcolor(BLACK);
settextstyle(SANS_SERIF_FONT,0,1);
setcolor(WHITE);
line(col1,row1,col2,row1);
line(col1,row1,col1,row2);
setcolor(BLACK);
line(col2,row1,col2,row2);
line(col2,row2,col1,row2);
settextstyle(DEFAULT_FONT,0,1);
}
};
class clockbody:public coordinate
{
private:
int radius; public:
clockbody(int centreX,int centreY):coordinate(centreX,centreY)
{
int inner_radius;
int i;
setcolor(WHITE);
settextstyle(TRIPLEX_FONT,0,1);
outtextxy(260,82,"TIME VIEWER");
radius = (200*8)/20;
inner_radius = (radius*8)/10;
setcolor(WHITE);
circle(x,y,radius);
setfillstyle(SOLID_FILL,LIGHTGRAY);
floodfill(x,y,getmaxcolor());
setcolor(WHITE);
circle(x,y,inner_radius-5);
setfillstyle(SOLID_FILL,WHITE);
floodfill(x,y,getmaxcolor());
setcolor(BLACK);
circle(x,y,1);
int row,col;
char no[5];
settextstyle(SANS_SERIF_FONT,0,1);
radius = 70;
settextstyle(DEFAULT_FONT,0,1);
for(i=1;i<=12;i++)
{
row = (x+radius*sin(_2PI*i/12.0));
col = (y-radius*cos(_2PI*i/12.0));
itoa(i,no,10);
outtextxy((row-textwidth(no)/2),(col+textheight(no)/2)-5,no);
}
}
int tellradius(void)
{
return radius;
}
int tellcentreX(void)
{
return x;
}
int tellcentreY(void)
{
return y;
}
};
void main(void)
{
int gd = DETECT,gm;
int hr,min,sec,acchr;
int button,x,y;
char strtime[3],opt;
struct time ot,nt;
static char apflg;
void frame(int,int,int,int);
void background(int,int,int,int);
void clockhands(int,int,int,clockbody,char);
char *putzero(char[]);
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
frame(190,125,450,350);
frame(190,70,450,120);
background(190,360,450,400);
background(190,410,450,450);
BUTTON hrup(238,370,250,380),hrdn(238,381,250,390),
mnup(303,370,315,380),mndn(303,381,315,390),
scup(368,370,380,380),scdn(368,381,380,390),
apup(428,370,440,380),apdn(428,381,440,390),
Ok(200,418,270,443),Cancel(370,418,440,443);
setcolor(BLACK);
outtextxy(240,371,"");outtextxy(305,371,"");
outtextxy(370,371,"");outtextxy(430,371,"");
outtextxy(240,382,"");outtextxy(305,382,"");
outtextxy(370,382,"");outtextxy(430,382,"");
outtextxy(230,428,"Ok");outtextxy(382,428,"Cancel");
textbox hour(200,370,235,390),minute(265,370,300,390),
second(330,370,365,390),ampm(390,370,425,390);
clockbody clock(getmaxx()/2,getmaxy()/2);
timenow time;
mouse m;
gettime(&ot);
setcolor(WHITE);
outtextxy(100,470,"Developed and Designed by Ranawat Mahipat Balwantraj, GCET.");
while(1)
{
hr = time.tellhour();
min = time.tellminute();
sec = time.tellsecond();
if(hr>=12)
apflg = 'p';
if(hr < 12)
apflg = 'a';
m.getmousepos(button,x,y);
if(IS_OK_SELECTED(x,y,button))
{
while(IS_OK_SELECTED(x,y,button))
{
Ok.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(230,428,"Ok");
}
Ok.UnSelect();
setcolor(BLACK);
outtextxy(230,428,"Ok");
gettime(&nt);
if(nt.ti_hour==0)
nt.ti_hour=12;
settime(&nt);
break;
}
if(IS_CANCEL_SELECTED(x,y,button))
{
while(IS_CANCEL_SELECTED(x,y,button))
{
Cancel.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(382,428,"Cancel");
}
Cancel.UnSelect();
setcolor(BLACK);
outtextxy(382,428,"Cancel");
settime(&ot);
break;
}
if(IS_HRUP_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_HRUP_SELECTED(x,y,button))
{
hrup.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(240,371,"");
}
hrup.UnSelect();
nt.ti_hour++;
if(nt.ti_hour>23)
nt.ti_hour = 12;
else if(nt.ti_hour > 11 && nt.ti_hour < 13)
nt.ti_hour = 0;
settime(&nt);
hr = time.tellhour();
setcolor(BLACK);
outtextxy(240,371,"");
}
if(IS_HRDN_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_HRDN_SELECTED(x,y,button))
{
hrdn.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(240,382,"");
}
hrdn.UnSelect();
if(nt.ti_hour < 1 && apflg == 'a')
nt.ti_hour = 12;
nt.ti_hour--;
if(nt.ti_hour < 12 && apflg == 'p')
nt.ti_hour = 23;
else if(nt.ti_hour < 1 && apflg =='a')
nt.ti_hour = 0;
settime(&nt);
hr = time.tellhour();
setcolor(BLACK);
outtextxy(240,382,"");
}
if(IS_MNUP_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_MNUP_SELECTED(x,y,button))
{
mnup.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(305,371,"");
}
mnup.UnSelect();
nt.ti_min++;
if(nt.ti_min > 59)
nt.ti_min = 0;
min = time.tellminute();
settime(&nt);
setcolor(BLACK);
outtextxy(305,371,"");
}
if(IS_MNDN_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_MNDN_SELECTED(x,y,button))
{
mndn.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(305,382,"");
}
mndn.UnSelect();
nt.ti_min--;
if(nt.ti_min == 0)
nt.ti_min = 59;
settime(&nt);
min = time.tellminute();
setcolor(BLACK);
outtextxy(305,382,"");
}
if(IS_SCUP_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_SCUP_SELECTED(x,y,button))
{
scup.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(370,371,"");
}
scup.UnSelect();
nt.ti_sec++;
if(nt.ti_sec > 59)
nt.ti_sec = 0;
settime(&nt);
sec = time.tellsecond();
setcolor(BLACK);
outtextxy(370,371,"");
}
if(IS_SCDN_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_SCDN_SELECTED(x,y,button))
{
scdn.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(307,382,"");
}
scdn.UnSelect();
nt.ti_sec--;
if(nt.ti_sec == 0)
nt.ti_sec = 59;
min = time.tellminute();
settime(&nt);
sec = time.tellminute();
setcolor(BLACK);
outtextxy(305,382,"");
}
if(IS_APUP_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_APUP_SELECTED(x,y,button))
{
apup.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(430,371,"");
}
apup.UnSelect();
setcolor(BLACK);
outtextxy(430,371,"");
switch(apflg)
{
case 'a': nt.ti_hour += 12;
settime(&nt);
break;
case 'p': nt.ti_hour -= 12;
settime(&nt);
break;
}
settime(&nt);
}
if(IS_APDN_SELECTED(x,y,button))
{
gettime(&nt);
while(IS_APDN_SELECTED(x,y,button))
{
apdn.Select();
m.getmousepos(button,x,y);
setcolor(WHITE);
outtextxy(430,382,"");
}
apdn.UnSelect();
setcolor(BLACK);
outtextxy(430,382,"");
switch(apflg)
{
case 'a': nt.ti_hour += 12;
settime(&nt);
break;
case 'p': nt.ti_hour -= 12;
settime(&nt);
break;
}
settime(&nt);
}
setcolor(BLACK);
if(hr == 0)
acchr = 12;
else if(hr>12)
acchr = hr-12;
else
acchr = hr;
if(hr>=12)
setcolor(WHITE),outtextxy(400,375,"AM"),
setcolor(BLACK),outtextxy(400,375,"PM"),
apflg = 'p';
else
setcolor(WHITE),outtextxy(400,375,"PM"),
setcolor(BLACK),outtextxy(400,375,"AM"),
apflg = 'a';
outtextxy(210,375,putzero(itoa(acchr,strtime,10)));
outtextxy(275,375,putzero(itoa(min,strtime,10)));
outtextxy(340,375,putzero(itoa(sec,strtime,10)));
opt='n';
clockhands(hr,min,sec,clock,opt);
delay(50);
setcolor(WHITE);
outtextxy(210,375,putzero(itoa(acchr,strtime,10)));
outtextxy(275,375,putzero(itoa(min,strtime,10)));
outtextxy(340,375,putzero(itoa(sec,strtime,10)));
opt = 'y';
clockhands(hr,min,sec,clock,opt);
}
closegraph();
restorecrtmode();
}
char* putzero(char strtime[])
{
if(strlen(strtime) == 1)
{
strtime[1] = strtime[0];
strtime[0] = '0';
strtime[2] = '\0';
}
return strtime;
}
void clockhands(int h, int m,int s,clockbody clock,char opt)
{
int x = clock.tellcentreX();
int y = clock.tellcentreY();
int r = clock.tellradius();
int h_len = (r*5)/10;
int m_len = (r*7)/10;
int s_len = (r*6)/10;
double hour_value = h+m/60.0 + s/3600.00;
hour_value *= _2PI/12.0;
if(opt!='y')
setcolor(BLACK);
setlinestyle(0,0,3);
line(x,y,(int)(x+h_len*sin(hour_value)),(int)(y-h_len*cos(hour_value)));
line(x,y+1,(int)(x+h_len*sin(hour_value)),(int)(y-h_len*cos(hour_value))+1);
double minute_value = m+ s/60.0;
minute_value *= _2PI/60.0;
if(opt!='y')
setcolor(BLACK);
setlinestyle(0,0,3);
line(x,y,(int)(x+m_len*sin(minute_value)),(int)(y-m_len*cos(minute_value)));
line(x,y+1,(int)(x+m_len*sin(minute_value)),(int)(y-m_len*cos(minute_value))+1);
double second_value = s*_2PI/60.0;
minute_value *= _2PI/60.0;
if(opt!='y')
setcolor(BLACK);
setlinestyle(0,0,1);
line(x,y,(int)(x+s_len*sin(second_value)),(int)(y-s_len*cos(second_value)));
}
void background(int c1,int r1, int c2, int r2)
{
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(c1,r1,c2,r2);
setcolor(WHITE);
line(c1,r1,c2,r1);
line(c1,r1+1,c2,r1+1);
line(c2,r1,c2,r2);
line(c2-1,r1,c2-1,r2);
setcolor(DARKGRAY);
line(c1,r1,c1,r2);
line(c1+1,r1,c1+1,r2);
line(c1,r2,c2,r2);
line(c1,r2-1,c2,r2-1);
}
void frame(int c1,int r1,int c2,int r2)
{
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(c1,r1,c2,r2);
setcolor(WHITE);
setfillstyle(SOLID_FILL,BLACK);
bar(c1+15,r1+15,c2-15,r2-15);
setcolor(WHITE);
line(c1,r1,c2,r1);
line(c1,r1+1,c2,r1+1);
line(c2,r1,c2-1,r2);
line(c1+15,r1+15,c1+15,r2-15);
line(c1+15,r2-15,c2-15,r2-15);
line((c1+15)-1,r1+15,(c1+15)-1,r2-15);
line((c1+15)-1,(r2-15)+1,c2-15,(r2-15)+1);
setcolor(DARKGRAY);
line(c1+15,(r1+15)-1,c2-15,(r1+15)-1);
line(c1+15,(r1+15)-2,c2-15,(r1+15)-2);
line(c1,r1,c1,r2);
line(c1+1,r1,c1+1,r2);
line(c1,r2,c2,r2);
line(c1+1,r2-1,c2,r2-1);
}
-
برنامج لإيجاد المصفوفة الثنائية
Code:
#include <iostream.h>
main()
{
float a[2][3], b[2][3] ;
int i, j ;
cout << "\n \a Please enter the elements: " ;
for(i=0; i<2; i++)
for(j=0; j<3; j++)
{
cout << "\n A[ "<< i+1<< " , "<< j+1 << " ] = " ;
cin >> a[j] ;
cout << "\t B[ "<< i+1<< " , "<< j+1 << " ] = " ;
cin >> b[j] ;
}
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
cout << a[j]+b[j] << "\t" ;
cout << '\n' ;
}
}
-
ضرب مصفوفتين ثنائيتين
Code:
#include <iostream.h>
main()
{
int a[5][5], b[5][5], c[5][5] ;
int temp, m, p, n, i, j, k ;
cout << "\nEnter number of row of 1st matrix\n" ;
cin >> m ;
cout << "\nEnter number of columns of 1st matrix\n" ;
cin >> p ;
cout << "\nEnter number of columns of 2nd matrix\n" ;
cin >> n ;
for(i=1;i<=m;i++)
for(j=1;j<=p;j++)
{
cout << "a["<< i<< "]["<< j<<"]=" ;
cin >> a[j] ;
}
cout << "\n" ;
for(i=1; i<=p; i++)
for(j=1; j<=n; j++)
{
cout << "b["<< i<< "]["<< j<< "]=" ;
cin >> b[j] ;
}
for(i=1; i<=m; i++)
for(j=1; j<=n; j++)
{
temp = 0 ;
for(k=1; k<=p; k++)
temp += a[k]* b[k][j] ;
c[j] = temp ;
}
cout << "\nThe multiplication is\n" ;
for(i=1; i<=m; i++)
{
for(j=1; j<=n;j++)
cout << c[j]<< " " ;
cout << "\n" ;
}
}
-
برنامج تذخل فيه 7 أرقام يقوم بترتيبها من الأكبر الى الأصغر
Code:
#include <iostream.h>
#include <stdio.h>
main()
{
short i, j, max, temp, number[7] ;
for(i=1; i<=7; i++)
{
printf("Please enter the number (%d) : ", i) ;
cin >> number ;
}
for(i=2; i<=7; i++)
if(number>max)
max = number ;
cout << "The maximum number of the numbers = "<<max ;
for(i=1; i<=6; i++)
{
for(j=i+1; j<=7; j++)
{
if(number[j]>number)
{
temp = number ;
number = number[j] ;
number[j] = temp ;
}
}
}
cout << "\nThe numbers are arranged as : \n\t " ;
for(i=1; i<=7; i++)
cout << number << "\t" ;
}
-
برنامج تعطية إحداثياث عمودين في الرسم البياني ويعطيك ما إذا كانا متوازيان أو متقاطعان في نقطة يقوم بذكر تلك النقطة
Code:
#include <iostream.h>
#include <math.h>
main()
{
float a1, a2, b1, b2, c1, c2, d, d_x, d_y, x, y ;
cout << "\nEnter the cofactor of the first line " ;
cin >> a1>> b1>> c1 ;
cout << "\nEnter the cofactor of the second line " ;
cin >> a2>> b2>> c2 ;
d = (a1*b2) - (a2*b1) ;
d_x = (c1*b2) - (c2*b1) ;
d_y = (a1*c2) - (a2*c1) ;
if(d==0)
cout << "\nThis two lines are parallel " ;
else
{
x = d_x / d ;
y = d_y / d ;
cout << "\nThe intersection point of your lines are :("<< x<<","<< y<<")" ;
}
}
-
برنامج حسابات لمستشفى
Code:
#include <iostream.h>
#include <conio.h>
main()
{
int n ;
char request ;
float sc, mc, misc, dayc, id, total, total_id, total_md ;
begin: clrscr() ;
cout << "\n\nPlease enter Number of days the patient set in hospital : " ;
cin >> n ;
cout << "Please enter Surgery coast : " ;
cin >> sc ;
cout << "Please enter Medication coast : " ;
cin >> mc ;
cout << "Please enter Miscellaneous coast : " ;
cin >> misc ;
cout << "Please enter Coast in hospital per day : " ;
cin >> dayc ;
cout << "Please enter Insurance deductible : " ;
cin >> id ;
total = (dayc* n) + sc + mc + misc + id ;
cout << "Total coast : " << total ;
total_id = total - id ;
cout << "\nTotal coast LESS Insurance deductible : " << total_id ;
total_md = total - mc ;
cout << "\nTotal coast LESS Medication & deductible : " << total_md ;
cout << "\nDo you have another patient (Y/N) : " ;
cin >> request ;
if(request=='y') goto begin ;
}
-
حل لهذه المعادلة aX^2+bX+c=0
Code:
#include <iostream.h>
#include <math.h>
main()
{
int a, b, c ;
float mezo, rule, rule_1, rule_2 ;
cout << "TO SOLVE THE QUADRATIC EQUATION: \n\t aX^2+bX+c=0 \n" ;
cout << "PLEASE ENTER a, b ,and c: " ;
cin >> a>> b>> c ;
mezo = b^2 - (4* a* c) ;
if(mezo==0)
{
rule = (-b) / (2* a) ;
cout << "THE ROOTS ARE:\n\t\t" << rule << "\n\t\t" << rule ;
}
else
if(mezo<0)
{
mezo = -mezo ;
rule_1 =(-b)/(2* a) ;
rule_2 = sqrt(mezo)/(2* a) ;
cout << "THE ROOTS ARE :\n\t\t" << rule_1<< " + "<< rule_2<< " i" ;
cout << "\n\t\t" << rule_1<< " - "<< rule_2<< " i" ;
}
else
{
rule_1 = ((-b)+ sqrt(mezo)) / (2* a) ;
rule_2 = ((-b)- sqrt(mezo)) / (2* a) ;
cout << "The roots are:\n\t\t"<< rule_1<< "\n\t\t"<< rule_2 ;
}
cin>>"";
}
-
حاسبة تقوم بالعمليات الحسابية الأربع
Code:
#include <iostream.h>
#include <conio.h>
main()
{
clrscr();
int choice ;
float a, b, result ;
cout << "Please enter a number : " ;
cout << "\n (1) add the numbers" ;
cout << "\n (2) subtract the numbers" ;
cout << "\n (3) multiply the numbers" ;
cout << "\n (4) devides the numbers\n " ;
cin >> choice ;
if( (choice>4) || (choice<1) )
{
cout << "\t\t *** Wrong input *** " ;
goto exit ;
}
cout << "Please enter the two numbers (a, and b) : " ;
cin >> a>> b ;
switch(choice)
{
case 1:
result = a+ b ;
cout << a<< " + "<< b<< " = "<< result ;
break ;
case 2:
result = a- b ;
cout << a<< " - "<< b<< " = "<< result ;
break ;
case 3:
result = a* b ;
cout << a<< " * "<< b<< " = "<< result ;
break ;
case 4:
result = a/ b ;
cout << a<< " / "<< b<< " = "<< result ;
break ;
} getch();
exit:
}
-
Reverse any integer
Code:
#include<iostream.h>
// Prints the reverse of any integer
main()
{
double m , d , n = 0 ;
cout << " Enter a positive integer : ";
cin >> m;
while ( m> 0)
{
d = m % 10;
m /= 10;
n = 10 * n + d;
}
cout << " The reverse is "<< n <<endl;
}
-
برنامج يستعمل الswitch
// A program to find the days of the week
Code:
#include<iostream.h>
main()
{
int x;
cout<<"Enter any number between 1-7\";
cin>>x;
switch(x)
{
case 1 : cout<<"Today is Saturday";
case 2 : cout<<"Today is Sunday";
case 3 : cout<<"Today is Monday";
case 4 : cout<<"Today is Tuesday";
case 5 : cout<<"Today is Wednesday";
case 6 : cout<<"Today is Thursday";
case 7 : cout<<"Today is Friday";
Default : cout<<"You have not entered a number between 1-7";
}
return 0;
}
-
قلب الmatrix
Code:
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[3][3];
int b[3][3];
int i;
int j;
for (i=1;i<=3;i++)
for (j=1;j<=3;j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[j];
}
for (i=1;i<=3;i++)
for (j=1;j<=3;j++)
{
cout<<a[j]<<" ";
cout<<"\t";
}
for (i=1;i<=3;i++)
for (j=1;j<=3;j++)
{
b[j]=a[j];
cout<<b[j]<<" ";
}
return 0;
}
-
برنامج يحسب الفاتورة
Code:
#include <iostream.h>
main()
{
int oldvalue, newvalue , Unit , Cost;
cout<<"Enter the oldvalue:";
cin>>oldvalue;
cout<<"Enter the newvalue:";
cin>> newvalue;
Unit = newvalue - oldvalue;
if (Unit<=200)
Cost= (Unit*2);
else
if (Unit<=500)
Cost= (200*2)+(Unit-200)*5;
else
Cost=(200*2)+(300*5)+(Unit-500)*(7);
cout<<"The Cost is"<< Cost<<endl;
return 0;
}
-
Template Class
Code:
#include<iostream.h>
const int SIZE = 10;
template < class ListType> class List {
private :
ListType data[SIZE];
int back;
public:
List(){back=0;}
void add ( ListType ch);
ListType remove ();
};
template < class ListType > void List <ListType> :: add ( ListType ob)
{
if (back == SIZE)
cout<<"List is full";
else{
data[back] = ob ;
back++;
}
}
template < class ListType > ListType List <ListType> ::remove()
{
if (back == 0 ){
cout<<"List is empty";
return (ListType(0));
}
else{
back--;
return (data[back]);
}
}
void main(){
List<char> charL;
charL.add('A');
charL.add('B');
charL.add('C');
for(int i=0; i<3; i++)
cout << "remove :"<<charL.remove()<<endl;
List<double> doubleL;
doubleL.add(1.1);
doubleL.add(9.9);
doubleL.add(100.55);
for(i=0; i<3; i++)
cout << "remove :"<<doubleL.remove()<<endl;
}
-
Recursive Function
Code:
#include<stdio.h>
#include<conio.h>
void PrintReverse ();
void main()
{
printf("\nEnter a word :");
PrintReverse();
getch();
}
void PrintReverse ()
{
char n ;
scanf("%c",&n);
if( n != 10 )
PrintReverse();
printf("%c",n);
}
-
Sort an Array
Code:
#include<stdio.h>
#include<conio.h>
void SelectionSort(int arr[],int size);
void PrintArray(int arr[],int size);
void main()
{
int arr[10],size = 10;
for (int i=0;i<size;i++)
{
printf("\narr[%d] = ",i);
scanf("%d",&arr);
}
SelectionSort(arr,size);
PrintArray(arr,size);
getch();
}
void SelectionSort(int arr[],int size)
{
int n,j;
if (size > 0)
{
for(int i=size-2; i>=0;i--)
{
if (arr < arr[i+1])
{
n = arr;
j = i;
if (arr[size-1] > arr[j])
{
arr[j] = arr[size-1];
arr[size-1] = n;
}
}
}
SelectionSort(arr,size-1);
}
}
void PrintArray(int arr[],int size)
{
for(int i=0;i<size;i++)
printf("\narr[%d] = %d",i,arr);
}
-
Recursive Binary Search
Code:
#include<stdio.h>
int RecursiveBinarySearch(int *,int,int,int);
void sort(int *,int);
int main()
{
int array[10],key,size=10,Value;
for(int i=0;i<size;i++)
{
printf("\narray[%d] = ",i);
scanf("%d",&array);
}
sort(array,size);
printf("\nEnter Key Value :");
scanf("%d",&key);
printf("\nThe Key Value is %d",key);
Value = RecursiveBinarySearch(array,0,size,key);
if (Value == -1)
printf("\nThe key value is not found ");
else
printf("\nIt's found in the location %d in the array",Value);
return 0;
}
void sort(int *array,int size)
{
int temp;
for(int i=0;i<size-1;i++)
for(int j=i+1;j<size;j++)
if(*(array+i)>*(array+j))
{
temp = *(array+i);
*(array+i) = *(array+j);
*(array+j) = temp;
}
for(i=0;i<size;i++)
printf("\narray[%d] = %d",i,*(array+i));
}
int RecursiveBinarySearch(int *array,int low,int high,int key)
{
int mid;
mid = (high+low)/2;
if ( key == *(array+mid))
return mid;
else if ( mid == high || mid == low)
return -1;
else if(*(array+mid)>key)
return RecursiveBinarySearch(array,low,mid,key);
else
return RecursiveBinarySearch(array,mid,high,key);
}
-
Structures & Enumeration
Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
struct Book{
char title[30],author[30],ISBN[30],publisher[30],month[30],price[30],quantity[30];
};
void AddBook(struct Book [],int *);
void displayTable(struct Book [],int *);
int Search(struct Book [],int *,char *);
void changePrice(struct Book [],int,char *);
void find_ToTal_New_Books(struct Book [],int *,char *[],int *);
enum Month {JAN=1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC} ;
void main()
{
struct Book book[100];
char *MonthsName[]={"","January","February","March","April","May","June","July","August","September","October","November","December"};
int size = 100,key,count[13] = {0};
char enter,ISBN[30],price[30];
enum Month months;
do{
puts("1 - Add a Book");
puts("2 - Display Table");
puts("3 - Search for a Book");
puts("4 - Change a Price ");
puts("5 - Sold in each month");
puts("6 - Exit");
puts("Enter your Choice :");
scanf("%d%c",&key,&enter);
switch(key)
{
case 1:{
AddBook(book,&(--size));
break;
}
case 2:{
displayTable(book,&size);
break;
}
case 3:{
puts("Enter The ISBN of the Book:");
gets(ISBN);
if(Search(book,&size,ISBN)== -1)
printf("Not Found\n");
else
{
printf("ISBN : %s\n",ISBN);
printf("Book Title : %s\n",book[Search(book,&size,ISBN)].title );
}
break;
}
case 4:{
puts("Enter The ISBN of the Book:");
gets(ISBN);
if(Search(book,&size,ISBN)== -1)
printf("Not Found\n");
else
{
puts("Enter the new Price: ");
gets(price);
changePrice(book,Search(book,&size,ISBN),price);
}
break;
}
case 5:{
find_ToTal_New_Books(book,count,MonthsName,&size);
for( months=JAN;months<=DEC;months++)
printf("%-12s\t%d\n",*(MonthsName+months),count[months]);
break;
}
case 6:
{
break;
}
default:{
puts("Invalid Choice");
break;
}}
}while(key!=6);
}
void AddBook(struct Book *book,int *size)
{
puts("Enter the Title of the Book :");
gets(book[*size].title);
puts("Enter the Author of the Book :");
gets(book[*size].author);
puts("Enter the ISBN Number of the Book :");
gets(book[*size].ISBN );
puts("Enter the Publisher of the Book :");
gets(book[*size].publisher );
puts("Enter the Month of the Book first sold :");
gets(book[*size].month );
puts("Enter the Price of the Book :");
gets(book[*size].price );
puts("Enter the Quantity of the Book :");
gets(book[*size].quantity);
}
void displayTable(struct Book *book,int *size)
{
printf("%-15s%-15s%-10s%-10s%-10s%-10s%-10s\n","Title","Author","ISBN","Publisher","Month","Price","Quantity");
for(int i = 99;i>=*size;i--)
{
printf("%-15s%-15s%-10s%-10s%-10s%-10s%-10s\n",(book+i)->title,(book+i)->author,(book+i)->ISBN,(book+i)->publisher,(book+i)->month,(book+i)->price,(book+i)->quantity);
}
}
int Search(struct Book *book,int *size,char *ISBN)
{
for(int i = 99;i>=*size;i--)
if(strcmpi(book.ISBN,ISBN)==0)
return i;
return -1;
}
void changePrice(struct Book *book,int pos,char *price)
{
strcpy(book[pos].price,price);
}
void find_ToTal_New_Books(struct Book *book,int *count,char *MonthsName[],int *size)
{
for(int i = 99;i>=*size;i--)
{
if (isdigit(book.month[0]))
{
int m;
sscanf(book.month,"%d",&m);
strcpy(book.month,*(MonthsName+m));
++*(count+m);
}
else
{
for(int j=1;j<=12;j++)
if (strcmpi(MonthsName[j],book.month)==0)
++*(count+j);
}
}
}
-
passing virables by refrence
Code:
#include<iostream.h>
void year_calc(long total_days,int &year,int &month,int &day)
{
while(total_days>365)
{
total_days -= 365;
year++;
}
while(total_days>30)
{
total_days -= 30;
month++;
}
day = total_days;
}
void main()
{
int year=0,month=0,day=0;
long total_days;
cout<<"Enter Total Days :"<<endl;
cin>>total_days;
year_calc(total_days,year,month,day);
cout<<"years : "<<year<<endl;
cout<<"months: "<<month<<endl;
cout<<"days : "<<day<<endl;
}
-
Template Function
Code:
#include<iostream.h>
template < class T >
T Subtract ( T num1,T num2 )
{
if (num1>num2)
return num1-num2;
else
return num2-num1;
}
void main()
{
int i1,i2;
cout<<"Intagers :"<<endl;
cout<<"Enter 2 Integers :"<<endl;
cin>>i1>>i2;
cout<<"The Difference is : "<<Subtract(i1,i2)<<endl;
long l1,l2;
cout<<"Longs :"<<endl;
cout<<"Enter 2 Longs :"<<endl;
cin>>l1>>l2;
cout<<"The Difference is : "<<Subtract(l1,l2)<<endl;
float f1,f2;
cout<<"Floats :"<<endl;
cout<<"Enter 2 Floats :"<<endl;
cin>>f1>>f2;
cout<<"The Difference is : "<<Subtract(f1,f2)<<endl;
double d1,d2;
cout<<"Doubles :"<<endl;
cout<<"Enter 2 Doubles :"<<endl;
cin>>d1>>d2;
cout<<"The Difference is : "<<Subtract(d1,d2)<<endl;
}
-
:36_1_47: ذكرتنا بالمأسه ياوائل
بس والله متعب لغة باسكال اهون :regular_s
يعطيك العافيه على هالمجهود
-
وعليكم السلام ورحمه الله وبركاته
أخي الكريم (( وائل ))
تسلم على هالمجهود الرائع
على فكرة انا راح انزل المادة ( ++ C )
بالفصل الاول السنه الجاية
تقبل فائق تقديري واحترامي
ودمت بخير
أخوك / وحش جده
-
جهد رائع
ده مش شغل أسبوع ولا أتنين ده شغل شهور. :62_62:
ألف شكر أخي وائل علي المجهود والمساهمة .
والله انا كنت راح أكتب في موضوع أن مفيش قسم للغات البرمجة وكنت أتمني لو حاجة زي كده تتعمل ونقدر ننزل أكبر قدر من الشروح والعروض للتعليم وان شاء الله راح أكون أول المساهمين.
-
تسلم أخي وائل على هذا المرجع الطيب ..
لو في أي برنامج في رأسي .. سأجده هنا .. ممتاز ..
ربنا يوفقك..