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 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,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=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: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;
}
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,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=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: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;
}