المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : a function mneu_option() ..... مسألة في C++



أميرة الوفاء
17-11-2007, 02:33 PM
السلام عليكم ورحمة الله وبركاته


عندي مسألة منغلقة شوي..:33:


هذي المسألة أتركها للأعضاء يعني :1zhelp: :1zhelp: :1zhelp:


وخصوصا ل
:biggthumpUUNUU
جزاه الله خيرا ما قصر فاللي قبله وفهمناه عدل:09:
نترككم للمسألة :biggthump

Write a C++ program which calls a function mneu_option() that displays the following program menu:

http://www3.0zz0.com/2007/11/17/12/99495487.jpg

- The function should return the user choice to the program.
-The program should keep displaying the menu until the user chooses to exit by selecting option 4.
Each menu item would correspond to on of the following functions :
(a) A void function prim_num(a,b), which lists all prime number between integers a,b (a prime number is the number that is divisible by 1 and by itself only).
(b) A double function pi(n), which returns the value of approximated to n terms, where


or :
(c) A void function rev_order(k), which reverses the order of the digits of an integer number. The main program should print the integer number in a reverse order (ex: 57249 ---à 94275).

(2) A void function Analysis(), which reads the contents of an input file and prints some analysis about the file contents in the following form :

Number of lines :
Number of capital letters :
Number of small letters :
Number of digits :
Other symbols :

(3) A bool function search(str), which gets some string from the program and searches this string for some word. The function should return true if the word is included in the string, false otherwise. If the searching was successful, the function should replace this word in the string with capital letters. The main program then prints the string after this replacement.


وسلامتكم .. هذي المسألة اهداء خاصة ل
UUNUU :biggthump


واللي يتكرم منكم الطيبين بعد ترانا نستقبل;)


سأعود للنقاش في المسألة معكم:31:


:flybye:

علي جنيدي
17-11-2007, 06:36 PM
ماهي شروط اللعب توابع بنى أم صفوف

علي جنيدي
17-11-2007, 08:04 PM
هذا هو الحل بدون توابع التعامل مع المحارف يرجى الاطلاع لمن يهمه الأمر


#include<iostream.h>
#include<math.h>
#include<stdlib.h>
void Display(void);
void Choise (char);
void Prime(int , int) ;
double PI ( double );
void rev_order(int) ;
void main()
{
char c;
while(1)
{
Display();
cin >> c ;
Choise(c) ;
}
return ;
}

void Display(void)
{
cout << "Welcome This is the program menu Please Print the number your choice"<< endl
<< "1. Numeric calculation " << endl
<< " a. Prime numbers " << endl
<< " b. Pi approxmiation " << endl
<< " c. Reverse order " << endl
<< endl
<< "2. Text Analysis " << endl
<< "3. Searching a text " << endl
<< "4. Exit " << endl ;
}
void Choise(char c)
{
switch( c )
{
case 'a':
{
int a , b ;
cout << " Enter two numbers a , b " << endl ;
cin >> a >> b ;
Prime(a , b) ;
}
break ;
case 'b':
{
double n ;
cout << "Please enter a number " << endl ;
cin >> n ;
cout << PI(n) << " is approximtly to " << n << endl ;
}
break ;
case 'c':
{
int k ;
cout << "Enter anumber " << endl ;
cin >> k ;
rev_order(k);
}
break ;

case '4' :
exit(1);

default:
cout << " You choise is not correct " << endl;
}
}
void Prime(int a , int b)
{
bool D ;
for(int i = a ; i <= b ; i++)
{
D = true ;
for(int j = 2 ; j <= i/2 ; j++)
{
if(i%j == 0)
{
D = false ;
break ;
}
}
if(D)
cout << i << " " ;
}
}

double PI(double n)
{
return floor(n) ;
}
void rev_order(int k)
{
cout << " The Reverse of " << k << " is " ;
int rk = 0 ;
while(k/10 != 0)
{
rk *= 10 ;
rk += k%10 ;
k = k/10 ;
}
cout << rk*10 + 1 << endl ;
}

أميرة الوفاء
17-11-2007, 11:16 PM
ماهي شروط اللعب توابع بنى أم صفوف

مشكور على الحل بس ما هي الطريقة المطلوبة..:31:

سوري ما فهمت عليك

بس شوووف الطريقة تكون باستخدام الفانكشن والطريقة تكون مثل هذا المثال البسيط :ponder:






//This porgram reads a value n, call a function fact to compute n!,

//and another function to find the value of e approximated to n terms



#include <iostream>

#include <cmath>

using namespace std;



int fact(int x);



double E(int y);



int main()

{

int n;

double e;



cout <<"please Enter the value of n : ";

cin >>n;

cout << "\nThe Factorial of n (n!) = " << fact(n) <<endl<< endl;

e = E(n);

cout<< "E approximated to "<< n <<" terms is " << e << endl<< endl;



return 0;

}



/*----------------------------------------------------------------*/



int fact(int k){

int fac=1;

for(int i=1;i<=k;i++)

fac *=i;

return fac;

}



/*------------------------------------------------------------------*/



double E(int n){

double e=1;

for (int i=1;i<=n;i++)

e +=1.0/fact(i);

return e;

}



/*-------------------------------------------------------------------*/

أميرة الوفاء
17-11-2007, 11:19 PM
مشكور على الحل بس ما هي الطريقة المطلوبة..:31:

سوري ما فهمت عليك

بس شوووف الطريقة تكون باستخدام الفانكشن والطريقة تكون مثل هذا المثال البسيط :ponder:






//This porgram reads a value n, call a function fact to compute n!,

//and another function to find the value of e approximated to n terms



#include <iostream>

#include <cmath>

using namespace std;



int fact(int x);



double E(int y);



int main()

{

int n;

double e;



cout <<"please Enter the value of n : ";

cin >>n;

cout << "\nThe Factorial of n (n!) = " << fact(n) <<endl<< endl;

e = E(n);

cout<< "E approximated to "<< n <<" terms is " << e << endl<< endl;



return 0;

}



/*----------------------------------------------------------------*/



int fact(int k){

int fac=1;

for(int i=1;i<=k;i++)

fac *=i;

return fac;

}



/*------------------------------------------------------------------*/



double E(int n){

double e=1;

for (int i=1;i<=n;i++)

e +=1.0/fact(i);

return e;

}



/*-------------------------------------------------------------------*/








سوري ما عرف كيف طلع ذا اللفت.. بدون لفت

المهم مثل هذا المثال

أميرة الوفاء
25-11-2007, 09:05 AM
للرفع:ouch:


نو ون وانت تو سولف ات:sadwavey:

اتز انترستينج:ouch:


:أفكر: