السلام عليكم
ارجو المساعدة فى تكملة هذا البرنامج
البرنامج يقوم بعمل اله حاسبة
البرنامج مكون من 9 ملفات
6 منهم انتهو بقى 3
ملف يقوم بالتخزين
/**************************************************/[CalComand .h
#ifndef CALCCOMMANDH
#define CALCCOMMANDH
#include <string>
using std::string;
class CalcCommand
{
private:
//MyRef string doesn't support white space??!!!
string fOperand; //125...etc
string fOperation; // +,-,*,..etc
string fDescription; // messege
CalcCommand* fNext;
public:
CalcCommand ();
CalcCommand (string operand, string operation, string description);
CalcCommand (const CalcCommand& cmd); //MyRef;copy constructor
string getOperand () const;
string getOperation () const;
string getDescription () const;
string toString ();// ???
//MyRef:the seter will pass the argument by refrence
void setOperand (const string& operand);
void setOperation (const string& operation);
void setDescription (const string& description);
// Members that allow CalcCommands to be in a LinkedList
//MyRef: they are the seter and the geter of "fNext"
CalcCommand* getNext () const;
void setNext (CalcCommand* next);
};
#endif//**************************************CalcComand.cpp
#include "calccommand.h"
#include <cstdio>
#include <string>
CalcCommand::CalcCommand ()//waseem;default constructor
{}
CalcCommand::CalcCommand (string operand, string operation, string description)
{
fOperand = operand;
fOperation = operation;
fDescription = description;
fNext = 0; // set the pointer to 0
}
CalcCommand::CalcCommand (const CalcCommand& cmd)//copy constructor
{
fOperand = cmd.getOperand ();
fOperation = cmd.getOperation ();
fDescription = cmd.getDescription ();
fNext = cmd.getNext ();
}
string CalcCommand::getOperand () const
{
return fOperand;
}
string CalcCommand::getOperation () const
{
return fOperation;
}
string CalcCommand::getDescription () const
{
return fDescription;
}
string CalcCommand::toString ()
{
int bufsize = fOperation.size() + fOperand.size() + fDescription.size() + 3;
char* buffer = new char [bufsize];
sprintf (buffer, "%s\t%s\t%s\n", fOperation.c_str(), fOperand.c_str(),
fDescription.c_str()); //myref C_str() will return the string that passed into it
string str (buffer);
delete buffer;
return str;
}
void CalcCommand::setOperand (const string& operand)
{
fOperand = operand;
}
void CalcCommand::setOperation (const string& operation)
{
fOperation = operation;
}
void CalcCommand::setDescription (const string& description)
{
fDescription = description;
}
void CalcCommand::setNext (CalcCommand* next)
{
fNext = next;
}
CalcCommand* CalcCommand::getNext () const
{
return fNext;
}دوال مساعدة
//******************************utils.h #ifndef UTILSH #define UTILSH #include <string> #include <sstream> #include <cstdlib> #include <cctype> using namespace std; bool isValidDouble (string data); double stringToDouble (string data); string doubleToString (double data); #endif
//*************************utils.cpp
#include "utils.h"
/**
This method runs a simple check on the string data to verify that it is a valid
double number.
*/
bool isValidDouble (string data)
{
bool decpointcnt = 0;
for (int i = 0; i < data.size(); i++)
{
if (isdigit(data) == 0)
{
// if the char is no digit...
if (data != '.' && data != '-') return false;
else if (data == '-' && i != 0) return false;
else if (data == '.' && decpointcnt > 0) return false;
if (data == '.' && decpointcnt == 0) ++decpointcnt;
}
}
return true;
}
/**
Converts a string into a double value. This function only produces reliable
results if data contains a valid double number. Use isValidDouble to verify
this.
*/
double stringToDouble (string data)
{
return atof (data.c_str()); /*MyRef atof is a function included in <cstdlib>
& it take a parameter whitch is a pointer to string and it returns double **/
}
/**
Converts any double number into a string.
*/
string doubleToString (double data)
{
stringstream stream;
stream << data;
string result;
stream>>result;
stream.clear ();
return result;
}يجب ان يكون Link list للملفات
اي يجب عمل ملفين وهما linkedlist.h and linkedlist.cpp
الملف linkedlist.h موجود
لكن linkedlist.cpp هذه هى مشكلتى الأولى
ها هو linkedlist.h
#ifndef LINKEDLISTH
#define LINKEDLISTH
#include "calccommand.h"
class LinkedList
{
private:
CalcCommand* fFirst;
public:
LinkedList ();
LinkedList (LinkedList& list);
~LinkedList ();
LinkedList& operator= (LinkedList& list);
void push_back (CalcCommand* data);
void clear ();
CalcCommand* getFirst () const;
bool isEmpty () const;
};
#endifيجب عمل ملفين وهما Calculator.h and Calculator.cpp
الملفCalculator.h موجود
لكن Calculator.cppهذه هى مشكلتى الثانية
ها هو Calculator.h
#ifndef CALCULATORH
#define CALCULATORH
#include "linkedlist.h"
#include <string>
using std::string;
class Calculator
{
private:
LinkedList* fCommandHistory;
double fSubResult;
protected:
void logCommand (string operation, string operand, string description);
public:
Calculator ();
~Calculator ();
bool add (const string& operand);
bool subtract (const string& operand);
bool divide (const string& operand);
bool multiply (const string& operand);
bool sqrt (const string& operand);
bool pow (const string& operand);
void reset ();
string getResult ();
LinkedList* getCommandHistory () const;
};
#endifارجو المساعده فى عمل الملفين وليس مهم ال main
ملحوظة لا استخدم هنا ال inheritance
والف شكر مقدما