what is my mistake

C

CuTe_Engineer

hii,

can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,
soo plz can you help me un finding my mistake
i will past the proramme here ,


the headers,


#include<string>





#ifndef H_Gymnasium
#define H_Gymnasium


struct activities
{
string exercises;
int time;



};


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

};


#endif

#include<string>





#ifndef H_Nutrition
#define H_Nutrition


struct meals
{
string food;
int portion;



};


class Nutrition
{
protected:
meals nutritionarray[5];
int nutritionLength;

public:
void set(string,int);
void getMeals(string& , int&)const;
void print();
Nutrition(string="" , int=0);
double calories();


};


#endif

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


#ifndef H_Patient
#define H_Patient





struct person
{
string name;
double energy;



};


class Patient:public Gymnasium , public Nutrition,public Regime
{

public:
void set(string,int,string,int,string,double);
void get(string&,int& ,string& ,int&,string&,double&)const;
void print();
Patient(string= "",int=0,string="",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





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


private:
Gymnasium exercisePlan ;
Nutrition dietPlan;


};


#endif
===============================================
the implitation

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


using namespace std;


const int gymlength=5;


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


gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;



}


void Gymnasium::getActivities(string& ex , int& T )const
{

ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;



}


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


}


Gymnasium::Gymnasium(string ex , int T )
{

gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;



}


double Gymnasium:: calories()
{
int total,calories ,i,lostcalories;

for(i=0;i>gymlength;i++)
{


if (gymarray.exercises=="OpenGym"){
calories=680*gymarray.time;


}
else if (gymarray.exercises=="Treadmill"){
calories=820*gymarray.time;


}
else if (gymarray.exercises=="Bike"){
calories=620*gymarray.time;


}
else if (gymarray.exercises=="Fitness"){
calories=740*gymarray.time;


}
else if (gymarray.exercises=="Hoop"){
calories=210*gymarray.time;
}
total+=calories;


}


lostcalories=total/60;
return lostcalories;



}


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

using namespace std;


const int Nutritionlength=4;


void Nutrition::set(string f , int p )
{
nutritionarray[Nutritionlength].food=f;
nutritionarray[Nutritionlength].portion=p;



}


void Nutrition ::getMeals(string&f , int&p )const
{
f=nutritionarray[Nutritionlength].food;
p=nutritionarray[Nutritionlength].portion;


}


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


}


double Nutrition::calories()
{
int total,calories ,i,gainedcalories;

for(i=0;i>4;i++)
{
nutritionarray.food;
nutritionarray.portion;


if (nutritionarray.food=="Carbohydrates"){
calories=90*nutritionarray.portion;


}
else if (nutritionarray.food=="Protein"){
calories=70*nutritionarray.portion;


}
else if (nutritionarray.food=="Vitamins"){
calories=50*nutritionarray.portion;


}
else if (nutritionarray.food=="Water"){
calories=10*nutritionarray.portion;


}


total+=calories;
}


gainedcalories=total/100;


return gainedcalories;


}


void Nutrition:: 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,string f,int p,string n,double e)
{
Gymnasium::set(ex,T);
Nutrition::set(f,p);
info.name=n;
info.energy=e;



}


void Patient::get(string& ex,int& T ,string& f ,int& p,string&
n,double&e)const
{
Gymnasium::getActivities(ex,T);
Nutrition::getMeals(f,p);
n=info.name;
e=info.energy;


}


void Patient::print()
{

cout<<"Before the regime"<<info.name<<"energy was
"<<calories()<<"calories"<<endl;
Regime::print();
Gymnasium::print();
Nutrition::print();



}


Patient::patient(string ex,int T,string f,int p,string n,double
e):Gymnasium(ex,T),Nutrition(f,p),
Regime(ex,T,f,p)
{
n=info.name;
e=info.energy;


}


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 ex,int T,string f,int p)
{
exercisePlan.set(ex,T);
dietPlan.set(f,p);



}


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


}


Regime::Regime(string ex,int T,string f,int p)
{
exercisePlan.set(ex,T);
dietPlan.set(f,p);


}


double Regime::calories()
{
int After;

After=dietPlan.calories()- exercisePlan.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;


int T,p ;
string f , ex , n;
double e;


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


ifstream inFile;


inFile.open("patientActivities.txt");


inFile>>ex>>T;


inFile.close();


inFile.open("patientMeals.txt");


inFile>>f>>p;


inFile.close();


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


A.print();


return 0;
 
M

Michael DOUBEZ

CuTe_Engineer a écrit :
hii,

can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,

Everything is not fine because the program compiles.

You should learn how to use arrays. I suspect you try to use C++ as a
dynamically typed language and expect arrays to be smart.

Example from your code bellow:
activities gymarray[5];
const int gymlength=5;
void Gymnasium::set(string ex , int T )
{


gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;

index of an array should be 0 <= index < gymlength.
Here you are writing outside the array.

Writing at the end of an array doesn't increase it size.
void Gymnasium::getActivities(string& ex , int& T )const
{

ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;

Here again you get a value outside the array.

I suspect you were expecting to tables: one of of exercises and one of
times. I doen't work this way: from an array of activities you can only
access individual elements (gymarray).

So you method must return a specific element in the array or you have to
construct the arrays you want.

Michael
 
C

CuTe_Engineer

CuTe_Engineer a écrit :
can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,

Everything is not fine because the program compiles.

You should learn how to use arrays. I suspect you try to use C++ as a
dynamically typed language and expect arrays to be smart.

Example from your code bellow:
activities gymarray[5];
const int gymlength=5;
void Gymnasium::set(string ex , int T )
{
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;

index of an array should be 0 <= index < gymlength.
Here you are writing outside the array.

Writing at the end of an array doesn't increase it size.
}
void Gymnasium::getActivities(string& ex , int& T )const
{
ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;

Here again you get a value outside the array.

I suspect you were expecting to tables: one of of exercises and one of
times. I doen't work this way: from an array of activities you can only
access individual elements (gymarray).

So you method must return a specific element in the array or you have to
construct the arrays you want.

Michael


so it should be two dimensional array so that i`l be able to access
the exercise and the time right?
like:
gymarray[j]
 
J

Juha Nieminen

CuTe_Engineer said:
can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,
soo plz can you help me un finding my mistake
i will past the proramme here ,

Would it be too much to ask if you tried to find the problem yourself
first and only then, after not being successful, you could ask properly
by
1) telling what is it that the program is supposed to do,
2) telling how it is malfunctioning
3) telling what you tried to do, or where do you think the mistake
might be,
4) posting a *minimal* version of the program which reproduces the
problem instead of just dumping the the entire program, without any
info, without the slightest sign of you even having tried to solve the
problem yourself, so that others will do the hard work for you.

You cannot always rely on other people solving your problems. You have
to learn to solve them yourself, and also to at least *try* to solve
them and if you don't succeed, to at least do the majority of the work
hunting the bug so that you can ask others properly about the problem
and not just burden them with the entire thing.
 
D

Dave Shooter

CuTe_Engineer said:
hii,

can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,
soo plz can you help me un finding my mistake
i will past the proramme here ,

class Patient:public Gymnasium , public Nutrition,public Regime
{
public:
void set(string,int,string,int,string,double);
void get(string&,int& ,string& ,int&,string&,double&)const;
void print();
Patient(string= "",int=0,string="",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;
};

<snip>

Public inheritance models an 'is-a' relationship between entities where,
generally, the derived class (eg Patient) is a specialised version of
the more general base class. The Patient declaration here effectively
states that a Patient is a kind of Gymnasium, is a kind of Nutrition and
is a kind of Regime. Obviously I don't have the specification for your
program, but in terms of Object-Orientated Design, the use of multiple
inheritance here doesn't strike me as a correct design choice.
 
C

CuTe_Engineer

Would it be too much to ask if you tried to find the problem yourself
first and only then, after not being successful, you could ask properly
by
1) telling what is it that the program is supposed to do,
2) telling how it is malfunctioning
3) telling what you tried to do, or where do you think the mistake
might be,
4) posting a *minimal* version of the program which reproduces the
problem instead of just dumping the the entire program, without any
info, without the slightest sign of you even having tried to solve the
problem yourself, so that others will do the hard work for you.

You cannot always rely on other people solving your problems. You have
to learn to solve them yourself, and also to at least *try* to solve
them and if you don't succeed, to at least do the majority of the work
hunting the bug so that you can ask others properly about the problem
and not just burden them with the entire thing.

okey sorry and i`ll not ASK you to solve my problems
3) telling what you tried to do, or where do you think the mistake
might be,

if i know where are my mistake i`ll not ask you for a help
1) telling what is it that the program is supposed to do,
i think if you read what i wrote you will know what is it that the
program is supposed to do
and also to at least *try* to solve
them and if you don't succeed, to at least do the majority of the work
hunting the bug so that you can ask others properly about the problem
and not just burden them with the entire thing.

actualy i did the majority of the work but the programme it`s not
working if i know why i won`t ask for help
 
O

osmium

Dave Shooter said:
<snip>

Public inheritance models an 'is-a' relationship between entities where,
generally, the derived class (eg Patient) is a specialised version of
the more general base class. The Patient declaration here effectively
states that a Patient is a kind of Gymnasium, is a kind of Nutrition and
is a kind of Regime. Obviously I don't have the specification for your
program, but in terms of Object-Orientated Design, the use of multiple
inheritance here doesn't strike me as a correct design choice.

In particular, note that a gymnasium is a building and a patient is a human
being. Note also that a patient "is -a" Regime and it also *has* a Regime.
Usually, it would be one or the other ("is-a", "has-a"). If you were
earlier given a less cumbersome assignment to learn inheritance, now would
be a good time to go back and do it.
 
O

osmium

:

can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,

int main()
{
Patient A;

You have just constructed a Patient with six default parameters, in other
words, a patient about whom nothing whatsoever is known. What it the proper
output of your program when this happens? In American idiom, my response
would be "You have got to be kidding!". I note that the parameters include
such meaningless variables such as f, T, and p.

What useful information could *any* program possibly compute when no input
is provided? You get some data from the user but then you proceed to
totally ignore it. It is crucial that the order in which things are done is
proper.

If the instructor told you that a default constructor must be possible, you
will have to, by program, detect the nonsensical attempts to use the end
result of such a constructor. I would defer this work to the end after the
main program is pretty well working. This is the wrong order of work for a
real programmer, but you are not a real programmer.
 
J

Juha Nieminen

CuTe_Engineer said:
okey sorry and i`ll not ASK you to solve my problems

That kind of attitude is not the best one if you really want people to
help you.
"Here's the program, it doesn't work, fix it" is an obnoxious request.
actualy i did the majority of the work but the programme it`s not
working if i know why i won`t ask for help

You did not tell anything about what you have done, what the program
is supposed to do and how it's misbehaving. You have to help people to
help you.
 
B

BobR

CuTe_Engineer wrote in message...

/* """
CuTe_Engineer a écrit :
hii,
can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not
working ,

Everything is not fine because the program compiles.

You should learn how to use arrays. I suspect you try to use C++ as a
dynamically typed language and expect arrays to be smart.

Example from your code bellow:
activities gymarray[5];
const int gymlength=5;
void Gymnasium::set(string ex , int T ){
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;

index of an array should be 0 <= index < gymlength.
Here you are writing outside the array.

Writing at the end of an array doesn't increase it size.
}
void Gymnasium::getActivities(string& ex , int& T )const{
ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;

Here again you get a value outside the array.

I suspect you were expecting to tables: one of of exercises and one of
times. I doen't work this way: from an array of activities you can only
access individual elements (gymarray).

So you method must return a specific element in the array or you have to
construct the arrays you want.

so it should be two dimensional array so that i`l be able to access
the exercise and the time right?
like:
gymarray[j]

""" */

No. Your array is:

activities gymarray[5];

That means you can only access:

gymarray[0]; // first element
gymarray[1];
gymarray[2];
gymarray[3];
gymarray[4]; // last element

But, when you use gymlength (which == 5), then you are doing:

gymarray[5];

.... which is outside the array!
 
O

osmium

cute_engineer said:
void Patient::get(string& ex,int& T ,string& f ,int& p,string&
n,double&e)const
{
Gymnasium::getActivities(ex,T);
Nutrition::getMeals(f,p);
n=info.name;
e=info.energy;

The '=' symbol does *not* mean equal. Try to figure out what it does mean
and incorporate your findings into your program.
 
A

arnuld

okey sorry and i`ll not ASK you to solve my problems

Aye... What should I think of you ?

if i know where are my mistake i`ll not ask you for a help

What kind of man you are ?

So you are ... CuTe_Engineer.... hmmm.....

let me think ....

...... you seem like a TROLL to me
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top