I have made cancer prediction based on symptoms using decision trees but i am not able to run my code
Please Help ME!! Thanks in Advance!!! -
-
#include<iostream>
-
using namespace std;
-
#include<conio.h>
-
#include<string.h>
-
-
struct dectree
-
{
-
char symptom[50];
-
-
struct disease
-
{
-
char disea[50];
-
}dis[20];
-
}arr[40];
-
-
void datainsert()
-
{
-
strcpy(arr[0].symptom,"Uneasiness");
-
strcpy(arr[0].dis[0].disea,"Pancreas");
-
strcpy(arr[0].dis[1].disea,"Stomach");
-
strcpy(arr[0].dis[2].disea,"Esophagus");
-
strcpy(arr[0].dis[3].disea,"Kidney");
-
strcpy(arr[0].dis[4].disea,"Lung");
-
strcpy(arr[0].dis[5].disea,"Bone");
-
strcpy(arr[0].dis[6].disea,"Brain");
-
strcpy(arr[0].dis[7].disea,"Leukmia");
-
strcpy(arr[0].dis[8].disea,"Colon");
-
-
strcpy(arr[1].symptom,"Unexplained Weight Loss");
-
strcpy(arr[1].dis[0].disea,"Pancreas");
-
strcpy(arr[1].dis[1].disea,"Stomach");
-
strcpy(arr[1].dis[2].disea,"Esophagus");
-
strcpy(arr[1].dis[3].disea,"Kidney");
-
strcpy(arr[1].dis[4].disea,"Lung");
-
-
strcpy(arr[2].symptom,"Fatigue");
-
strcpy(arr[2].dis[0].disea,"Bone");
-
strcpy(arr[2].dis[1].disea,"Brain");
-
strcpy(arr[2].dis[2].disea,"Leukmia");
-
strcpy(arr[2].dis[3].disea,"Colon");
-
-
strcpy(arr[3].symptom,"Stomach Ache");
-
strcpy(arr[3].dis[0].disea,"Pancreas");
-
strcpy(arr[3].dis[1].disea,"Stomach");
-
strcpy(arr[3].dis[2].disea,"Esophagus");
-
strcpy(arr[3].dis[3].disea,"Kidney");
-
-
strcpy(arr[4].symptom,"Chronic Cough");
-
strcpy(arr[4].dis[0].disea,"Lung");
-
-
strcpy(arr[5].symptom,"Changing Bowel Habits");
-
strcpy(arr[5].dis[0].disea,"Colon");
-
-
strcpy(arr[6].symptom,"Pain");
-
strcpy(arr[6].dis[0].disea,"Bone");
-
strcpy(arr[6].dis[1].disea,"Leukmia");
-
strcpy(arr[6].dis[2].disea,"Brain");
-
-
strcpy(arr[7].symptom,"Hypertension");
-
strcpy(arr[7].dis[0].disea,"Pancreas");
-
strcpy(arr[7].dis[1].disea,"Kidney");
-
-
strcpy(arr[8].symptom,"Swallowing Difficulty");
-
strcpy(arr[8].dis[0].disea,"Stomach");
-
strcpy(arr[8].dis[1].disea,"Esophagus");
-
-
strcpy(arr[13].symptom,"Head Ache");
-
strcpy(arr[13].dis[0].disea,"Brain");
-
-
strcpy(arr[14].symptom,"Body Ache");
-
strcpy(arr[14].dis[0].disea,"Bone");
-
strcpy(arr[14].dis[1].disea,"Leukmia");
-
-
strcpy(arr[15].symptom,"Change in urine");
-
strcpy(arr[15].dis[0].disea,"Kidney");
-
-
strcpy(arr[17].symptom,"Heartburn");
-
strcpy(arr[17].dis[0].disea,"Esophagus");
-
-
strcpy(arr[29].symptom,"Physical Intolerance");
-
strcpy(arr[29].dis[0].disea,"Leukmia");
-
-
strcpy(arr[30].symptom,"Bone swelling");
-
strcpy(arr[30].dis[0].disea,"Bone");
-
-
}
-
void result(int n)
-
{
-
cout<<"Based on the following symptom you have chances of following CANCERS : \n";
-
-
for(int i=0;i<9;i++)
-
{
-
cout<<arr[n].dis[i].disea<<"\t";
-
}
-
cout<<endl;
-
}
-
void search()
-
{
-
int i=0;
-
int count=1;
-
int root=i;
-
int lchild;
-
int rchild;
-
char syn[40];
-
int queue[20];
-
int k=1;
-
-
lchild=2*root+1;
-
rchild=2*root+2;
-
-
-
while(arr[lchild].symptom!= NULL && arr[rchild].symptom!= NULL)
-
{
-
-
cout<<"Enter the symptom "<<"\t";
-
cin.getline(syn,40);
-
-
queue[count]=lchild;
-
count++;
-
queue[count]=rchild;
-
count++;
-
-
-
if(strcmp(arr[root].symptom,syn)==0)
-
{
-
root=queue[k];
-
lchild=2*root+1;
-
rchild=2*root+2;
-
k++;
-
-
}
-
else if( queue[k]!=NULL)
-
{
-
root=queue[k];
-
k++;
-
if(strcmp(arr[root].symptom,syn)==0)
-
{
-
root=queue[k];
-
lchild=2*root+1;
-
rchild=2*root+2;
-
k++;
-
-
}
-
}
-
else
-
{
-
break;
-
}
-
}
-
-
result(root);
-
-
}
-
main()
-
{
-
datainsert();
-
search();
-
getch();
-
}
-
11 1826
Is there a reason you are using C++ but are attempting to code in C ?
You should be using be using C++ string objects, classes and a map container. That avoids all of the tree code.
If you are writing in C then use the C #includes and the scanf/printf functions.
If you continue your way, then use your debugger to step through the code.
C++ might kind of look like: - class Disease
-
{
-
private:
-
string diseaseName;
-
};
-
-
class Symptom
-
{
-
private:
-
vector<Disease> dis;
-
};
-
Your database is: - map<string, Symptom> > database;
-
-
This data model assumes a key symptom which is looked up in the map container. The Symptom object has an embedded array of Disease objects which are the diseases associated with the symptom. All of the lookup tree code is done in the map container which is a C++ Standard Library object.
Thank You!
What i am doing is to incorporate both of them for the simplicity of the program.
I have found that my loop is not ending properly.. If you could please see that and give your input/rectification about the traversal or the search part.
If you have time..Please try running my code then you can see the error i am facing
Thank You!!
You mention run-time problems. Are you getting any compiler warnings?
Line 113 checks if the symptom field is NULL, but symptom is a char array not a char pointer. I'm surprised you didn't get a compiler warning for this. Likewise for other NULL test on line 133.
Can you describe in words the intent behind your search() function? Variable names lchild and rchild suggest a binary tree; but the arr array does not look a tree.
Thank You!!!
The compiler is not showing any warning but the loop is running infinitely.
The purpose behind this is the prediction of the disease based on symptom and yes its a binary tree made up using arrays. If you observe the array positions are such that it will form a tree.
If you observe the array positions are such that it will form a tree.
Array positions are not usually used for trees.
Trees are made up of nodes where the node contains a pointer to keys larger than the search key and a pointer to the keys smaller then the search key and a pointer to the data value if the search key is equal. In the case of 1-2-3 trees there may be even more pointers.
Have you implemented a tree structure out of a book? If so, you can use the book example to debug your code. If not, you may want to find a tree structure you are comfortable with and implement that.
I would advise against placing values in known positions. You will be better off using addresses so you can place data indirectly thereby removing the requirement for a data structure. Instead your structure is defined by following an address to a node.
Thank you !
I haven't gone through the book structure
I want to implement the tree structure without nodes just using the array positions
In case if you have run the code you would have found that the loop runs infinitely and everytime it asks for symptoms
The thing that I want to end the loop conditionally an I am not able to run that
Each dectree structure associates one symptom with up to 20 diseases; arr is an array of 40 of these structures. Please explain the intended logic of the search function. - Do you intend to merely search the array for the first matching symptom and then you're done?
- Do you intend to dance through the array in some disease-specific order?
You say the array is organized as a tree, but I don't understand what that means. A key attribute of a tree is the notion of a link to the next item (next right; next left). For example, what is the next item on the right of arr[7] (hypertension)? Which array entry is the root of the tree?
Traditionally, a decision tree is a structure where you start with a question; and each possible answer to that question either leads to another decision tree (another question) or to a final decision. How you answer the questions determines your path through the structure. The path is typically different each time.
What mechanism do you use to vary your path through your decision tree?
Thank You!!!
Ok ...so if you want to make a tree out of the array positions I have given then do 2i+1 and 2i+2
For example lets take the hypertension its at array 7 position so now to find out its root you will do (I-1)/2 ie 7-1=6 -> 6/2 = 3 now see array 3 ,...you will find stomach ache ... And see if you don't find the correspondent number like you are searching for that means its not there in the list(ie the node doesn't have Xchild)
See what I want to do is that first if a person has uneasiness then I will ask further symptom and each symptom is associated with some amount of cancer ...finally I come to a specific point where a person stops...you can make the tree with the above formulas
Thanks !!!
Your loop terminates because either - The loop condition on line 113 is satisfied.
- You reach the break instruction on line 148: root symptom is not the entered symptom (line 125) and queue[k]==NULL (line 133).
As I pointed out in my first reply, none of your comparisons to NULL will do what you expect. This is likely why your loop doesn't terminate.
By the way, the lchild and rchild values of "Physical intolerance" and "Bone swelling" will be larger than the size of your array. You should trap these out-of-range values before using them to access the array. Accessing past the end of an array is Undefined Behavior.
Thank You!!!
The problem with the code was that lchild and rchild were such that it wasn't getting to null
and about out of range it won't give error as the values are not there that means its null
I would like to share that I have successfully run the code after rectifying the traversal mistake
BIG THANK YOU TO ALL WHO HELPED !!
Mission accomplished !!!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MBS |
last post by:
I am trying to pass a string from one page to another. The input
string comes from a database and many times has the superscript TM
trademark symbol. The querystring handles this properly because...
|
by: C++ Shark |
last post by:
Hi,
which stl class is good for creating search trees? I am looking for
something flexible, that allows me to search for a required state (of
matrices, graphs, etc.) quickly.
thanks in...
|
by: barnesc |
last post by:
>barnesc at engr.orst.edu wrote:
> > So my question is: are there any other *practical* applications of a
> > B-tree based list/set/dict ? In other words, is this module totally
> > worth coding,...
|
by: news.microsoft.com |
last post by:
In my engineering class we're discussing microprocessor branch predictors.
Is it possible to write a Windows application (anything whatsoever) that
would allow me see how branch prediction is done...
|
by: ptrSriram |
last post by:
Can someone help me with an algorithm to merge two binary search trees.
One method I thought of was to flatten both the trees into sorted
lists(inorder traversal),merge those two sorted lists,...
|
by: dr3amxstar |
last post by:
Hi this might not be totally related but im just trying my luck here. I am doing a project - protein secondary structure prediction using Artificial Neural Network. I have written out the full code,...
|
by: aeismail |
last post by:
Hi, everybody:
A quick question regarding how to write if/then blocks.
Do C++ compilers care in terms of execution (i.e., efficiency) which
block in an if/then/else loop is executed? That is,...
|
by: Ganon11 |
last post by:
Hey guys,
OK, taking care of this beforehand; I AM a student in a university. This IS part of my homework, and (as a moderator), I'm doing my best to follow the posting guidelines I work so hard...
|
by: rsprawls |
last post by:
I found a disk for a b-tree algorithm that I purchased back in 93 or
so. I'd hoped to find this, but now I'd like to know how worthwhile
are b-trees in today's advancements? This is old C code...
|
by: sani kolik |
last post by:
I have three tables.
I have the following database table with information about symptoms, diseases, and diseaseSymptoms:
DISEASE_T SYMPTOMS diseaseSymptoms
========== ========== ========...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |