Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. //base class validation
  4. struct validation
  5. {
  6. validation(){}
  7. ~validation(){ delete is_val; }
  8. //pure virtual function to enforce reimplementation
  9. virtual void menu() = 0;
  10. virtual bool isValid() = 0;
  11.  
  12. protected:
  13. std::string str;
  14. validation* is_val;
  15. };
  16.  
  17. //function foward declaration
  18. void menu_All();
  19.  
  20. int main()
  21. {
  22. menu_All();
  23. return 0;
  24. }
  25.  
  26. struct gmail: validation
  27. {
  28. gmail(){}
  29.  
  30. gmail(std::string mail): _mail(mail){}
  31.  
  32. ~gmail()
  33. {
  34. delete is_val;
  35. _mail.clear();
  36. }
  37.  
  38. bool isValid()
  39. {
  40. std::string server("@gmail.com");
  41.  
  42. std::string piece(_mail.substr(_mail.size()-server.size()));
  43.  
  44. return !piece.compare(server);
  45. }
  46.  
  47. void menu()
  48. {
  49. do{
  50. std::cout<<"\n\tEnter your google e-mail: ";
  51. std::cin>>str;
  52.  
  53. is_val = new gmail(str);
  54.  
  55. if(is_val->isValid())
  56. std::cout<<"\n\tEmail: " << str << " is Valid.\n\n";
  57. else
  58. std::cout<<"\n\tEmail: " << str << " is Invalid.\n\n";
  59.  
  60. }while(!is_val->isValid());
  61. }
  62.  
  63. private:
  64. std::string _mail;
  65. };
  66.  
  67. struct uol: validation
  68. {
  69. uol(){}
  70.  
  71. uol(std::string mail): _mail(mail){}
  72.  
  73. ~uol()
  74. {
  75. delete is_val;
  76. _mail.clear();
  77. }
  78.  
  79. bool isValid()
  80. {
  81. std::string server("@uol.com.br");
  82.  
  83. std::string piece(_mail.substr(_mail.size()-server.size()));
  84.  
  85. return !piece.compare(server);
  86. }
  87.  
  88. void menu()
  89. {
  90. do{
  91. std::cout<<"\n\tEnter your uol e-mail: ";
  92. std::cin>>str;
  93.  
  94. is_val = new uol(str);
  95.  
  96. if(is_val->isValid())
  97. std::cout<<"\n\tEmail: " << str << " is Valid.\n\n";
  98. else
  99. std::cout<<"\n\tEmail: " << str << " is Invalid.\n\n";
  100.  
  101. }while(!is_val->isValid());
  102. }
  103.  
  104. private:
  105. std::string _mail;
  106. };
  107.  
  108. struct bol: validation
  109. {
  110. bol(){}
  111.  
  112. bol(std::string mail): _mail(mail){}
  113.  
  114. ~bol()
  115. {
  116. delete is_val;
  117. _mail.clear();
  118. }
  119.  
  120. bool isValid()
  121. {
  122. std::string server("@bol.com.br");
  123.  
  124. std::string piece(_mail.substr(_mail.size()-server.size()));
  125.  
  126. return !piece.compare(server);
  127. }
  128.  
  129. void menu()
  130. {
  131. do{
  132. std::cout<<"\n\tEnter your bol e-mail: ";
  133. std::cin>>str;
  134.  
  135. is_val = new bol(str);
  136.  
  137. if(is_val->isValid())
  138. std::cout<<"\n\tEmail: " << str << " is Valid.\n\n";
  139. else
  140. std::cout<<"\n\tEmail: " << str << " is Invalid.\n\n";
  141.  
  142. }while(!is_val->isValid());
  143. }
  144.  
  145. private:
  146. std::string _mail;
  147. };
  148.  
  149. void menu_All()
  150. {
  151. int op;
  152. validation* m_val;
  153.  
  154. enum { Gmail=1, Uol, Bol, Exit };
  155.  
  156. do{
  157. std::cout << "\n\tValidation e-mail"
  158. "\n\t[1]-Gmail"
  159. "\n\t[2]-Uol"
  160. "\n\t[3]-Bol"
  161. "\n\t[4]-Exit"
  162. "\n\tEnter: ";
  163. std::cin>>op;
  164.  
  165. switch(op)
  166. {
  167. case Gmail:
  168.  
  169. m_val = new gmail();
  170.  
  171. m_val->menu();
  172.  
  173. break;
  174.  
  175. case Uol:
  176.  
  177. m_val = new uol();
  178.  
  179. m_val->menu();
  180.  
  181. break;
  182.  
  183. case Bol:
  184.  
  185. m_val = new bol();
  186.  
  187. m_val->menu();
  188.  
  189. break;
  190.  
  191. case Exit:
  192.  
  193. std::cout << "\n\tGood Bye!\n\n";
  194. exit(1);
  195.  
  196. break;
  197.  
  198. default:
  199.  
  200. std::cout << "\n\tInvalid Option!\n\n";
  201.  
  202. break;
  203. }
  204. }while(1);
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement