البرنامج التاسع:
المضروب باستخدام while:
كود:#include <iostream.h> int main() { int i=1,num,fact=1; cout<<"Enter The Number: "; cin>>num; while(i<=num) { fact*=i;//fact=fact*i i++; } cout<<"Factorial = "<<fact<<endl; return 0; }
- الإهدائات >> | |
إضافه إهداء |
البرنامج التاسع:
المضروب باستخدام while:
كود:#include <iostream.h> int main() { int i=1,num,fact=1; cout<<"Enter The Number: "; cin>>num; while(i<=num) { fact*=i;//fact=fact*i i++; } cout<<"Factorial = "<<fact<<endl; return 0; }
البرنامج العاشر:
برنامج يطلب من المستخدم إدخال مجموعة من الأعداد تنتهي بالصفر ثم يقوم بحساب المتوسط لهذه الأعداد وإذا صادف عدد سالب فإنه يتجاهله ولايضعه في الحسبان باستخدام Continue ثم يكمل العملية:
كود:#include<iostream.h> int main() { int x,sum=0,count=0; cout<<"Enter the numbers : "<<endl; for (;;) { cin>>x; count+=1; if (x<0) { count-=1; continue; } else sum=sum+x; if(x==0) { count-=1; break; } } cout<<"The Avarege = "<<sum/count<<endl; return 0; }
البرنامج الحادي عشر:
برنامج يحسب المساحة والحجم لبعض الأشكال الهندسية..
كود:#include<iostream.h> void Square(); void Rectangle (); void Triangle (); void Circle (); int main() { int choice; do { cout<<"\t \t ---------- Main Menu ---------- "<<endl<<endl; cout<<"\t1-The Square Area && Square Volume."<<endl; cout<<"\t2-The Rectangle Area && Rectangle Volume."<<endl; cout<<"\t3-The Triangle Area."<<endl; cout<<"\t4-The Circle Area && Circumfrence."<<endl; cout<<"\t5-Quit."<<endl<<endl; cout<<"\t\t *******************************"<<endl<<endl; cout<<"Enter your choice: "; cin>>choice; switch (choice) { case 1: Square(); break; case 2: Rectangle (); break; case 3: Triangle (); break; case 4: Circle (); break; case 5: cout<<"Thank you."<<endl; break; default: cout<<"Try again."<<endl; } } while (choice !=5); return 0; } //********************************************** void Square() { float S_length,S_area,S_volume; cout<<"Enter the Square length: "; cin>>S_length; S_area = S_length * S_length; S_volume = S_length * S_length * S_length; cout<<"The Square Area = "<<S_area<<endl; cout<<"The Square Volume = "<<S_volume<<endl; } //********************************************** void Rectangle () { float R_length,R_width,R_height,R_area,R_volume; cout<<"Enter the Rectangle length: "; cin>>R_length; cout<<"Enter the Rectangle width: "; cin>>R_width; cout<<"Enter the Rectangle height: "; cin>>R_height; R_area = R_length * R_width; R_volume = R_length * R_width * R_height; cout<<"The Square Area = "<<R_area<<endl; cout<<"The Square Volume = "<<R_volume<<endl; } //********************************************** void Triangle () { double T_base,T_height,T_area; cout<<"Enter the Triangle base: "; cin>>T_base; cout<<"Enter the Triangle height: "; cin>>T_height; T_area = 0.5 * T_base * T_height; cout<<"The Triangle Area = "<<T_area<<endl; } //********************************************** void Circle () { double C_radius,C_area,Circumfrence; const double T = 3.14; cout<<"Enter the Circle radius:"; cin>>C_radius; C_area= T * C_radius * C_radius; Circumfrence= 2 * T * C_radius; cout<<"The Square Area = "<<C_area<<endl; cout<<"The Circumfrence = "<<Circumfrence<<endl; } //**********************************************
البرنامج الثاني عشر:
برنامج يقوم بحساب مساحة المستطيل عن طريق استدعاء بروسيجر آخر يقوم بالحساب..
كود:#include<iostream.h> float cal(float length,float width); void main() { float length,width,area; cout<<"Enter the rectangle length:"; cin>>length; cout<<"Enter the rectangle width:"; cin>>width; area=cal(length,width); cout<<"Rectangle Area = "<<area<<endl; } float cal(float length,float width) { float w; w = length * width; return w; }
البرنامج الثالث عشر:
برنامج تقوم انت بإدخال أسمك ثم يقوم هو بطباعة عبارة ترحيبيه يظهر فيه اسمك الذي ادخلته.
كود:#include <iostream> #include <string> using namespace std; int main() { string name; cout<<"Enter your name: "; cin>>name; cout<<"Hello "<<name<<endl; return 0; }
البرنامج الرابع عشر:
المصفوفه..array
أشجع نفسي..كود://array #include<iostream> using namespace std; /////////////////////////////////// int main() { int arr[100]; int nElems=0; int j; int searchkey; //------------------------------ arr[0]=33; arr[1]=55; arr[2]=11; arr[3]=23; arr[4]=66; arr[5]=99; arr[6]=77; arr[7]=00; arr[8]=25; arr[9]=22; nElems=10; //------------------------------- for (j=0;j<nElems;j++) cout<<arr[j]<<" "; cout<<endl; //-------------------------------- searchkey=66; for (j=0;j<nElems;j++) if (arr[j]==searchkey) break; if (j==nElems) cout<<"Can't find "<<searchkey<<endl; else cout<<"Found "<<searchkey<<endl; //--------------------------------- searchkey=55; cout<<"Deleting "<<searchkey<<endl; for (j=0;j<nElems;j++) if (arr[j]==searchkey) break; for (int k=j;k<nElems;k++) arr[k]=arr[k+1]; nElems--; //-------------------------------------- for (j=0;j<nElems;j++) cout<<arr[j]<<" "; cout<<endl; return 0; }
السلام عليكم
مشاء الله جهدك واضح
بس عندي طلب لو مافيها تعب
ممكن تضيفي الـ "output"...
بس الموضوع ولا احسن ..
ارق الاماني بكل جميل
و وجدت نفسي أنتهي.. و غدت حياتي كالضباب
أسير فيها.. كالغريب .. و نسيت أني كنت يوما شاعرا
و بأن حبي كان في الأعماق بحرا ثائرا
لا شيء عندي
غير ذكرى.. أو حكايات قديمة ..أو همسة مرت مع الأيام
أو شكوى.. عقيمة ..أو دمعة تهتز في عيني
و يخفيها نداء.. الكبرياء..أو بسمة كانت تحلق
في حياتي.. كالضياء.. ماذا أقول و أنت يا قلبي تموت
عد للحياة
هلا أخوي..
أول شي أشكرك لأنك متابع الموضوع معاي.. ..توي أحس انه فيه أحد متابع الموضوع معاي..
وثاني شي أبحاول إن شاءالله انزل لك Output..لانه من الحين وورى رح يصير ال Output طويل شوي..لكن اذا قدرت إن شاءالله ماراح أقصر..
بس ودي أعرف اذا فيه برنامج سابق ودك أعطيك ال Output حقه..أنا مستعده..
حدد لي رقم البرنامج وانا جاهزة...
ألف ألف شكر لك ولمرورك اللي أسعدني بصراحه..
واذا عندك أي ملاحظات ثانيه أتقبلها منك بكل صدر رحب..
تحياااتي لك..
البرنامج الخامس عشر:
المصفوفة بإستخدم الكلاس:
مثلا هذا البرنامج أخوي shadow hearts صعب أني أجيب لك ال output لأنه طويل..كود:#include<iostream> #include<vector> using namespace std; ////////////////////////////////////////////////////// class Array { private: vector<double>v; int nElems; public: //------------------------------------------------ Array() :nElems(0) { } //------------------------------------------------ Array(int max):nElems(0) { v.resize(max); } //------------------------------------------------ bool find(double searchkey) { int j; for(j=0;j<nElems;j++) if(v[j]==searchkey) break; if(j==nElems) return false; else return true; } //------------------------------------------------ void insert(double value) { v[nElems]=value; nElems++; } //------------------------------------------------ bool remove(double value) { int j; for(j=0;j<nElems;j++) if (value == v[j]) break; if(j==nElems) { cout<<"Can't find "<<value<<endl; return false; } else { for(int k=j;k<nElems;k++) v[k]=v[k+1]; nElems--; cout<<"Deleting "<<value<<endl; return true; } } //------------------------------------------------ void display() { for(int j=0;j<nElems;j++) cout<<v[j]<< " "; if (nElems == 0) cout<<"No elements"<<endl; cout<<endl; } //------------------------------------------------ };//end class Array ///////////////////////////////////////////////////////////// int main() { int maxSize=100; int choice,element,searchkey,deletkey; Array arr(maxSize); do { cout<<"\t1-Adding a new element."<<endl; cout<<"\t2-Search for an element."<<endl; cout<<"\t3-Delete any element."<<endl; cout<<"\t4-Display the elements."<<endl; cout<<"\t5-Ending the program."<<endl<<endl; cout<<"Enter your choice:"; cin>>choice; cout<<endl; switch (choice) { case 1: cout<<"Enter the element:"; cin>>element; arr.insert(element); cout<<endl; break; case 2: cout<<"Enter the searchkey:"; cin>>searchkey; if(arr.find(searchkey)) cout<<"Found "<<searchkey<<endl; else cout<<"Can't find "<<searchkey<<endl; cout<<endl; break; case 3: cout<<"Enter the deletkey:"; cin>>deletkey; arr.remove(deletkey); cout<<endl; break; case 4: arr.display(); cout<<endl; break; case 5: cout<<"Thank you"<<endl<<endl; break; default: cout<<"Try again"<<endl<<endl; break; } } while (choice != 5); return 0; }
لكن فيه حل..أنت ممكن تعطيني ال input و ال output في البرامج اللي تشك فيها..وأنا رح أدخلها عندي ونقارن النتائج في النهاية..ماأدري وش رايك؟؟
تحياااتي لكم جميعاً..
اول شكرا على ردك السريع
وبعدين انا الحمد لله خلصت لغت السي بلس بلس من سنه ..
والسي شارب بقيلها كام اسبوع وانتهي منه ...
لان اجرب راندوم يعني ما افتكر رقم البرنامج الي فيه المشكله
وان شاء الله لو حصلت اي مشكله برسلك input و output البرنامج الي انا شاكك فيه
موضوعك متعوب عليه
معاكي للنهايه..
أرق الاماني بكل جميل
العفو أخوي..
ومبروووووك على أنك خلصت السي بلس بلس
وعقبال السي شارب..وإن شاءالله بتفوق..
أوكي..مثل ماتفضلت أي برنامج تلقى فيه مشكلة أعطني ال input و ال output
وأنا ادخلها عندي ونقارن ال output
وهالكلام برضوه لباقي الأعضاء..
الف ألف شكر لك على ردك ومرورك ومتابعتك..
تحيااتي لك..
البرنامج السادس عشر:
stack
كود:#include <iostream> #include <vector> using namespace std; //<<<<<<<<<<<<<<<<<<< class Stack { private: int maxSize; vector<double> stackV; int top; public: Stack(int s) : maxSize(s), top(-1) { stackV.resize(maxSize); } //------------------------ void push (double j) { stackV[++top]=j; } //---------------------------- double pop() { return stackV[top--]; } ///------------------- double peek() { return stackV[top]; } ///------------------- bool isEmpty() { return(top==-1); } //--------------------------- bool isFull() { return (top==maxSize-1); } }; //---------------------------- int main() { int choice; char x; Stack theStack(100); while (choice != 4) { cout<<"\t\t1-Add a new number.\n"; cout<<"\t\t2-Remove a number.\n"; cout<<"\t\t3-Display all the numbers in stak.\n"; cout<<"\t\t4-Quit.\n\n"; cout<<"\tEnter your choice:"; cin>>choice; switch(choice) { case 1: double num; while (! theStack.isFull() ) { cout<<"Enter the number: "; cin >>num; theStack.push(num); cout<<"Are you finish??(Y,N): "; cin>>x; if ((x=='Y') ||(x=='y')) break; if (theStack.isFull()) cout<<"The stak is Full !! "<<endl; } break; case 2: double removnum; removnum=theStack.pop(); cout<<"Remov "<<removnum<<endl; if (theStack.isEmpty()) cout<<"The stak is Empty !! "<<endl; break; case 3: if (theStack.isEmpty()) cout<<"The stak is Empty !! "<<endl; else cout<<theStack.peek()<<endl; break; case 4: cout<<"Thank you "<<endl; break; default: cout<<"Try again!!"<<endl; break; } } return 0; }
البرنامج السابع عشر:
queueكود:#include <iostream.h> #include <vector> using namespace std; /////////////////////// class Queue { private: int maxSize; vector<int> queVect; int j; int front; int rear; int nItems; public: Queue(int s) :maxSize(s), front(0),rear(-1),nItems(0) { queVect.resize(maxSize); } //-------------------------------------------------------- void Insert(int j) { if (rear==maxSize-1) rear=-1; queVect[++rear]=j; nItems++; } //------------------------------------------------- int remove() { int temp=queVect[front++]; if (front==maxSize) front=0; nItems--; return temp; } //-------------------------------------------- int peekFront() {return queVect[front];} //--------------------------------------------- bool isEmpty() {return (nItems==0);} //------------------------------------------- bool isFull() {return (nItems==maxSize);} //------------------------------------------ int size() {return nItems;} }; //------------------------------------------------ int main() { Queue theQueue(100); double value; int choice; int element; int num; int a; do { cout<<"\n\t Tha MAIN MENU \n"; cout<<"\t1-Insert the element\n"; cout<<"\t2-display the first element\n"; cout<<"\t3-display number of elements\n"; cout<<"\t4-remove the element\n"; cout<<"\t5-Quit\n"; cout<<"Enter your choice:"; cin>>choice; switch(choice) { case 1: cout<<"Enter the element:"; cin>>value; theQueue.Insert(value); break; case 2: element=theQueue.peekFront(); cout<<"the first element: "<<element<<endl; break; case 3: num=theQueue.size(); cout<<"numbers of elements: "<<num<<endl; break; case 4: if(theQueue.isEmpty()) break; a=theQueue.remove(); cout<<a<<" "<<endl; break; case 5: cout<<"Thank you.\n"; break; default: cout<<"Try again!!"; } } while (choice!=5); return 0; }
ألم تر أنَّ الله خلّـَد ذكـره *** إذ قال في الخمس المؤذن: أشهـدوشـقّ له من اسمه ليجلــه *** فذو العرش محمود وهذا محمــداللهم صلى وسلم على خاتم الانبياء والمرسلين نبي الرحمة محمد صلى الله عليه وسلم تسلميا كثيراً..اللهم اغفر للمسلمين والمسلمات الأحياء منهم والأموات وارحمهم اللهم آمين..
البرنامج الثامن عشر..
bubbleSort
كود:#include <iostream.h> #include<vector> using namespace std; //---------------------------------- class ArrayBub { private: vector<double>v; int nElems; //---------------------------------- void swap(int one,int two) { double temp=v[one]; v[one]=v[two]; v[two]=temp; } //---------------------------------- public: //---------------------------------- ArrayBub(int max):nElems(0) { v.resize(max); } //---------------------------------- void insert() { double value; for(;;) { cout<<"Enter the number ,when you finished press zero :"; cin>>value; if (value ==0) break; v[nElems]=value; nElems++; } } //---------------------------------- void display() { for (int j=0;j<nElems;j++) cout<<v[j]<<" "; cout<<endl; } //--------------------------------- void bubbleSort() { int out,in; for(out=nElems-1;out>1;out--) for(in=0;in<out;in++) if(v[in]>v[in+1]) swap(in,in+1); } //--------------------------------- }; //////////////////////////////////// int main() { int maxSize=100; ArrayBub arr(maxSize); arr.insert(); arr.display(); arr.bubbleSort(); arr.display(); return 0; }
البرنامج التاسع عشر:
Linked Lists
كود:#include<iostream> using namespace std; //------------------------ class Link { public: int iData; double dData; Link* pNext; //---------------------------------------- Link(int id,double dd) : iData(id),dData(dd),pNext(NULL) { } //-------------------------------------------- void displayLink() { cout<<"{"<<iData<<"}"; } }; //--------------------------------------------- class LinkList { private: Link* pFirst; public: //--------------------------------------------- LinkList() :pFirst(NULL) { } //---------------------------------------------- ~LinkList() { Link* pCurrent=pFirst; while(pCurrent!= NULL) { Link* pOldCur=pCurrent; pCurrent=pCurrent->pNext; delete pOldCur; } } //-------------------------------------------- void insertFirst(int id,double dd) { Link* pNewLink= new Link(id,dd); pNewLink->pNext=pFirst; pFirst=pNewLink; } //------------------------------------------- Link* find(int key) { Link* pCurrent=pFirst; while(pCurrent->iData!= key) { if(pCurrent->pNext==NULL) return NULL; else pCurrent=pCurrent->pNext; } return pCurrent; } //------------------------------------------- bool remove(int key) { Link* pCurrent=pFirst; Link* pPrevious=pFirst; while(pCurrent->iData!= key) { if(pCurrent->pNext==NULL) return false; else { pPrevious=pCurrent; pCurrent=pCurrent->pNext; } } if(pCurrent==pFirst) pFirst=pFirst->pNext; else pPrevious->pNext=pCurrent->pNext; delete pCurrent; return true; } //------------------------------------- void displayList() { cout<<"List(first - - > last ):"; Link* pCurrent=pFirst; while(pCurrent!=NULL) { pCurrent->displayLink(); pCurrent=pCurrent->pNext; } cout<<endl; } }; //------------------------------------------------ int main() { LinkList theList; int choice; double value; do { cout<<"\n\t Tha Main Menu \n"; cout<<"\t1-Insert student\n"; cout<<"\t2-Remove student\n"; cout<<"\t3-Search about student\n"; cout<<"\t4-display students\n"; cout<<"\t5-Quit\n"; cout<<"Enter your choice:"; cin>>choice; switch(choice) { case 1: cout<<"Enter the ID of student: "; cin>>value; theList.insertFirst(value,0); break; case 2: cout<<"Enter the ID of student: "; cin>>value; if(theList.remove(value)) cout<<"Removed link with key "<<value<<endl; else cout<<"Can't remove student"<<endl; break; case 3: cout<<"Enter the ID of student: "; cin>>value; if(theList.find(value)!=NULL) cout<<"Found link with key "<<theList.find(value)->iData<<endl; else cout<<"Can't find student "<<endl; break; case 4: theList.displayList(); break; case 5: cout<<"Thank you.\n"; break; default: cout<<"Try again!!"; } } while (choice != 5); return 0; }
الذين يشاهدون الموضوع الآن: 1 (0 من الأعضاء و 1 زائر)