السلام عليكم
أحتاج طريقة لكتابة flow chart لبرنامج بلغة ++C يحتوي على class وتم وراثة آخر منه
وكذلك class تم اشتقاق آخر منه بالوراثة المتعددة
أنا ما عرفت أكتبها بسبب وجود class المشتق وأبغي أعرف الطريقة
أحتاجها قبل يوم الثلاثاء
وشكراً
السلام عليكم
أحتاج طريقة لكتابة flow chart لبرنامج بلغة ++C يحتوي على class وتم وراثة آخر منه
وكذلك class تم اشتقاق آخر منه بالوراثة المتعددة
أنا ما عرفت أكتبها بسبب وجود class المشتق وأبغي أعرف الطريقة
أحتاجها قبل يوم الثلاثاء
وشكراً
كود الوراثة:
#include <iostream.h>
#include <conio.h>
#include <process.h>
class calculator
{
protected:
char funcname[15];
float number, n1, n2;
float answer;
int pow;
char ch, op;
public:
float add (float n1, float n2)
{
float result= n1+n2;
return result;
}
float sub (float n1, float n2)
{
float result= n1-n2;
return result;
}
float mlt (float n1, float n2)
{
float result= n1*n2;
return result;
}
float div (float n1, float n2)
{
float result= n1/n2;
return result;
}
float power (float n, int t)
{
double result= 1.0;
for (int j=0;j<t;j++)
result*=n;
return result;
}
void showdata()
{
cout<< endl << funcname << " calculation ";
cout<< "\tAnswer is: " << answer;
}
double squaret (int n);
float getans();
};
float sciencecalc::square_root (int n)
{
float s=0;
for (double j=0;j<19;j++)
{
s=j*j;
if (s==n)
{
cout<< "The sqrt of " << s << " = " << j << endl;
break;
}
if (s>n) //s=5
{
for (double i=0.0;i<1.0;i+=0.1)//incr the 1st digit 16.1
{
//=0.1 <0.9
s=j-1; //5-1=4
s=s+i; //s=4.0
double h=s*s; //h=16.0
if (h<n) //16.0<17
{
for (double q=0.01;q<0.1;q+=0.01) //incr the 2nd digit 16.01
{
//h=n 2nd 0.09
s=s+q; //s=4.10
double m=s*s; //m=16.81 until 4.13*4.13=17.056
if (m>n) //17.056>17
{
s=s-0.01; //Range of 4.12
for (double x=0.001;x<0.01;x+=0.001)
{
//x=0.001;m=n
s=s+x; //4.121
double y=s*s;
if (y>n)
{
s=s-0.001;
for (double b=0.0001;b<0.001;b+=0.0001)
{
s=s+b;
double z=s*s;
return s;
}
}
}
}
}
}
}
}
}
}كود الوراثة المتعددة
#include <iostream.h>
#include <conio.h>
const int max=2;
class calculator
{
private:
float num1, num2;
float answer;
char ch, op;
char fname[10];
public:
float add (float num1, float num2)
{
float result= num1+num2;
return result;
}
float sub (float num1, float num2)
{
float result= num1-num2;
return result;
}
float mlt (float num1, float num2)
{
float result= num1*num2;
return result;
}
float div (float num1, float num2)
{
float result= num1/num2;
return result;
}
void showdata()
{
cout<< endl<< "Function Name: " << fname << "The Answer is: " << answer;
}
virtual float getans (char cname);
};
float calculator :: getans (char cname)
{
int n1, n2;
calculator calc;
cout<< "\nEnter function name: ";
cin>> fname;
cout<< "\nEnter first number, operator, second number: ";
cin>> n1 >> op >> n2;
switch (op)
{
case'+': {answer=calc.add(n1,n2); break;}
case'-': {answer=calc.sub(n1,n2); break;}
case'*': {answer=calc.mlt(n1,n2); break;}
case'/': {answer=calc.div(n1,n2); break;}
}
cout<< "\nThe answer is: " << answer;
if (cname=='r')
{
cout<< "\nRgular Calculation";
return answer;
}
return answer;
}
class sciencecalc : public calculator
{
public:
float square (float n1)
{
float result= n1*n1;
return result;
}
double squaret (float n1);
void virtual showdata ()
{
calculator::showdata();
}
float getans (char cname);
};
float sciencecalc::getans (char cname)
{
float prvans, k;
double answer;
char op;
sciencecalc calc;
prvans= calculator::getans(cname);
cout<< "\nWould you like to perform square, square_root, power calculation (y/n): ";
cin>> op;
if (op=='n')
{
cout<< "\nThe answer is: ";
return prvans;
}
if (op=='y')
{
cout<< "\nEnter type of calculation: " << endl;
cout<< "Press 's' for square calculation: " << endl;
cout<< "Press 't' for square root calculation: " << endl;
cout<< "Press 'p' for power calculation: " << endl;
cin>> op;
if (op=='s')
{answer=calc.square(prvans);}
else if (op=='t')
{answer=calc.squaret(prvans);}
}
cout<< "\nThe answer is " << answer;
return answer;
}
float sciencecalc :: squaret (int n) // double squaret (float n1);
{
float s=0;
for (double j=0;j<19;j++)
{
s=j*j;
if (s==n)
{
cout<< "The sqrt of " << s << " = " << j << endl;
break;
}
if (s>n) //s=5
{
for (double i=0.0;i<1.0;i+=0.1)//incr the 1st digit 16.1
{
//=0.1 <0.9
s=j-1; //5-1=4
s=s+i; //s=4.0
double h=s*s; //h=16.0
if (h<n) //16.0<17
{
for (double q=0.01;q<0.1;q+=0.01) //incr the 2nd digit 16.01
{
//h=n 2nd 0.09
s=s+q; //s=4.10
double m=s*s; //m=16.81 until 4.13*4.13=17.056
if (m>n) //17.056>17
{
s=s-0.01; //Range of 4.12
for (double x=0.001;x<0.01;x+=0.001)
{
//x=0.001;m=n
s=s+x; //4.121
double y=s*s;
if (y>n)
{
s=s-0.001;
for (double b=0.0001;b<0.001;b+=0.0001)
{
s=s+b;
double z=s*s;
return s;
}
}
}
}
}
}
}
}
}
}
class statisticcalc : public sciencecalc
{
public:
float mean (s)
{
float ans;
ans= (s/float(3));
cout<< endl << "Mean = " << ans <<endl;
return ans;
}
float variance (float s, float n)
{
float ans;
float a=s-n;
ans= sciencecalc::square(a);
cout<< "Varianve= " << ans << endl;
return ans;
}
float standvar (float s)
{
float ans;
ans= sciencecalc::squaret (s);
cout<< "Standvar = " << ans << endl;
return ans;
}
float getans (char cname);
};
float statisticcalc :: getans (char cname)
{
float prvans, k, answer;
char op;
statisticcalc calc;
prvans= sciencecalc::getans (cname);
if (cname=='s')
{
float amean = calc.mean (prvans);
float vari = calc.variance (prvans,amean);
float sd= calc.standvar (vari);
cout<< "\nStatical Class" << cname; cin>> k;
cout<< "Statistics Calculation mean = " << amean;
}
return prvans;
}
void main()
{
int n=0, numb, j;
char ch;
float answer;
char fname;
calculator acalc;
sciencecalc scalc;
sciencecalc tcalc;
calculator * aptr;
aptr=&tcalc; //you have to put virtual in getans calculator else no polym
cout<< "Enter type of calculation: " << endl;
cout<< "Press 'r' for regular calculator" << endl;
cout<< "Press 's' for statical calculator" << endl;
cout<< "Press 'c' for scientific calculator: ";
cin>> fname;
do
{
answer= aptr->getans (fname);
cout<< "Answer is" << answer << endl << endl;
cout<< "\n\nDo another(Y/N): ";
ch= getche();
} while (ch!='n');
}هذا الموضوع مغلق.