Professional Documents
Culture Documents
#include "pch.h"
#include <iostream>
#include <string>
#include <conio.h>
struct operator_D {
bool exist;
int pow;
};
struct var {
char ch;
int pow;
operator_D D;
};
struct term {
int coeff;
var v;
term() {
coeff = v.pow = v.D.pow = 1;
v.ch = '\0';
v.D.exist = false;
}
};
node() {
next = NULL;
}
node(node& n) {
data = n.data;
}
node& operator= (const node& n) {
data = n.data;
}
};
template <typename U>
class LinkList {
private:
U* head;
U* tail;
U* temp;
public:
LinkList() {
head = NULL;
tail = NULL;
temp = NULL;
}
bool is_empty() {
if (head == NULL)
return true;
return false;
}
void insert(U d) {
if (is_empty()) {
head = new U;
head->data = d.data;
head->next = NULL;
tail = head;
}
else {
temp = new U;
temp->data = d.data;
temp->next = NULL;
tail->next = temp;
tail = temp;
}
}
void del() {
if (!is_empty()) {
temp = head;
U* ptr;
while (temp != NULL) {
ptr = temp;
temp = temp->next;
delete ptr;
}
}
}
void display() {
if (is_empty()) {
cout << "The List is Empty" << endl;
return;
}
temp = head;
while (temp->next != NULL) {
cout << temp->data;
temp = temp->next;
}
cout << temp->data << endl;
}
void MultiplyCoeff(int c) {
if (!is_empty()) {
temp = head;
while (temp != NULL) {
temp->data.coeff = temp->data.coeff * c;
temp = temp->next;
}
}
}
void MultiplyD() {
if (!is_empty()) {
temp = head;
while (temp != NULL) {
temp->data.v.D.pow = temp->data.v.D.pow + 1;
temp = temp->next;
}
}
}
void negate() {
if (!is_empty()) {
temp = head;
while (temp != NULL) {
temp->data.coeff = temp->data.coeff * -1;
temp = temp->next;
}
}
}
};
int main()
{
cout << endl << "Example: Dx-3y=0 (NO SPACES! NO Brackets!)" << endl;
cout << "Now Enter First Linear Homogeneous Differential Equation : ";
getline(cin, eq1);
i = 0;
check = eq1[i];
while (check != 0) {
if (check == '=') {
nod1.data = temp;
exp1.insert(nod1);
break;
}
else if (isdigit(check)) {
temp.coeff = check - '0';
if (!is_positive) temp.coeff = 0 - temp.coeff;
check = eq1[++i];
continue;
}
else if (check == 'D') {
temp.v.D.exist = true;
check = eq1[++i];
if (isdigit(check)) {
temp.v.D.pow = check - '0';
check = eq1[++i];
continue;
}
continue;
}
else if (check == dep_var[0] || check == dep_var[1]) {
temp.v.ch = check;
check = eq1[++i];
if (isdigit(check)) {
temp.v.pow = check - '0';
check = eq1[++i];
continue;
}
continue;
}
else if (check == '+' || check == '-'){
if (i == 0) {
if (check == '+') is_positive = true; else is_positive =
false;
check = eq1[++i];
continue;
}
nod1.data = temp;
exp1.insert(nod1);
temp = term();
is_positive = true;
check = eq1[++i];
continue;
}
else {
exp1.del();
cout << ".................INVALID Equation..................." <<
endl;
system("pause");
exit(0);
}
}
temp = exp1.getterm(dep_var[0]);
term temp2 = exp2.getterm(dep_var[0]);