dealing with protected data members - c++
This is a discussion on dealing with protected data members - c++ ; 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' :
...
-
dealing with protected data members
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
ublic 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:
rint()
{
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[i]=exercises*time;
totalLost+=gymarray[i];
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[i]=food*portion;
totalgained+=Nutritionarray[i];
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:
rint()
{
cout<<"Before the regime"<<name<<"energy was
"<<calories()<<"calories"<<endl;
Regime:
rint();
Gymnasium:
rint();
Nutrition:
rint();
}
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:
rint()
{
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;
}
-
Re: dealing with protected data members
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[i]=exercises*time;
Here, exercises is unknown.
> totalLost+=gymarray[i];
> Lostcalories=totalLost/60;
>
> }
[snip]
Michael
-
Re: dealing with protected data members
On 2007-10-26 09:30, CuTe_Engineer wrote:
> 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[i]=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
-
Re: dealing with protected data members
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 ?
-
Re: dealing with protected data members
On Oct 26, 10:39 am, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2007-10-26 09:30, CuTe_Engineer wrote:
>
>
>
>
>
> > 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[i]=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)
-
Re: dealing with protected data members
On 2007-10-26 11:37, CuTe_Engineer wrote:
> On Oct 26, 10:39 am, Erik Wikström <Erik-wikst...@telia.com> wrote:
>> On 2007-10-26 09:30, CuTe_Engineer wrote:
>>
>>
>>
>>
>>
>> > 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[i]=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.
--
Erik Wikström
Similar Threads
-
By Application Development in forum c++
Replies: 4
Last Post: 11-04-2007, 06:37 AM
-
By Application Development in forum c++
Replies: 1
Last Post: 10-07-2007, 12:15 PM
-
By Application Development in forum Java
Replies: 6
Last Post: 09-20-2007, 04:55 PM
-
By Application Development in forum Idl-pvwave
Replies: 9
Last Post: 06-15-2007, 02:54 PM
-
By Application Development in forum DOTNET
Replies: 2
Last Post: 01-11-2007, 10:37 AM