-
my node
well i tryed changing this around alot and this is the way i have it and got the least amount of errors i was trying to make a node but it really didnt work out.. this was just to get used to them no real point in it..
ok well i have left the part i think is wrong in red..
Code:
#include <iostream>
using namespace std;
struct node
{
int start_up;
float p;
int position;
int sprint;
int total;
node* next;
};
class database
{
private:
node one;
node two;
node three;
one.next = &two;
two.next = &three;
public:
void football_one();
void football_two();
void football_three();
};
void database::football_one()
{
cout<<"How long it the start up. (in yards)"<<endl;
cin>> one.start_up;
cout<<"How long is the sprint? (in yards)"<<endl;
cin>> one.sprint;
one.total = one.start_up + one.sprint;
cout<<"you have to run :"<<one.total<<" yards."<<endl;
cout<<"Now to find out how fast you will run. \nEnter you yard position"<<endl;
cin>> one.position;
cout<<"You will be running at :";
if ((100 * one.position) / one.sprint >= one.sprint)
{
cout<<"100%"<<endl;
}
else
{
one.p = (100 * one.position) / one.sprint;
cout<< one.p<<"%"<<endl;
}
}
void database::football_two()
{
cout<<"How long it the start up. (in yards)"<<endl;
cin>> two.start_up;
cout<<"How long is the sprint? (in yards)"<<endl;
cin>> two.sprint;
one.total = two.start_up + two.sprint;
cout<<"you have to run :"<<two.total<<" yards."<<endl;
cout<<"Now to find out how fast you will run. \nEnter you yard position"<<endl;
cin>> two.position;
cout<<"You will be running at :";
if ((100 * two.position) / two.sprint >= two.sprint)
{
cout<<"100%"<<endl;
}
else
{
one.p = (100 * two.position) / one.sprint;
cout<< three.p<<"%"<<endl;
}
}
void database::football_three()
{
cout<<"How long it the start up. (in yards)"<<endl;
cin>> three.start_up;
cout<<"How long is the sprint? (in yards)"<<endl;
cin>> three.sprint;
one.total = three.start_up + three.sprint;
cout<<"you have to run :"<<three.total<<" yards."<<endl;
cout<<"Now to find out how fast you will run. \nEnter you yard position"<<endl;
cin>> three.position;
cout<<"You will be running at :";
if ((100 * three.position) / three.sprint >= three.sprint)
{
cout<<"100%"<<endl;
}
else
{
one.p = (100 * three.position) / one.sprint;
cout<< three.p<<"%"<<endl;
}
}
int main()
{
football_one();
football_two();
football_three();
}
-
Code:
class database
{
private:
node one;
node two;
node three;
public:
database () { one.next = &two; two.next = &three; }; //private data needs to be initalized
void football_one();
void football_two();
void football_three();
};
Code:
int main()
{
database d;
d.football_one();
d.football_two();
d.football_three();
}
-
Well you now know how to use nodes, but you didnt utilize them. in your program the *next is useless because you inputted the data and outputted the data without cycling through the nodes. Maybe you should make a print function that prints each node and cycles through. Ill post some example code from a Store program I created that is sort of similar.
-
Here is some example code that can help you see how to output linked Nodes and how to fiddle with them.
-
ok but i still get some error here :
Code:
class database
{
private:
node one;
node two;
node three;
one.next = &two;
two.next = &three;
public:
database () { one.next = &two; two.next = &three; };
void football_one();
void football_two();
void football_three();
};
-
Ya, because in a class you have private and public data members and functions. So that means you cant do any assigning in that part, only within functions.
Basically you can only declare variables and functions.
Thats why I moved it to the default constructor database() that is called each time you create a database object. So in that function surrounded by the brackets, it does what you had before.