473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

design question regarding multiple update

Say you have a class:

stuct Updater{
int _v1;
int _v2
int _v3;

update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.

Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.

The same for v2, and v3 respectively.
Thanks
Sep 11 '08 #1
8 1061
On Sep 11, 11:05*am, puzzlecracker <ironsel2...@gmail.comwrote:
Say you have a class:

stuct Updater{
* int _v1;
* int *_v2
* int *_v3;

update(int v1, int v2, int v2);
bool isBad(int val);

};

Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.

Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.

The same for v2, and v3 respectively.

Thanks
Ok, did you have a question?
Socks
Sep 11 '08 #2
On Sep 11, 12:13*pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Sep 11, 11:05*am, puzzlecracker <ironsel2...@gmail.comwrote:
Say you have a class:
stuct Updater{
* int _v1;
* int *_v2
* int *_v3;
update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.
Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.
The same for v2, and v3 respectively.
Thanks

Ok, did you have a question?
Socks
How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.
Sep 11 '08 #3
puzzlecracker wrote:
On Sep 11, 12:13 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
>On Sep 11, 11:05 am, puzzlecracker <ironsel2...@gmail.comwrote:
>>Say you have a class:
stuct Updater{
int _v1;
int _v2
int _v3;
update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.
Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.
The same for v2, and v3 respectively.
Thanks
Ok, did you have a question?
Socks

How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.
Like this:
stuct Updater{
int _v1;
int _v2
int _v3;

void update(int v1, int v2, int v2);
bool isBad(int val);
};

You only need to implement update and isBad methods.

This might help you solve the problem :
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
Sep 11 '08 #4
On Sep 11, 12:39*pm, anon <a...@no.invalidwrote:
puzzlecracker wrote:
On Sep 11, 12:13 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Sep 11, 11:05 am, puzzlecracker <ironsel2...@gmail.comwrote:
>Say you have a class:
stuct Updater{
* int _v1;
* int *_v2
* int *_v3;
update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.
Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.
The same for v2, and v3 respectively.
Thanks
Ok, did you have a question?
Socks
How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.

Like this:
stuct Updater{
* *int _v1;
* *int *_v2
* *int *_v3;

void update(int v1, int v2, int v2);
bool isBad(int val);

};

You only need to implement update and isBad methods.

This might help you solve the problem :http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
dude, I am looking for a design pattern for this sort of problem,
not a jerk-like response.
Sep 11 '08 #5
puzzlecracker wrote:
On Sep 11, 12:39 pm, anon <a...@no.invalidwrote:
>puzzlecracker wrote:
>>On Sep 11, 12:13 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Sep 11, 11:05 am, puzzlecracker <ironsel2...@gmail.comwrote:
Say you have a class:
stuct Updater{
int _v1;
int _v2
int _v3;
update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.
Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.
The same for v2, and v3 respectively.
Thanks
Ok, did you have a question?
Socks
How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.
Like this:
stuct Updater{
int _v1;
int _v2
int _v3;

void update(int v1, int v2, int v2);
bool isBad(int val);

};

You only need to implement update and isBad methods.

This might help you solve the problem :http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

dude, I am looking for a design pattern for this sort of problem,
not a jerk-like response.
The pattern is sitting in front of a PC with a C++ book and study. This
is at least the second exercise you post in the newsgroup, don't expect
to have easy time in finding people that let you dodge your homework.

Best wishes,

Zeppe
Sep 11 '08 #6
On Sep 11, 12:47*pm, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
puzzlecracker wrote:
On Sep 11, 12:39 pm, anon <a...@no.invalidwrote:
puzzlecracker wrote:
On Sep 11, 12:13 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Sep 11, 11:05 am, puzzlecracker <ironsel2...@gmail.comwrote:
Say you have a class:
stuct Updater{
* int _v1;
* int *_v2
* int *_v3;
update(int v1, int v2, int v2);
bool isBad(int val);
};
Each time update is called, you want to update all the members
respectively, However, if you one of the v's is bad, you try other
vals, if they are good, to update it.
Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
it v3, otherwise, you set it to 0.
The same for v2, and v3 respectively.
Thanks
Ok, did you have a question?
Socks
How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.
Like this:
stuct Updater{
* *int _v1;
* *int *_v2
* *int *_v3;
void update(int v1, int v2, int v2);
bool isBad(int val);
};
You only need to implement update and isBad methods.
This might help you solve the problem :http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
dude, * I am looking for a design pattern for this sort of problem,
not a jerk-like response.

The pattern is sitting in front of a PC with a C++ book and study. This
is at least the second exercise you post in the newsgroup, don't expect
to have easy time in finding people that let you dodge your homework.

Best wishes,

Zeppe
Funny, really.... I am actually working professional and this is a
simple version of a problem I am working on... done with school, many,
many years ago... For now, I use lots of ifs to solve it, and I think
there is a general pattern.

Anyway
Sep 11 '08 #7
puzzlecracker wrote:
>>dude, I am looking for a design pattern for this sort of problem,
not a jerk-like response.
The pattern is sitting in front of a PC with a C++ book and study. This
is at least the second exercise you post in the newsgroup, don't expect
to have easy time in finding people that let you dodge your homework.

Best wishes,

Zeppe

Funny, really.... I am actually working professional and this is a
simple version of a problem I am working on... done with school, many,
many years ago... For now, I use lots of ifs to solve it, and I think
there is a general pattern.
"Professional" is a really strong word.

--
Gennaro Prota | name.surname yahoo.com
Breeze C++ (preview): <https://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
Sep 11 '08 #8
On Sep 12, 5:05 am, Michael DOUBEZ <michael.dou...@free.frwrote:
puzzlecracker a écrit :
On Sep 11, 12:47 pm, Zeppe
<ze...@remove.all.this.long.comment.yahoo.itwrot e:
puzzlecracker wrote:
On Sep 11, 12:39 pm, anon <a...@no.invalidwrote:
puzzlecracker wrote:
On Sep 11, 12:13 pm, Puppet_Sock <puppet_s...@hotmail.comwrote:
On Sep 11, 11:05 am, puzzlecracker <ironsel2...@gmail.comwrote:
>Say you have a class:
>stuct Updater{
> int _v1;
> int _v2
> int _v3;
>update(int v1, int v2, int v2);
>bool isBad(int val);
>};
>Each time update is called, you want to update all the members
>respectively, However, if you one of the v's is bad, you try other
>vals, if they are good, to update it.
>Say v1 is bad, then you try set it to v2, if v2 is bad, then you set
>it v3, otherwise, you set it to 0.
>The same for v2, and v3 respectively.
>Thanks
Ok, did you have a question?
Socks
How to design this sort architecture? I thought it was straightforward
from my description as well as subject line.
Like this:
stuct Updater{
int _v1;
int _v2
int _v3;
void update(int v1, int v2, int v2);
bool isBad(int val);
};
You only need to implement update and isBad methods.
This might help you solve the problem :http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
dude, I am looking for a design pattern for this sort of problem,
not a jerk-like response.
The pattern is sitting in front of a PC with a C++ book and study. This
is at least the second exercise you post in the newsgroup, don't expect
to have easy time in finding people that let you dodge your homework.
Best wishes,
Zeppe
Funny, really.... I am actually working professional and this is a
simple version of a problem I am working on... done with school, many,
many years ago... For now, I use lots of ifs to solve it, and I think
there is a general pattern.

You can define a function that returns the first value valid and a
fallback otherwise:

int getFirstValid(int a, int b, int c,int fallback)
{
return isBad(a)?isBad(b)?isBad(c)?
fallback:c:b:a;

}

And then:
void update(int v1, int v2, int v2)
{
_v1=getFirstValid(v1,v2,v3,0);
_v2=getFirstValid(v2,v3,v1,0);
_v3=getFirstValid(v3,v1,v2,0);

}

If it bothers you to test multiple times the validity of a value, there
is a more obfuscated version with any number of parameter:

void update(int v1, int v2, int v3,...,v42)
{
//computing first value valid in range
const int after_v41=isBad(v41)?v42:v41;
const int after_v40=isBad(v40)?after_v41:v40;
...
const int after_v1 =isBad(1)?after_2:v1;

//values valid ?

if(isBad(after_v1))
{ //all parameters are bad
//set to fallback
_v1=_v2=_v3=..=_v42=0;
retun;
}

_v1=after_v1;
_v2=isBad(after_v2)?after_v1:after_v2;
_v3=isBad(after_v3)?after_v1:after_v3;
...
//here you can even gain some comparison
// as soon as sBad(after_v3)=true,
//all values vX-v42 takes value after_v1
...
_v42=isBad(42)?after_v1:v42;

}

--
Michael

Thanks, I found a simpler solution:
Updater::update(int v1, int v2, int v2)
{
bool a= isbad(v1),
b= isBad(v2),
c= isbad(v3);

_v1 = a ? (b ? (c ? 0 : v3) : v2) : v1;
_v2 = b ? (a ? (c ? 0 : v3) : v1) : v2;
_v3 = c ? (a ? (b ? 0 : v2) : v1) : v3;
}
Sep 14 '08 #9

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

Similar topics

9
by: Patchwork | last post by:
Hi Everyone, I have a design related question (in C++) that I am hoping someone can help me with. It is related to my previous post but since it was pointed out that I was more or less asking...
1
by: madunix | last post by:
We are a public utility institution established by virtue of the Securities Law. The Company oversees securities' registration, deposit, transfer of ownership and clearing and settlement. The...
3
by: Sorin Dolha | last post by:
Hello, We intend to create an ASP.NET-based Web application (hosted on Internet Information Services, or IIS) and one feature of the application needs to allow the end user to upload photos to...
10
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post...
2
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the...
3
by: reageer | last post by:
Hi all, I have a design question: I have a bunch of users (name, address, zip, etc.). They are assigned a card with a specific id. The only thing unique is this card id, or probably the...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...
0
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...

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.