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

مساعدة في برنامج

بدأه احمد رشوان في 28 مارس 2009 · 5 رد · 559 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Problem statement:

In this project you are asked to write a program that solves two linear equations in two variables.

The program should ask a user to enter the equations as follows:

_____________________________

Enter the first equation:

2x + 3y = 6

Enter the second equation:

x + y = 4

The solution is:

X = 6

Y = ‐2

Press any key to continue…..

________________________________

Hints:

a. You may need some parsing steps in order to solve the problem

b. Your program should deal with equations with zero‐coefficient variables, e.g. x = 5 or y = 2

c. You may need some knowledge of matrix operations

__________________________________

محاولتي :

include<iostreaml.h>#

include<stdlib.h>

void main ()

}

int x,y;

cout<<"Enter the first equation";

cin>>x=>>y=;

cout<<x=<<y=<<x+y<<endl;

cout<<"Enter the second equation:";

cin>>x>>y>>;

cout<<"The solution is:";

cout<<x<<y<<endl;

{

MATRIX

#2

حسب النص برنامجك يجب أن يقوم بأخذ نص المعادلة كما هو، بشكل string او char[] ومن ثم تقوم بسحب قيم المعاملات منه وليس أن تقوم بطلبها بالشكل x = ? و y = ? لأنك بهذا لا تقوم بحل المعادلة :huh:

ِشئ آخر من ثالث hint يقول لك يمكنك الاستفادة من حل المعادلات الخطية باستخدام الـ matrices.. بالشكل

LaTeX
:lol:

تم تعديل هذه المشاركة بواسطة Xacker في 28 مارس 2009 في 19:47

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#3

السلام عليكــم ورحمـة الله وبركاتــه ،،

يمكنك أخى استخدام طريقة كرامر فى حل المعادلات

وهى تعتمد على مفهوم المحددات

شوف البرنامج التالى


using namespace std;
int main()
{
double a1,b1,c1;
double a2,b2,c2;
double delta,deltax,deltay;
double X,Y;
cout<<" enter first equation : ";
cin>>a1>>b1>>c1;
cout<<" enter second equation : ";
cin>>a2>>b2>>c2;
delta=a1*b2-b1*a2;
deltax=c1*b2-b1*c2;
deltay=a1*c2-c1*a2;
X=deltax/delta;
Y=deltay/delta;
cout<<"X= "<<X<<endl;
cout<<"Y= "<<Y<<endl;
return 0;
}
#include <iostream>

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#4

بارك الله فيكم اخواني

ما قصرتو

MATRIX

#5

السلام عليكــم ورحمـة الله وبركاتــه ،،

هذا البرنامج أقراء الكود بتمعن

#include <iostream>
#include <string>
#include<cctype>
#include <cstdlib> 
using namespace std;

struct verb{int x,y,z;};
struct position{int x,plus,y,equal;};
verb get_verb(string str)
{
position pos;
verb ver;
string tmp;


pos.x=str.find("x");
pos.plus=str.find("+");
pos.y=str.find("y");
pos.equal=str.find("=");

if(!pos.x)
{
	ver.x=1;
}
else
{
	tmp=str.substr(0,pos.x);
	ver.x=atoi(tmp.c_str());
	tmp.clear();
}
if(!isdigit(str[pos.y-1]))
{
	ver.y=1;

}else
{
	tmp=str.substr(pos.plus,pos.y);
	ver.y=atoi(tmp.c_str());
	tmp.clear();

}
tmp=str.substr(pos.equal+1);
ver.z=atoi(tmp.c_str());



  return ver;
}
int main(int argc, char *argv[])
{
string eq;
verb ver1,ver2;
int x,y;
cout<<"Enter the first equation:"<<endl;
getline(cin,eq);
ver1=get_verb(eq);
cout<<"Enter the second equation:"<<endl;
getline(cin,eq);
ver2=get_verb(eq);

x=(ver1.z*ver2.y-ver2.z*ver1.y)/(ver1.x*ver2.y-ver2.x*ver1.y);
y=(ver1.x*ver2.z-ver2.x*ver1.z)/(ver1.x*ver2.y-ver2.x*ver1.y);

cout<<"The solution is:"<<endl;
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
cin.get();
	return 0;
}
tvquran_6.gif

#6

السلام عليكــم ورحمـة الله وبركاتــه ،،

ممتاز أخى العزيز فهد

وهذه طريقه أخرى تتعامل مع المعاملات العشريه والسالبه


#include <string>
#include<ctype.h>
using namespace std;
void parse(string s,float &a,float& b,float& c)
{
string tmp_a="",tmp_b="",tmp_c="";
int key=1;
bool t=true;
cin>>s;
for (int i=0;i<s.size();i++)// 3x+5y=8
{
if(isdigit(s) || s=='.' || s=='-' || s=='+')
{
t=true;
if(key==1)
tmp_a+=s;
else if(key==2)
tmp_b+=s;
else if(key==3)
tmp_c+=s;
}
else
{
t=false;
}
if((isdigit(s[i+1]) || s[i+1]=='.' || s[i+1]=='-' || s[i+1]=='+') && !t) key++;
}
if(tmp_a=="+" || tmp_a=="") a=1;
else if(tmp_a=="-") a=-1;
else
a= atof(tmp_a.c_str());
if(tmp_b=="+") b=1;
else if(tmp_b=="-") b=-1;
else
b=atof(tmp_b.c_str());
c=atof(tmp_c.c_str());
}
int main()
{
float a1,b1,c1,a2,b2,c2;
string q1,q2;
cout<<" enter the first equation : \n";
parse(q1,a1,b1,c1);
cout<<"enter the second equation : \n";
parse(q2,a2,b2,c2);
cout<<"X= "<<(c1*b2-b1*c2)/(a1*b2-b1*a2)<<endl;
cout<<"Y= "<<(a1*c2-c1*a2)/(a1*b2-b1*a2)<<endl;
return 0;
}
#include<iostream>

ملحوظه : البرنامج يحتاج بعض التطوير حيث انه لا يتعامل مع

hint 2

:D

تم تعديل هذه المشاركة بواسطة amin_mu123 في 29 مارس 2009 في 07:20

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

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