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

مشاهدة النسخة كاملة : طلب مساعده



سوارالليل
08-07-2005, 07:55 PM
باستخدام لغة c++

اكتب برنامج تقوم فيه بتعريف class باسم number ومن ثم تقوم بمايلي/



1-يقرا عدد صحيح موجب (n)

2-يحدد اذاكان العدد اوليا ام لا ((prime number

3-حساب وطباعة مضروب العدد المدخل(n!)

4-حساب وطباعة مجموع الاعداد الاقل من العددn

5- تحديد في ما اذا كان العدد n عدد زوجي (even) او فردي(odd)

6-زيادة قيمة العدد n بواحد



الclass الذي ستقوم بتعريفه يحتوي على مايلي



(value (int

(Isitprime (bool

(Factorial (double

(Sum (double

(N_type (bool

(Counter (int




الClass قم بكتابة برنامج يستخدم class numberوتتم فيه قراءة رقم(n) ومن ثم حساب اذا ماكان العدد اوليا او لا ايضا يقوم بطباعة مضروب العددN ونوع العدد زوجي او فردي ومن ثم يقوم بزيادة قيمة العدد بواحد

ارجو الرد اليوم مشكورين

Argonaut
09-07-2005, 01:58 AM
بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
ارجو ان يكون هذا المطلوب

#include <iostream.h>
int first_numerator,second_numerator;
int first_denominator,second_denominator;
int res_up,res_down,whole_num,org_up,org_down;
int Low_Value, High_Value;
int a,b,c,d;
int pick;
char answer;
bool check,check2;
char symbol;
void cancel_fraction()
{
org_up = res_up/(res_up-first_denominator);
org_down = res_down/(res_up-first_denominator);
for (a=1;a<res_up;a++)
{
check=false;
for (b=1;b<a;b++)
{
if ((a%b==0) && (a!=1) && (b!=1))
{
check=true;
}
}
if ((check==false) && (a!=1))
{
while ((res_up%a==0) && (res_down%a==0))
{
res_up=res_up/a;
res_down=res_down/a;
}
}
}
for (c=1;c<res_down;c++)
{
check2=false;
for (d=1;d<c;d++)
{
if ((c%d==0) && (c!=1) && (d!=1))
{
check2=true;
}
}
if ((check2==false) && (c!=1))
{
while ((res_up%c==0) && (res_down%c==0))
{
res_up=res_up/c;
res_down=res_down/c;
}
}
}
}

void calculate()
{
switch(pick)
{
case 1 :res_up=(second_denominator*first_numerator) + (first_denominator*second_numerator);
res_down=first_denominator*second_denominator;
symbol = '+';
break;
case 2 :res_up=(second_denominator*first_numerator) - (first_denominator*second_numerator);
res_down=first_denominator*second_denominator;
symbol = '-';
break;
case 3 :res_up=first_numerator*second_numerator;
res_down=first_denominator*second_denominator;
symbol = '*';
break;
case 4 :res_up=first_numerator*second_denominator;
res_down=first_denominator*second_numerator;
symbol = '/';
break;
}
}
void input()
{
do
{
cout << "Enter the numerator and denominator\nof the first fraction:";
cin >> first_numerator >> first_denominator;
}while(first_numerator < 0);
do
{
cout << "Enter the numerator and denominator\nof the second fraction:";
cin >> second_numerator >> second_denominator;
}while(second_numerator < 0);
do
{
cout << "\nMenu of Operations\n";
cout << "Add...................1\n";
cout << "Subtract..............2\n";
cout << "Multiply..............3\n";
cout << "Divide................4\n\n";
cout << "Which operation?";
cin >> pick;
}while(pick != 1 && pick != 2 && pick != 3 && pick != 4);
}
void output()
{
if (res_down==1)
{
cout << "\n " << first_numerator << " " << second_numerator << " " << res_up << " " << res_up << endl;
cout << "--- " << symbol << " --- = --- =\n";
cout << " " << first_denominator << " " << second_denominator << " " << res_down << endl;
cout <<"\nDo you want to try again ? (y/n) : ";
cin >> answer;
if (answer=='y' || answer=='Y')
{
input();
}
else
{}
}
else
{
if(res_up > res_down)
{
Low_Value = res_down;
High_Value = res_up;
}
else
{
High_Value = res_down;
Low_Value = res_up;
}
for(int i = Low_Value; i > 0;i--)
{
if( (Low_Value % i == 0) && (High_Value % i == 0) )
{
res_up=res_up/i;
res_down= res_down/i;
}
}
if(res_up > res_down)
{
whole_num = res_up%res_down;
res_up = res_up-(res_down*whole_num);
cout << "\n " << first_numerator << " " << second_numerator << " " << org_up << " " << whole_num << " " << res_up << endl;
cout << "--- " << symbol << " --- = --- = ---\n";
cout << " " << first_denominator << " " << second_denominator << " " << org_down << " " << res_down << endl;
cout <<"\nDo you want to try again ? (y/n) : ";
cin >> answer;
}
else
{
cout << "\n " << first_numerator << " " << second_numerator << " " << org_up << " " << res_up << endl;
cout << "--- " << symbol << " --- = --- = ---\n";
cout << " " << first_denominator << " " << second_denominator << " " << org_down << " " << res_down << endl;
cout <<"\nDo you want to try again ? (y/n) : ";
cin >> answer;
}
if (answer=='y' ||answer=='Y')
{
input();
}
else
{}
}
}
int main()
{
input();
calculate();
cancel_fraction();
output();
return 0;
}
وشكرا

سوارالليل
09-07-2005, 03:59 AM
الله يعطيك العافيه بس الاكواد الي كتبتها ماتخص البرنامج الي طلبت المساعده فيه هذي الاكواد لبرنامج ثاني ماهي نفس سؤال البرنامج الي انا كاتبه

Argonaut
10-07-2005, 09:29 PM
الله يعافيك :jap003: يعني تريد تعريف class بانه number :jap004: انا كنت حاسب فقط \n
سامحني سوف ارى الموضوع

Argonaut
11-07-2005, 10:31 PM
سوار الليل ارجو اعفائي من هذه المهمة نظرا للسبب الواضح وشكرا واسف وان شاء الله تجد الخيريين
وشكرا :jap035:

wcw
13-07-2005, 08:53 PM
#include<iostream>
using namespace std;
class Number
{
private:
int value;

public:
void readValue()
{
cin>>value;
}
int getValue()
{return value;}
bool isitprime()
{
if(value==1||value==2)
return true;
if(value==0)
return true;

for(int i=2;i<=value/2;i++)
if(value%i==0)
return false;
return true;
}
double Factorial()
{
double collection=1;
double factorial=value;
while(factorial!=0)
{
collection=collection*factorial;
factorial--;
}
return collection;
}
double Sum()
{ double value1=value;
double collection=0;
while(value1!=0)
{
value1--;
collection=collection+value1;
}
return collection;
}
bool nType()
{
if(value%2==0)
return true;
return false;
}
int counter()
{
int Counter;
Counter=value+1;
return Counter;
}


};
int main()
{
Number s;
cout<<"Enter the value: "<<endl;
s.readValue();
cout<<"the value is :"<< s.getValue()<<endl;
if(s.isitprime()==true)
cout<<"it is prime"<<endl;
else
cout<<"not prime"<<endl;
cout<<"the factorial is"<<s.Factorial()<<endl;
cout<<"the collection of number less "<<s.getVaue() <<"is"<<s.Sum()<<endl;
if(s.nType()==true)
cout<<"it is even"<<endl;
else
cout<<"it is odd"<<endl;
cout<<"the counter is"<<s.counter()<<endl;







return 0;
}