مشاهدة النسخة كاملة : مسأله صعبة في c++


huda2005
10-04-2007, 11:22 AM
عندي مسأله صعبه مرررره , ماعرفت أحلها
المطلوب أنه نحلها بلغة c++

فالشخص اللي عنده خبره يجي ويورينا شطارته ..

الحل أنا مستعجله عليه وااااااااااايد..
لازم نقدمه بعد يوم أو يومين


المسأله في المرفقات
أرجوكم الموضوع مهم جداااااا

منطلق بطموحي
10-04-2007, 01:49 PM
السلام عليكم:

أولا المسالة ليست بهذه الصعوبة ..لو نظرتي الى البرمجة انها صعبه فلن يحل السؤال !

ثانيا في المنتدى لا نقدم حل برمجي كامل ...نحن نوضح فقط الاشياء الغير مفهومة ...حبذا لو تبدأي بكود و ممكن نوضح الاشياء الغير صحيحة او الغير مفهومة فيه

بالنسبة للمساله بسيطة كل ما تحتاجينه ان تفهمي طريقة newton raphson لحل جذور المعادلة و قد تم توضيح هذا بالسؤال مع ذكر مثال ايضا! فاين المشكلة؟

huda2005
10-04-2007, 01:56 PM
هالاسبوع عندي اختبارات وااااااااااايد
دخيلكم لاتبخلون علي بالحل
بظل مديونه لكم

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

huda2005
10-04-2007, 02:00 PM
حاسه بالخجل لاني اول مره اطلب حل لمسأله او اطلب شيء
دايما استحي بس هالمره محتاجه رغما عني للحل, فضغطت على نفسي علشان اسأل احد واطلب منه الحل

اتمنى المساعده

:تحياتي:
Huda2005

منطلق بطموحي
10-04-2007, 02:00 PM
اختي هناك منا من لديه اشغال و من لديه دراسه و اختبارات و اخر من لديه مشاريع! من الصعب ان نقدم لك كل الحل ..بالاساس هذا لن يكون في مصلحتك ابدا

ضعي الكود الذي توصلتي اليه و سنساعدك قليلا ...اما ان نحل كل السؤال ! هذا ليس فيه فائدة ...و من ثم هذا group assignment قسمي الشغل على ال group الشغل البرمجي لا يقع على عاتق طالب واحد!

huda2005
10-04-2007, 02:05 PM
من المفترض انه لجروب بس الدكتور قرر انه كل شخص لوحده


شكرا عموما على المساعده

huda2005
11-04-2007, 12:35 PM
انا حليت المساله بس ياليت احد يصحح لي اخطائي قبل لا اسلم الاجابه

ومشكور يا (منطلق بطموحي)
ماتقصر بأسلوبك خليتني احل المسأله بروحي
الحل اعتقد انه ناقص شيء مافهمت مال outputfile named report.out
الحل اللي حليته موجود بالمرفقات

huda2005
16-04-2007, 12:46 PM
طبعا مافيه احد يرد ,,, المنتدى تعباااااااااااان
انا حليت المسأله وهذا حلي النهائي
************************************************** ****************************
#include <iostream> // include libraries
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
//************************************************** ***************************
ofstream outputfile;
// function of f(x) to be approximated
double f(double x)
**
double fx = pow(x, 2) - 4;
return fx;
}
//************************************************** ************************
//derived_f(x) using the calculation of previews function
double derived_f(double x)
**
double dfx = 2 * x;
return dfx;
}
//************************************************** ************************
//newton_raphson(x) this function find the root of a function by successive approximations
double newton_raphson(double x)
**
double x_k1 = x - (pow(x, 2) - 4)/(2 * x);
return x_k1;
}

//################################################## #########################

int main() // function main began to executed
**
outputfile.open("report.out.txt");

cout << "Newton-Raphson Method to approximate the root of a function\n\n";
outputfile << "Newton-Raphson Method to approximate the root of a function\n\n";

char choice; // decleration of choice to decide if you want to continue or not
do ** double precision;

double dx;
double x = 6; //initialized constant variable
int count = 0; //initialize constant variable

cout << "- Enter precision (1/10, 1/100, 1/1000,...): ";
outputfile << "- Enter precision (1/10, 1/100, 1/1000,...): ";
cin >> precision;
outputfile<< precision;
cout << endl;
outputfile << endl;
cout << right << setw(8) << "xk"
<< right << setw(12) << "f(x)"
<< right << setw(17) << "derived_f(xk)"
<< right << setw(8) << "xk+1"
<< right << setw(10) << "dx"
<< endl;
outputfile << right << setw(8) << "xk"
<< right << setw(12) << "f(x)"
<< right << setw(17) << "derived_f(xk)"
<< right << setw(8) << "xk+1"
<< right << setw(10) << "dx"
<< endl;

while (count == 0 || (count > 0 && dx > precision)) //use while loop
**
cout << fixed << setprecision(3);
outputfile << fixed << setprecision(3);
cout << right << setw(9) << x;
outputfile << right << setw(9) << x;

double fx = f(x); //decleration of f(x) which = pow(x, 2) - 4
cout << right << setw(12) << fx;
outputfile << right << setw(12) << fx;

double dfx = derived_f(x); //decleration of dfx which =2 * x;
cout << right << setw(12) << dfx;
outputfile << right << setw(12) << dfx;
double x_k1 = newton_raphson(x); //decleration of x_k1 which =x - (pow(x, 2) - 4)/(2 * x)
cout << right << setw(12) << x_k1;
outputfile << right << setw(12) << x_k1;


dx = x - x_k1;
cout << right << setw(12) << dx;
outputfile << right << setw(12) << dx;

cout << endl;
outputfile << endl;
x = x_k1;
count++;
}

do
** cout << "- Enter your choice: (q) to quit, (c) to continue: ";
outputfile << "- Enter your choice: (q) to quit, (c) to continue: ";
cin >> choice;
outputfile<< choice<<endl;
cin.ignore(1000, '\n');
// if statement determine if the user want to continue the programm or end.

if (choice == 'C' || choice == 'c' || choice == 'Q' || choice == 'q')
break;
else //message for invalid choice
cout << "Invalid choice. Try again.\n\n";
outputfile << "Invalid choice. Try again.\n\n";
} while (1);

cout << endl;
outputfile << endl;
} while (choice != 'q' && choice != 'Q');

cout << "Bye!\n\n";
outputfile << "Bye!\n\n";
//************************************************** *************************


return 0; //programm end successfully
} // end main