473,480 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

what is my mistake

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[i].exercises=="OpenGym"){
calories=680*gymarray[i].time;
}
else if (gymarray[i].exercises=="Treadmill"){
calories=820*gymarray[i].time;
}
else if (gymarray[i].exercises=="Bike"){
calories=620*gymarray[i].time;
}
else if (gymarray[i].exercises=="Fitness"){
calories=740*gymarray[i].time;
}
else if (gymarray[i].exercises=="Hoop"){
calories=210*gymarray[i].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[i].food;
nutritionarray[i].portion;
if (nutritionarray[i].food=="Carbohydrates"){
calories=90*nutritionarray[i].portion;
}
else if (nutritionarray[i].food=="Protein"){
calories=70*nutritionarray[i].portion;
}
else if (nutritionarray[i].food=="Vitamins"){
calories=50*nutritionarray[i].portion;
}
else if (nutritionarray[i].food=="Water"){
calories=10*nutritionarray[i].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;

Oct 28 '07 #1
7 1709
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[i]).

So you method must return a specific element in the array or you have to
construct the arrays you want.
}
Michael
Oct 28 '07 #2
On Oct 28, 9:51 am, Michael DOUBEZ <michael.dou...@free.frwrote:
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[i]).

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[i][j]

Oct 28 '07 #3
CuTe_Engineer wrote:
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.
Oct 28 '07 #4
On Oct 28, 12:20 pm, Juha Nieminen <nos...@thanks.invalidwrote:
CuTe_Engineer wrote:
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.
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
Oct 28 '07 #5

CuTe_Engineer wrote in message...

/* """
On Oct 28, 9:51 am, Michael DOUBEZ <michael.dou...@free.frwrote:
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[i]).

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[i][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!

--
Bob R
POVrookie
Oct 29 '07 #6
cute_engineer wrote:
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.
}

Oct 29 '07 #7
On Sun, 28 Oct 2007 05:45:19 -0700, CuTe_Engineer wrote:

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

Oct 31 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2013
by: PassingBy | last post by:
I recently came across a template site selling cd's and was wondering what the groups opinion is of this? I purchased one of the cd's and the templates are great and Im looking forward to...
47
4480
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
41
1905
by: Greenhorn | last post by:
Hi, We see that C is a bit liberal towards non-standard syntax, for e.g. when i tried <printf("string1", "string2 %d", v1);> in Dev-C++, it printed string1 and no error was raised, is this the...
20
4965
by: yaron | last post by:
Hi, 1. I am familiar with .NET 1.1 and not with .NET 2.0 . if i should start a new networking project should i write it with .net 2.0 beta or write it with .net 1.1 ? 2. What are the...
19
1750
by: Fernando Cacciola | last post by:
I'm puzzled, Why and how _exactly_ is this: void Foo<T>(T v ) where T : Interface/Value/Class/class any better than this void Foo( Interface/Value/Class/object v )
1
1329
by: bra49er | last post by:
In November I bought VB 2005 express from amazon. When attempting to install it the program installing said that it was Visual Web developer 2005 and not VB 2005, however all the packaging was...
39
3026
by: VidTheKid | last post by:
THE PROBLEM The % symbol is too vague when defining dimensions in CSS and HTML. It can relate to an inherited value, a measure of the containing element (which can differ between box models) or...
11
1915
by: bobh | last post by:
Hi All, I can't remember what it is called but I know it did have a name I thought I remembered it as a 'cascading event' but I don't think that's what it really is called. senario: your...
25
2647
by: Cromulent | last post by:
On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@comcast.netsaid: Err, no not really as that has nothing to do with stock market prices :). -- "I disapprove of what you say, but I'll defend...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.