Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > dealing with protected data members

Reply
Thread Tools

dealing with protected data members

 
 
CuTe_Engineer
Guest
Posts: n/a
 
      10-26-2007
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 Patientublic 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,doub le=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:atient(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;

}

 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      10-26-2007
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
 
Reply With Quote
 
 
 
 
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a
 
      10-26-2007
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
 
Reply With Quote
 
CuTe_Engineer
Guest
Posts: n/a
 
      10-26-2007
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 ?

 
Reply With Quote
 
CuTe_Engineer
Guest
Posts: n/a
 
      10-26-2007
On Oct 26, 10:39 am, Erik Wikstr÷m <(E-Mail Removed)> 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)

 
Reply With Quote
 
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a
 
      10-26-2007
On 2007-10-26 11:37, CuTe_Engineer wrote:
> On Oct 26, 10:39 am, Erik Wikstr├Âm <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
data members as "protected"? Act C++ 28 10-05-2004 10:40 PM
CLass members; public, private, protected and ??? Chris Mantoulidis C++ 6 01-03-2004 04:59 PM
accessing protected data members of instance of parent class Suzanne Vogel C++ 5 12-09-2003 01:55 AM
Q on Classes & SubClasses with protected members Praveen Java 1 11-21-2003 03:14 AM
Difference between "Protected WithEvents myClassName" And "Protected myClassName" ? Andreas Klemt ASP .Net 2 07-05-2003 12:51 AM



Advertisments