Implementing an on/off switch for high level validation? C++
up vote
-4
down vote
favorite
I am looking for some guidance.
Part of my current homework is to implement a "switch" that the user chooses at the beginning of the program. If they choose "yes" it will turn on high-level validation (functions that will make sure the user enters valid input and not exit program immediately), if they chose "no" then it turns that off, and I rely on low-level input validation with exit_failures.
Some context: C++; we are practicing inheritance and slight polymorphism; one base class and two derived classes; the main array is an array of object pointers. Let me know if you need more context.
I'm imagining this in a few ways...
1.) Using a switch case, if they enter 1 for yes, then one program with high lvl validation begins, if they enter 2 for no, then a separate program begins without high lvl validation. That seems silly. 2 programs in one? Doesn't sound something any mildly-savvy programmer would do.
2.) Getting "yes" or "no" for input and using that as a global variable value or passing it to every function. With a bunch of if conditions that will guide the program if user chooses yes or no. This also seems tedious and silly, and I can't use global variables for it.
3.) There must be a more slick way to do this. I feel like I'm over complicating this "switch" concept, but I also am not seeing how it could be easily implemented.
Any tips or hints? I don't want to get too deep into my program if this switch concept will cause a lot of back-coding. Thank you!
edit: Sorry... I did post this to another site. Just trying to increase my chances of getting assistance, and different points of view.
c++
|
show 4 more comments
up vote
-4
down vote
favorite
I am looking for some guidance.
Part of my current homework is to implement a "switch" that the user chooses at the beginning of the program. If they choose "yes" it will turn on high-level validation (functions that will make sure the user enters valid input and not exit program immediately), if they chose "no" then it turns that off, and I rely on low-level input validation with exit_failures.
Some context: C++; we are practicing inheritance and slight polymorphism; one base class and two derived classes; the main array is an array of object pointers. Let me know if you need more context.
I'm imagining this in a few ways...
1.) Using a switch case, if they enter 1 for yes, then one program with high lvl validation begins, if they enter 2 for no, then a separate program begins without high lvl validation. That seems silly. 2 programs in one? Doesn't sound something any mildly-savvy programmer would do.
2.) Getting "yes" or "no" for input and using that as a global variable value or passing it to every function. With a bunch of if conditions that will guide the program if user chooses yes or no. This also seems tedious and silly, and I can't use global variables for it.
3.) There must be a more slick way to do this. I feel like I'm over complicating this "switch" concept, but I also am not seeing how it could be easily implemented.
Any tips or hints? I don't want to get too deep into my program if this switch concept will cause a lot of back-coding. Thank you!
edit: Sorry... I did post this to another site. Just trying to increase my chances of getting assistance, and different points of view.
c++
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
1
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
2
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34
|
show 4 more comments
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I am looking for some guidance.
Part of my current homework is to implement a "switch" that the user chooses at the beginning of the program. If they choose "yes" it will turn on high-level validation (functions that will make sure the user enters valid input and not exit program immediately), if they chose "no" then it turns that off, and I rely on low-level input validation with exit_failures.
Some context: C++; we are practicing inheritance and slight polymorphism; one base class and two derived classes; the main array is an array of object pointers. Let me know if you need more context.
I'm imagining this in a few ways...
1.) Using a switch case, if they enter 1 for yes, then one program with high lvl validation begins, if they enter 2 for no, then a separate program begins without high lvl validation. That seems silly. 2 programs in one? Doesn't sound something any mildly-savvy programmer would do.
2.) Getting "yes" or "no" for input and using that as a global variable value or passing it to every function. With a bunch of if conditions that will guide the program if user chooses yes or no. This also seems tedious and silly, and I can't use global variables for it.
3.) There must be a more slick way to do this. I feel like I'm over complicating this "switch" concept, but I also am not seeing how it could be easily implemented.
Any tips or hints? I don't want to get too deep into my program if this switch concept will cause a lot of back-coding. Thank you!
edit: Sorry... I did post this to another site. Just trying to increase my chances of getting assistance, and different points of view.
c++
I am looking for some guidance.
Part of my current homework is to implement a "switch" that the user chooses at the beginning of the program. If they choose "yes" it will turn on high-level validation (functions that will make sure the user enters valid input and not exit program immediately), if they chose "no" then it turns that off, and I rely on low-level input validation with exit_failures.
Some context: C++; we are practicing inheritance and slight polymorphism; one base class and two derived classes; the main array is an array of object pointers. Let me know if you need more context.
I'm imagining this in a few ways...
1.) Using a switch case, if they enter 1 for yes, then one program with high lvl validation begins, if they enter 2 for no, then a separate program begins without high lvl validation. That seems silly. 2 programs in one? Doesn't sound something any mildly-savvy programmer would do.
2.) Getting "yes" or "no" for input and using that as a global variable value or passing it to every function. With a bunch of if conditions that will guide the program if user chooses yes or no. This also seems tedious and silly, and I can't use global variables for it.
3.) There must be a more slick way to do this. I feel like I'm over complicating this "switch" concept, but I also am not seeing how it could be easily implemented.
Any tips or hints? I don't want to get too deep into my program if this switch concept will cause a lot of back-coding. Thank you!
edit: Sorry... I did post this to another site. Just trying to increase my chances of getting assistance, and different points of view.
c++
c++
edited Nov 9 at 19:28
asked Nov 9 at 19:21
Glenn Oberlander
11
11
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
1
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
2
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34
|
show 4 more comments
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
1
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
2
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
1
1
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
2
2
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232064%2fimplementing-an-on-off-switch-for-high-level-validation-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I've tried to search SO for this question, but no luck. I will likely post there as well" is this a copy&paste of a question you already posted on a different site?
– user463035818
Nov 9 at 19:22
1
"I feel like I'm over complicating" ... i have the same feeling. Explaining code with words is always more compilcated than the code itself. Please add some example code to your question
– user463035818
Nov 9 at 19:24
2
Sounds like your instructor wants to to utilize polymorhism where you implement a "safe" derived class and a "unsafe" derived class and call all the functions through a common interface. Your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class.
– NathanOliver
Nov 9 at 19:26
@user463035818 I felt this was more of a concept idea to discuss and that code wasn't entirely necessary to figure out a useful way to do it. And yes, I did post this to another site (see edit).
– Glenn Oberlander
Nov 9 at 19:30
@NathanOliver Could you elaborate on what you mean by, "your runtime switch would then tell you to populate the array/pointer with the safe or unsafe class." If we have a base class and two derived classes, would I double those classes to have a safe and unsafe version?
– Glenn Oberlander
Nov 9 at 19:34