:36_1_47: ذكرتنا بالمأسه ياوائل
بس والله متعب لغة باسكال اهون :regular_s
يعطيك العافيه على هالمجهود
Printable View
:36_1_47: ذكرتنا بالمأسه ياوائل
بس والله متعب لغة باسكال اهون :regular_s
يعطيك العافيه على هالمجهود
وعليكم السلام ورحمه الله وبركاته
أخي الكريم (( وائل ))
تسلم على هالمجهود الرائع
على فكرة انا راح انزل المادة ( ++ C )
بالفصل الاول السنه الجاية
تقبل فائق تقديري واحترامي
ودمت بخير
أخوك / وحش جده
ده مش شغل أسبوع ولا أتنين ده شغل شهور. :62_62:
ألف شكر أخي وائل علي المجهود والمساهمة .
والله انا كنت راح أكتب في موضوع أن مفيش قسم للغات البرمجة وكنت أتمني لو حاجة زي كده تتعمل ونقدر ننزل أكبر قدر من الشروح والعروض للتعليم وان شاء الله راح أكون أول المساهمين.
تسلم أخي وائل على هذا المرجع الطيب ..
لو في أي برنامج في رأسي .. سأجده هنا .. ممتاز ..
ربنا يوفقك..
مشكور اخواني على المرور........
The idea of the game is to guide your 'X' between to walls ("!").
Code:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <dos.h>
using namespace std;
char anyChar;
int ShowTunnel(int x, int y)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(hStdOut, pos);
cout << "!\n";
}
int ShowX(int x)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = 0;
SetConsoleCursorPosition(hStdOut, pos);
cout << "X\n";
}
int MoveRandom(int k)
{
k = rand() % 3;
}
int TunnelSpaces(int L)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = 0;
pos.Y = L;
SetConsoleCursorPosition(hStdOut, pos);
}
int MoveDownTunnel()
{
/* read from file w[0] to w[9] */
TunnelSpaces(0);
ShowTunnel(w[0], 0);
w[0] = w[1];
TunnelSpaces(1);
ShowTunnel(w[1], 1);
w[1] = w[2];
TunnelSpaces(2);
ShowTunnel(w[2], 2);
w[2] = w[3];
TunnelSpaces(3);
ShowTunnel(w[3], 3);
w[3] = w[4];
TunnelSpaces(4);
ShowTunnel(w[4], 4);
w[4] = MoveRandom(w[4]);
ShowTunnel(w[5], 0);
w[5] = w[6];
ShowTunnel(w[6], 1);
w[6] = w[7];
ShowTunnel(w[7], 2);
w[7] = w[8];
ShowTunnel(w[8], 3);
w[8] = w[9];
ShowTunnel(w[9], 4);
w[9] = MoveRandom(w[9]);
getch();
system("CLS");
}
int main()
{
system("title M!kk0'z TuNN3L");
int w[9];
w[0] = w[1] = w[2] = w[3] = w[4] = 1;
w[5] = w[6] = w[7] = w[8] = w[9] = 20;
/* print w[0] to w[9] to file */
MoveDownTunnel();
cout << "Okay, that's all for now folks...\n";
getch();
return 0;
}
Program raise to the power of n
Code:
#include<stdio.h>
float raise(float base, float power)
{
int ctr = 0;
float answer = 0;
answer = 1;
for(ctr = 0; ctr< power; ctr++)
{
answer = base * answer;
printf("\n%.2f",answer);
}
return answer;
}
main()
{
float finalAnswer = 0;
clrscr();
finalAnswer = raise(2,0);
printf("\n\n%.2f",finalAnswer);
getch();
}
how to output "0.0"
Code:#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double increment = 0.0;
fixed(cout);
for (int i = 0; i < 10; ++i) {
cout << "[" << setprecision(1) << increment <<
"..";
cout << (increment + 0.1) << ")" << endl;
increment += 0.1;
}
}
#define vs const
الفرق
/* according to ms, if you want definenum to workCode:#include <stdio.h>
#include <conio.h>
#define definenum 10 + 8 * 20
int const constnum = 10 + 8 * 20;
int main(void) {
char c;
clrscr();
printf("\n\n definenum = %d", definenum);
printf("\n constnum = %d", constnum);
// but!!
printf("\n\n definenum = %d", definenum * 2);
printf("\n constnum = %d", constnum * 2);
c = getch();
return 0;
}
correctly in the above, you can change it to:
(10 + 8) * 20, which shows how definenum is stored -
as a literal string by the pre-processor, "10 + 8 * 20" which is
numerically evaluated at run time.
Whereas constnum is stored as the number 170, not the
literal "10 + 8 * 20". */
دي مجموعة من برامج بلغة السي بلس بلس
السلام عليكم ورحمة الله وبركاته
لغة السي بلس بلس او اي لغة برمجة عبارة عن 4 أجزاء ومنها من له 3 أجزاء فقط.
الجزء الأول: وهو عبارة عن البرمجة ولكن كل شغلك بيكون علي الدوس وغالبا ما بيكون غير منظم بمعني ان انت بتعمل البرنامج بس انت مش عارف ده يتبع أي قسم أو أي جزء والجزء ده خاص بالمبتدئين في البرمجة في البداية فقط مش في البرمجة عموما.
الجزء الثاني: وهو الجزء الخاص بتنظيم البيانات و انت برده شغال علي الدوس بس يتكون عارف ان انت شغال في تنظيم البيانات أو (Data structure) وفي الجزء ده انت بتستخدم arrays, linked list etc ولكن شغلك كله بيضيع بمجرد انتهاء البرنامج قصدي البيانات مش البرنامج.
الجزء الثالث: وهو الجزء الخاص بالتعامل مع الملفات (file structure) وهو أصعب جزء علي الرغم من حلاوة الشغل اللي بيطلع بعد كده والنظام اللي فيه وسوف تشعر باستمتاع اذا كنت قد وصلت أو حتي تعرض للجزء ده.
أما الجزء الأخير: فهو الجزء الخاص بال visual وده غني عن التعريف يمكنك من العمل مع التأثيرات والخروج من شاشة الدوس والتعامل مع الApplets .
طبعا الكل نسي انا قلت ده كله ليه ,
كل ده لأن الجزء اللي انا راح أنزله خاص بال Data Structure.
ونبدأ ب linked list برنامج بيعمل نسخ لقائمة لأخري.
وده برنامج binary search by recursionCode:#include<iostream.h>
#include<assert.h>
typedef int listelem;
class list
{
private:
struct node;
typedef node *link;
struct node
{
listelem elem;
link next;
};
link head;
link tail;
link current;
public:
list();
void insert(listelem &elem);
bool first(listelem &elem);
bool next(listelem &elem);
node copylist(node headcopy);
};
list::list()
{
head=0;
tail=0;
current=0;
}
void list::insert(listelem &elem)
{
link addnode=new node;
assert(addnode);
addnode->elem=elem;
if(head==0)
head=addnode;
else
tail->next=addnode;
tail=addnode;
addnode->next=0;
}
bool list::first(listelem &elem)
{
if(head==0)
return false;
else
{
elem=head->elem;
current=head;
return true;
}
}
bool list::next(listelem &elem)
{
assert(current);
if(current->next==0)
return false;
else
{
current=current->next;
elem=current->elem;
return true;
}
}
/*node list::copylist(node headcopy)
{
listelem elem1;
while(
}*/
int main()
{
list l;
listelem i;
char ch;
cout<<"enter the list:";
do{
cin>>i;
l.insert(i);
cout<<"again:";
cin>>ch;
}
while(ch!='n');
listelem elem;
bool notempty=l.first(elem);
while(notempty)
{
cout<<elem<<endl;
notempty=l.next(elem);
}
cout<<endl;
return 0;
}
Code:#include<iostream.h>
int binsearch(int a[],int first,int last,int target)
{
if(first>last)
return -1;
int mid=(first+last)/2;
if(target==a[mid])
return mid;
else
if(target<a[mid])
return binsearch(a,first,mid-1,target);
else
return binsearch(a,mid+1,last,target);
}
int main()
{
int a1[10];
int i,t;//,f1,l1;
cout<<"enter the elemnt of your array:";
for(i=0;i<10;i++)
cin>>a1[i];
cout<<"enter the target:";
cin>>t;
cout<<"the index is:"<<binsearch(a1,0,9,t)<<endl;
return 0;
}
وده برده برنامج binary search
وده برنامج بيعمل recursisonCode:#include<iostream.h>
#include<process.h>
int searchin(int a[],int target,int len)
{
int first=0;
int last=len-1;
int mid;
while(first<=last)
{
mid=(first+last)/2;
if(target==a[mid])
{
return mid;
exit(0);
}
else if(target>mid)
last=mid-1;
else
first=mid+1;
}
}
int main()
{
int l=10;
int arr[10];
int t,i;
cout<<"enter the element of array:"<<endl;
for(i=0;i<10;i++)
cin>>arr[i];
cout<<"enter the target:";
cin>>t;
cout<<"the index of your target is:";
cout<<searchin(arr,t,l);
cout<<endl;
return 0;
}
وده برنامج بيعمل حذف لعنصر في array معين وبع عناصر معينة.Code:#include<iostream.h>
void recurision(int x)
{
int x2;
while(x>0)
{
x2=x/2;
recurision(x/2);
cout<<x2<<endl;break;
}
}
int main()
{
int x1;
cout<<"enter an element"<<endl;
cin>>x1;
recurision(x1);
cout<<endl;
return 0;
}
وده برنامج بيحسب المضروب factorial طبعا غني عن التعريفCode:#include<iostream.h>
void del(int a[],int &len,int pos)
{
int i,v;
if((pos<0)||(pos>=len))
cout<<"your deletion is not complete:";
v=a[pos];
for(i=pos+1;i<len;i)
{
a[i-1]=a[i];
len--;
}
}
int main()
{int l=10;
int arr[10]={19,18,17,16,15,14,13},p;
cout<<"enter the postition:";
cin>>p;
del(arr,l,p);
cout<<"the array after the deletion is:"<<endl;
for(int i=0;i<l;i++)
cout<<arr[i]<<endl;
cout<<endl;
return 0;
}
وده برنامج بيضيف عنصر في array بع عناصر معينة.Code:#include<iostream.h>
int fact(int n)
{
if(n<=1)
return 1;
else
return n*fact(n-1);
}
int main()
{
int num;
cout<<"enter the number:";
cin>>num;
cout<<"the factorial is:"<<fact(num)<<endl;
return 0;
}
وده برنامج بيعمل بحث في linear search )array ) بحث خطي.Code:#include<iostream.h>
void insert(int a[],int &len,int &pos,int value)
{
if((pos<0)||(pos>len)||(len-1>10))
{cout<<"your insertion is not complete";}
else
{
for(int i=len-1;i>=pos;i--)
{
a[i+1]=a[i];
a[pos]=value;
len--;
}
}
}
int main()
{ int l=10;
int arr[10]={2,5,4,8,9,7,6,9,6,7},p,v;
cout<<"enter the position and the value:"<<endl;
cin>>p>>v;
insert(arr,l,p,v);
cout<<"your insertion is complete :"<<endl;
for(int j=0;j<10;j++)
cout<<arr[j]<<endl;
return 0;
}
وده برنامج بيرتب عناصر أي arrayCode:#include<iostream.h>
#include<process.h>
int max=10;
int search(int a[max],int target)
{
int j;
for(j=0;j<n;j++)
if (a[j]==target)
return j;
else
return target;
}
int main()
{
int arr[max];
cout<<"enter the array:"<<endl;
for(int i=0;i<10;i++)
cin>>arr[i];
cout<<"enter the target:"<<endl;
int x;
cin>>x;
cout<< search(arr,10,x);
cout<<endl;
return 0;
}
ده برنامج بيعمل بحث بس لازم يكون الarray مرتب يعني sorted وده (binary search).Code:#include<iostream.h>
const int max=10;
void swap(int arr[],int a,int o)
{
int temp=arr[o];
arr[o]=arr[a];
arr[a]=temp;
}
int partition(int arr[],int first,int last)
{
int lastele=first;
for(int i=first+1;i<=last;i++)
{
if(arr[first]>=arr[i])
{
++lastele;
swap(arr,lastele,i);
}
}
swap(arr,first,lastele);
return lastele;
}
void quick(int arr[],int first,int last)
{
if(first>=last)return ;
int split=partition(arr,first,last);
quick(arr,first,split-1);
quick(arr,split+1,last);
}
int main()
{
int arr[max]={4,5,2,3,6,8,5,7,11,10};
quick(arr,0,max);
for(int j=0;j<max;j++)
cout<<arr[j]<<endl;
return 0;
}
كفاية كده وبعدين أكملكم شوية كمان بكره أو بعده.Code:#include<iostream.h>
#include<process.h>
int searchin(int a[],int target,int len)
{
int first=0;
int last=len-1;
int mid;
while(first<=last)
{
mid=(first+last)/2;
if(target==a[mid])
{
return mid;
exit(0);
}
else if(target>mid)
last=mid-1;
else
first=mid+1;
}
}
int main()
{
int l=10;
int arr[10];
int t,i;
cout<<"enter the element of array:"<<endl;
for(i=0;i<10;i++)
cin>>arr[i];
cout<<"enter the target:";
cin>>t;
cout<<"the index of your target is:";
cout<<searchin(arr,t,l);
cout<<endl;
return 0;
}
وأتمني أن أكون قد وفقت وأرجو منكم الدعاء لي ولوالدي وللمسلمين وللمسلمات جميعا.
مشكور اخي على التفاعل....
sorting from the keyboard
Code:
#include <stdio.h>
#include <stdlib.h>
main()
{
int size=n;
// You haven't told the compiler anything about 'n', yet. Is it an
int,
float, and what is it's value, here? :(
int i;
printf("Data items in original order\n");
scanf("%d", &size);
int a[N];
'N' is not the same thing as 'n', (not that the compiler has been
told anything about 'n', either. :)
for (i = 0; i < size; i++)
Since we don't know what 'n' is, and size = n, we also don't know
what value 'size' is.
scanf("%d", &a[i]);
for (i = 0; i <= size - 1; i++) // printing
numbers
from the keyboard
I don't understand why you changed from:
(i = 0; i < size;...) which seems simple, to
(i = 0; i <= size - 1;...) which seems inelegant.
printf("%4d", a[i]);
for (i = 0; i <= size - 1; i++) // randomizing
from
the computer
a[i]=rand();
for (i = 0; i <= size - 1; i++) // output from
the
randomizing
printf("%4d", a[i]);
qsort(array, n, sizeof *array, compare);
But what IS n?? And what's 'array' doing here?
int compare(const void *lv, const void *rv)
{
const int *li = lv;
const int *ri = rv;
return (*li > *ri) - (*li < *ri);
}
return 0;