dealing with protected data members

C

CuTe_Engineer

hii,

i have problem in dealing with protected data members & array
this is my prog i make it as a project file

my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier

i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ?

the header files :

#include<string>

#ifndef H_Gymnasium
#define H_Gymnasium

using namespace std;

struct activities
{
string exercises;
int time;
};

class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif

#include<string>

#ifndef H_Gymnasium
#define H_Gymnasium

using namespace std;

struct activities
{
string exercises;
int time;
};

class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif

#include <string>
#include"Regime.h"
#include"Gymnasium.h"
#include"Nutrition.h"

#ifndef H_Patient
#define H_Patient

using namespace std;

struct person
{
string name;
double energy;
};

class Patient:public Gymnasium , public Nutrition
{

public:
void set(string,int,int,string,int,int,string,double);
void get(string&,int&,
int& ,string& ,int&,int&,string&,double&)const;
void print();
Patient(string=
"",int=0,int=0,string="",int=0,int=0,string=0,double=0);
double calories(); // find the difference between gained & lost
calories and
//and sub. it from the energy
private:
person info;
Regime regimePlan;
};
#endif
#include<string>
#include"Gymnasium.h"
#include"Nutrition.h"

#ifndef H_Regime
#define H_Regime

using namespace std;

class Regime
{
public:
void set(string,int,int,string,int,int);
void print();
Regime(string ,int,int,string,int,int);
double calories();

private:
Gymnasium exercisePlan ;
Nutrition dietPlan;
};
#endif

++++++++++++++++++++++++++++++++++++

& these are the implitation files

#include <iostream>
#include <string>
#include "Gymnasium.h"

using namespace std;

const int OpenGym =680;
const int Treadmill =820;
const int Bike=620;
const int Fitness=740;
const int Hoop=210;

const int gymlength=5;

void Gymnasium::set(string ex , int T , int length1 )
{
activities b;

b.exercises=ex;
b.time=T;
gymlength=length1;

}

void Gymnasium::getActivities(string& ex , int& T ,int&length1 )const
{
activities b;

ex=b.exercises;
T=b.time;
length1=gymlength;
}

void Gymnasium::print()
{
cout<<"He/She lost "<<calories()<<"calories"<<endl;
}

Gymnasium::Gymnasium(string ex , int T , int length1 )
{
activities b;

b.exercises=ex;
b.time=T;
gymlength=length1;

}

double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;


for(i=0 ,i<gymlength , i++)

gymarray=exercises*time;
totalLost+=gymarray;
Lostcalories=totalLost/60;

}

#include<iostream>
#include<string>
#include"Nutrition.h"

using namespace std;

const int Carbohydrates=90;
const int Protein=70;
const int Vitamins=50;
const int Water=10;

const int Nutritionlength=5;

void Nutrition::set(string f , int p , int length2)
{
food=f;
portion=p;
nutritionLength=length2;
}

void Nutrition ::getMeals(string&f , int&p ,int&length2)const
{
f=food;
p=portion;
length2=Nutritionlength;
}

Nutrition::Nutrition(string f , int p , int length2)
{
set(f,p,length2);
}

double Nutrition::calories()
{
int gainedcalories,totalgained;

for(int i=0 , i>Nutritionlength , i++)
Nutritionarray=food*portion;
totalgained+=Nutritionarray;
gainedcalories=totalgained/100;

return gainedcalories;
}
void print()
{
cout<<"He/She gained "<<calories()<<"calories"<<endl;
}

#include<iostream>
#include <string>
#include"Patient.h"


using namespace std;

void Patient::set(string ex,int T,int length1,string f,int p,int
length2,string n,double e)
{
b.exercises=ex;
b.time=T;
gymlength=length1;
food=f;
portion=p;
nutritionLength=length2;
name=n;
energy=e;

}

void Patient::get(string& exe,int& T, int& length1 ,string& f ,int&
p,int& length2,string& n,double&e)const;
{
Regime::get(ex,T,length1,f,p,length2);
n=name;
e=energy;
}

void Patient::print()
{
cout<<"Before the regime"<<name<<"energy was
"<<calories()<<"calories"<<endl;
Regime::print();
Gymnasium::print();
Nutrition::print();
}

Patient::patient(string ex,int T,int length1,string f,int p,int
length2,string n,double e)
{
set(ex,T,length1,f,p,length2,n,e);
}

double Patient::calories()
{
int before;

before=Regime::calories()+600;

return before;
}

#include<iostream>
#include<string>
#include"Regime.h"

using namespace std;

void Regime::set(string exe,int t,int lenght1,string f,int p,int
lenght2)
{
Gymnasium::set(exe,t,length1);
Nutrition::set(f,p,length2);
}

void Regime::print()
{
cout<<"After the regime Ahmed energy is
"<<calories()<<"calories"<<endl;
}

Regime::Regime(string exe,int t,int lenght1,string f,int p,int
lenght2)
{
Gymnasium::set(exe,t,length1);
Nutrition::set(f,p,length2);
}

double Regime::calories()
{
After=Gymnasium::calories()-Nutrition::calories();

return After;
}

+++++++++++++++++++++

the driver

#include<iostream>
#include <string>
#include<fstream>
#include "Gymnasium.h"
#include "Nutrition.h"
#include "Patient.h"
#include "Regime.h"

using namespace std;


int main()
{
Patient A;
activities b;
int T,p ,length1,length2;
string f , ex , n;
double e;


cin>>n>>e;
cout<<endl;

ifstream inFile;
inFile.open("patientActivities.txt");

inFile>>b.exercises>>b.time;

inFile.close();



inFile.open("patientMeals.txt");


inFile>>f>>p;

inFile.close();

A.set(ex,T,length1,f,p,length2,n,e);
A.print();

return 0;

}
 
M

Michael DOUBEZ

CuTe_Engineer a écrit :
hii,

i have problem in dealing with protected data members & array
this is my prog i make it as a project file

my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier

i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ? [snip]
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
}; [snip]
double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;


for(i=0 ,i<gymlength , i++)

gymarray=exercises*time;


Here, exercises is unknown.
totalLost+=gymarray;
Lostcalories=totalLost/60;

}

[snip]

Michael
 
G

Guest

hii,

i have problem in dealing with protected data members & array
this is my prog i make it as a project file

my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier

i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ?

the header files :

#include<string>

#ifndef H_Gymnasium
#define H_Gymnasium

Move the include-guards above other includes.
using namespace std;

Do not use this in header-files, all files that includes your header
will have to live with the effects.
struct activities
{
string exercises;
int time;
};

class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif

double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;


for(i=0 ,i<gymlength , i++)

gymarray=exercises*time;


Like you said, exercises is a member in a struct, that means that you
have to have an instance of that struct to access it:

activities a;
a.exercises = "Jump";

As can be seen from the above example, exercises is a string, you can
not multiply a string with an integer.
 
C

CuTe_Engineer

i know that`s my problem , i don`t know why it`s known
exercises is a member of the struct activities and i declare an array
in the class of type activities ( a struct)

struct activities
{
string exercises;
int time;
};

class Gymnasium
{
private:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};

so why it`s known ?
 
C

CuTe_Engineer

i have problem in dealing with protected data members & array
this is my prog i make it as a project file
my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier
i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ?
the header files :

#ifndef H_Gymnasium
#define H_Gymnasium

Move the include-guards above other includes.
using namespace std;

Do not use this in header-files, all files that includes your header
will have to live with the effects.




struct activities
{
string exercises;
int time;
};
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif
double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;
for(i=0 ,i<gymlength , i++)
gymarray=exercises*time;


Like you said, exercises is a member in a struct, that means that you
have to have an instance of that struct to access it:

activities a;
a.exercises = "Jump";

As can be seen from the above example, exercises is a string, you can
not multiply a string with an integer.

--
Erik Wikström- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


ok i got it

now my Question is should i pass exercises in the set function , if
the answer is yes ,how shoul i pass it bacuase i`m gettitng error

this is the set function

void Gymnasium::set(string ex , int T , int length1 )
{


exercises=ex;
time=T;
gymlength=length1;

}

&& exercises and time are protected member of a type activites
( struct)
 
G

Guest

i have problem in dealing with protected data members & array
this is my prog i make it as a project file
my errors are mainly about declaration like :
c:\documents and settings\xppresp3\desktop
\ass2\ass2\gymnasiumimp.cpp(56) : error C2065: 'exercises' :
undeclared identifier
i didn`t understand why its undeclared while it`s a struct data
members and it should be public, but i use it in a class as an
protected array , so how can i declare it now ?
the header files :

#ifndef H_Gymnasium
#define H_Gymnasium

Move the include-guards above other includes.
using namespace std;

Do not use this in header-files, all files that includes your header
will have to live with the effects.




struct activities
{
string exercises;
int time;
};
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int,int);
void getActivities(string&,int&,int&)const;
double calories();
void print();
Gymnasium(string, int , int);
};
#endif
double Gymnasium:: calories()
{
int totalLost,Lostcalories ,i;
for(i=0 ,i<gymlength , i++)
gymarray=exercises*time;


Like you said, exercises is a member in a struct, that means that you
have to have an instance of that struct to access it:

activities a;
a.exercises = "Jump";

As can be seen from the above example, exercises is a string, you can
not multiply a string with an integer.

--
Erik Wikström- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


ok i got it


No you did not.
now my Question is should i pass exercises in the set function , if
the answer is yes ,how shoul i pass it bacuase i`m gettitng error

this is the set function

Since I do not know what set is supposed to do I can only guess
void Gymnasium::set(string ex , int T , int length1 )
{
activities[T].exercise = ex;
activities[T].time = length1;
}

&& exercises and time are protected member of a type activites
( struct)

No, they are public members.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top