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.










share|improve this question























  • "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















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.










share|improve this question























  • "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













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.










share|improve this question















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++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • "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


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo