الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مسألة في ++c كتبت الاكواد .. واريد تحويلها الى دوال

بدأه .. قلم رصاص .. في 27 مايو 2011 · 7 رد · 1,146 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم اخواني اخواتي :happy:

انا من متابعين المنتدى ومن المستفيدين من برامجكم ومشاركتكم الفعاله

واليوم هذي اول مشاركه لي واتمنى القى تفاعل معاي في حل السؤال

السؤال في لغة ++c فيجول ستديو

بس حليت نص السؤال لكن بقى الجزء الثاني واريد مساعدتكم الفاضله اساتذتي الكرام .

لكم السؤال اولا اعزائي

فالبرنامج يقوم بأدخال عمر الطلاب أقل من ويساوي 8 سنوات وأكبر من ويساوي 6

يكون مسموح له العمليات:

1)علاقات الأرقام

2)ترتيب الأرقام من الأصغر إلى الاكبر

إذا كان العمر للطلاب أكبر من 8 وأقل من يساوي 10 يسمح له ب:

1)علاقات الأرقام

2)ترتيب الأرقام من الأصغر إلى الاكبر

3)جدول الضرب

4)عملية الجمع

5) الطرح

إذا كان العمر أكبر من 10 يسمح له ب:

1)علاقات الأرقام

2)ترتيب الأرقام من الأصغر إلى الاكبر

3)جدول الضرب

4)عملية الجمع

5)الطرح

6)عملية القسمة

7)حساب القوى

8)حساب الجذر التربيعي

المطلوب اساتذتي :happy:

رسم المخطط الأنسابي وكتابة كود C للبرامج 8 مع بعد تحويلها لدوال فرعية بالأضافة إلى 3 دوال menu1 لعرض قائمة العمليات المتاحة للطلاب بعمر أقل من ويساوي 8 سنوات وأكبر من ويساوي 6 و manu2 لعرض قائمة العمليات المتاحة للطلاب أكبر من 8 وأقل من يساوي 10و menu3 لعرض قائمة العمليات المتاحة للطلاب أكبر من 10

الان انا سويت البرامج الثمانيه كلها راح اعرضها لكم

بس ابي مساعده في تحويلها لدوال

ارجوكم :)

#2

انا قلت اني حليت الجزء الاول من السؤال وهو كتابة كود العمليات الحسابيه ...

وهذه هي الاكواد

1- كود علاقات الارقام ....

#include <iostream>
using namespace std;
int main (void)
{
int x,y;
cout << "Enter two num "<< endl;
cin >> x >> y ;

if ( x > y){
cout <<x << " > " << y << endl;
}
else{
if ( x < y ){
cout << x << " < " << y << endl;
}
else
{
x == y ;
cout << x << " = " << y << endl;
}
}
return 0;
}

2- كود ترتيب الارقام تصاعديا

#include<iostream>
using namespace std;
int main(){
int num [10], z ,t;
cout << "Enter the numbers: " << endl;
for (z=0; z<10; z++)
{
cin >> num[z];
}
for (int s=0; s<=8; s++)
{
for (int y=0; y<=9; y++)
{ if(num>num[y])
{
t=num;
num=num[y];
num[y]=t;
}
}
}
cout << "The result is : "<<endl;
for (z=0;z<10;z++)
{
cout <<num[z]<<endl;
}
return 0;
}

3- جدول الضرب

#include <iostream>
using namespace std;
int main ()
{
float x;
int z , s, c=0;
cout << "enter a number \n ";
cin >> x;
cout << "the multiplication table start from 1 to: \n ";
cin >> s;
while (c<s)
{
c++;
z=x*c;
cout << x<<"*"<<c<< "="<< z << endl;
}
return 0;
}

4- القسمه

#include <iostream>
using namespace std;
int main ()
{
float x, y,z;
char c ;
do {
cout <<"enter 2 number \n "<<"x= ";
cin >> x;
cout << "y= ";
cin >> y;
z = x/y;
cout << "x/y= " << z << endl;
}
while(c='y');
return 0;
}

5-الجمع والطرح

#include <iostream>
using namespace std;
int main ()
double x, y, z;
int s;
cout << " enter the number of the operation" << endl;
cout << "1- add" << endl;
cout << "2- sub" << endl;
cin >> s;
cout << "inter 2 number \n";
cin >> x >> y ;
switch(s)
{
case 1:
z=x+y;
cout << "x+y= \n";
break;
case 2:
z=x-y;
cout << "x-y= \n";
break;
}
cout << z << endl;
return 0;
}

6- حساب القوى

#include <iostream>
#include <cmath>
using namespace std;
int main(){
float num,p;
char c;
do
{
cout<<"enter a number";
cin>> num;
cout<<"enter the power";
cin>> p;
cout<<"the result is "<< pow(num,p)<<endl;
}
while(c='y');
return 0;
}

7- حساب الجذر التربيعي ..

#include <iostream>
#include <cmath>
using namespace std;
int main (void)
{
float a, s;
char c;
do
{
cout << " Enter number: ";
cin >> 
s = sqrt(a) ;
cout << " square = " << s << endl;
}
while(c='y');
return 0;
}

الان اريد مساعدتكم في الاكمال :happy:

#3

:mellow: ليش ما في احد رد :wacko: لهالدرجه صعب !

#4

طيب يا جماعه انا قاعده اكلم نفسي .... :wacko:

اوكي انا حاولت بس ماقدرت اوصل للمطلوب ..

حلي صح

بس مب هو المطلوب .. ياريت بس تصلحون لي الخطأ .. :huh: الله يخليكم ..

شوفوا هذا الكود

:)

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int compare ()
{
    //compare
int x,y;
cout << "Enter two num "<< endl;
cin >> x >> y ;

if ( x > y){
cout <<x << " > " << y << endl;
}
else if ( x < y ){
cout << x << " < " << y << endl;
}
else
{
cout << x << " = " << y << endl;

}
return 0;
}



//2- كود ترتيب الارقام تصاعديا


int sort(){
int num [10], z ,t;
cout << "Enter the numbers: " << endl;
for (z=0; z<10; z++)
{
cin >> num[z];
}
for (int s=0; s<=9; s++)
{
for (int y=0; y<=8; y++)
{ if(num[y]>num[y+1])
{
t=num[y];
num[y]=num[y+1];
num[y+1]=t;
}
}
}
cout << "The result is : "<<endl;

for (z=0;z<10;z++)
{
cout <<num[z]<<" ";
}
cout <<endl;
return 0;
}



//3- جدول الضرب


int mult ()
{
int x;
int z , s, c=0;
cout << "enter a number \n ";
cin >> x;
cout << "the multiplication table start from 1 to: \n ";
cin >> s;
while (c<s)
{
c++;
z=x*c;
cout << x<<"*"<<c<< "="<< z << endl;
}
return 0;
}


//4- القسمه


int div ()
{
float x=0, y=0,z=0;


std::cout <<"enter 2 number \n "<<"x= ";
std::cin >> x;
std::cout << "y= ";
std::cin >> y;
if(y==0){
     cout <<"illegal div, enter another value for y"<<endl;
}
z = x/y;
std::cout << "x/y= " << z << endl;


return 0;
}


//5-الجمع والطرح

int add (){
double x, y, z;

cout << "inter 2 number \n";
cin >> x >> y ;
z=x+y;
cout << x << "+" << y<< "="<< z << endl;
return 0;
}

 int sub (){
double x, y, z;
cout <<  "inter 2 number "<< endl;
cin >> x >> y ;
z=x-y;
cout << x<<"-"<< y<<"="<< z << endl;
return 0;
}

//6- حساب القوى



int power(){
float num,p;


cout<<"enter a number"<<endl;
cin>> num;
cout<<"enter the power"<<endl;
cin>> p;
cout<<"the result is "<< pow(num,p)<<endl;


return 0;
}


//7- حساب الجذر التربيعي .. 


int sqroot (void)
{
float a=0, s=0;

cout << " Enter number: ";
cin >> s;
s = std::sqrt(a) ;
cout << " square = " << s << endl;

return 0;
}

int main(){
    int age;
    string op;
    bool exit=false;
    while(!exit){
    cout<<"enter the age : "<<endl;
       cin >> age;

       if(age >= 6 && age <= 8){

           cout<<"please choose from the following operations: "<<endl;
               cout<<"compare or sort ? "<<endl;
               cin >> op ;

             if(op=="sort"){
                sort();
            }

             if(op=="compare"){
                compare();
            }

       }
       else if(age > 8 && age <= 10){

           cout<<"please choose from the following operations: "<<endl;
               cout<<"compare , sort , mult , add , sub ?"<<endl;
               cin >> op ;
                   if(op=="mult"){
                mult();
            }
               if(op=="compare"){
                compare();
            }
               if(op=="sub"){
                sub();
            }
              if(op=="add"){
                add();
            }
              if(op=="sort"){
                sort();
            }

       }
              else if( age > 10){

           cout<<"please choose from the following operations: "<<endl;
               cout<<"compare , sort , mult , add , sub ,  sqrt , div , pow ? "<<endl;
               cin >> op ;
                 if(op=="mult"){
                mult();
            }
          if(op=="compare"){
                compare();
            }
              if(op=="sub"){
                sub();
            }
            if(op=="add"){
                add();
            }
           if(op=="sort"){
                sort();
            }

           if(op=="pow"){
                power();
            }
          if(op=="sqrt"){
                sqroot();                                  
            }
          if(op=="div"){
                div();                                  
            }

       }
           else {

                cout<<"illegal age "<<endl;

           }

    }
    return 0;
}

بس الحين المطلوب اني اسوي menu1 ,2 ,3 واستخدم swetch

بس كيف ؟ ممكن احد يساعدني ..

انا حليت كل شي بس بعض التعديلات ارجوكم

الله يجزيكم الخير :happy:

#5

السلام عليكم ,

عدلت على كودج , بس للأمانه ما شيكت على كل الحالات للتأكد من صحة النواتج , (يقولون عندي إمتحان اليوم :D) .

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

void compare ()
{
int x,y;
cout << "Enter two num "<< endl;
cin >> x >> y ;
if ( x > y)
cout <<x << " > " << y << endl;
else if ( x < y )
cout << x << " < " << y << endl;
else
cout << x << " = " << y << endl;
}



//2- كود ترتيب الارقام تصاعديا


void sort(){
int num [10], z ,t;
cout << "Enter the numbers: " << endl;
for (z=0; z<10; z++)
cin >> num[z];
for (int s=0; s<=9; s++)
{
for (int y=0; y<=8; y++)
 if(num[y]>num[y+1])
{
t=num[y];
num[y]=num[y+1];
num[y+1]=t;
}

}
cout << "The result is : "<<endl;

for (z=0;z<10;z++)
{
cout <<num[z]<<" ";
}
cout <<endl;
}



//3- جدول الضرب


void mult ()
{
int x;
int z , s, c=0;
cout << "enter a number \n ";
cin >> x;
cout << "the multiplication table start from 1 to: \n ";
cin >> s;
while (c<s)
{
c++;
z=x*c;
cout << x<<"*"<<c<< "="<< z << endl;
}
}


//4- القسمه


void div ()
{
float x=0, y=0,z=0;
std::cout <<"enter 2 number \n "<<"x= ";
std::cin >> x;
std::cout << "y= ";
std::cin >> y;
if(y==0){
     cout <<"illegal div, enter another value for y"<<endl;
}
z = x/y;
std::cout << "x/y= " << z << endl;
}


//5-الجمع والطرح

void add (){
double x, y, z;
cout << "inter 2 number \n";
cin >> x >> y ;
z=x+y;
cout << x << "+" << y<< "="<< z << endl;
}

 void sub (){
double x, y, z;
cout <<  "inter 2 number "<< endl;
cin >> x >> y ;
z=x-y;
cout << x<<"-"<< y<<"="<< z << endl;
}

//6- حساب القوى
void power(){
float num,p;
cout<<"enter a number"<<endl;
cin>> num;
cout<<"enter the power"<<endl;
cin>> p;
cout<<"the result is "<< pow(num,p)<<endl;
}


//7- حساب الجذر التربيعي .. 


void sqroot ()
{
float a=0, s=0;
cout << " Enter number: ";
cin >> s;
s = std::sqrt(a) ;
cout << " square = " << s << endl;
}

void menu1(){
	int ch ;
 cout<<"Please choose from the following operations: "<<endl;
               cout<<"1-compare\n2-sort"<<endl;
               cin >>ch ;
switch (ch)
{
case 1:compare ();break ;
case 2:sort() ; break ;
default :cout<<"Error !" ;
}
}
void menu2(){
	int ch ;
 cout<<"Please choose from the following operations: "<<endl;
               cout<<"1-compare\n2-sort\n3-mult\n4-add\n5-sub"<<endl;
               cin >>ch ;
switch (ch)
{
case 1:compare ();break ;
case 2:sort() ; break ;
case 3:mult();break ;
case 4:add() ; break ;
case 5:sub(); break ;
default :cout<<"Error !" ;
}
}
void menu3(){
	int ch ;
 cout<<"Please choose from the following operations: "<<endl;
               cout<<"1-compare\n2-sort\n3-mult\n4-add\n5-sub\n6-div\n7-pow\n8-sqrt "<<endl;
               cin >>ch ;
switch (ch)
{
case 1:compare ();break ;
case 2:sort() ; break ;
case 3: mult();break ;
case 4:add(); break ;
case 5: sub(); break ;
case 6:div();break ;
case 7:power();break ;
case 8:sqroot();  break ;
default :cout<<"Error !" ;
}
}
int main(){
    int age;
	cout<<"Enter Your Age : " ; cin >> age ;
       if ((age >= 6) && (age <= 8))
		   menu1(); 
       else if ((age > 8) && (age <= 10))
           menu2();
       else if( age > 10)
           menu3();
       else        
         cout<<"illegal age "<<endl;
	   system("pause"); 
	   return 0 ;
}

امم عندج خطأ لو قارنتي بهالشكل :

 if(op=="sqrt")

موفقه عزيزتي :happy:

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#6

:lol: هذي الناس اللي اشرح الصدر

مب عارفه شلون اشكرج عزيزتي

بصراحه انقذتيني .. الله يوفقج بالامتحان ان شالله وتاخذين full mark :wub:

ايه انا عدلت عليه انتبهت له بعدين ..

بس بغيته يتكرر سؤال العمر .. :blush:

وين احط while ?

وتسلم يدج حبيبتي .. ماقصرتي ..

الله يوفقج وييسر امرج .. :happy:

#7
اقتباس
بس بغيته يتكرر سؤال العمر .. :blush:

وين احط while ?

الجزء المراد تكراره نضمنه داخل الـ loop , تسألين المستخدم هل تريد الأستمرار ام لا ؟

char answer = 'y' ;
	do{   
	cout<<"Enter Your Age : " ; cin >> age ;
    if ((age >= 6) && (age <= 8))
		   menu1(); 
       else if ((age > 8) && (age <= 10))
           menu2();
       else if( age > 10)
           menu3();
       else 
         cout<<"illegal age "<<endl;
	cout<<"Are you want to continue ? Y/N " <<endl;
	cin >> answer ;
	}while (answer=='y');

ان شاء الله يكون المطلوب ..

بالتوفيق :happy: ,

سبحآن الله وبحمده .. سبحآن الله العظيم .. ,

#8

ايه هذا هووو ..

تسلم الايادي :wub:

يعطيج الف عافيه ..

الله لايحرمنا من هالعلم :happy:

كل الود .....

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…