Guest User

Untitled

a guest
Jul 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class customerdata
  6. {
  7. private:
  8. int id;
  9. int age;
  10. int creditcard;
  11. int phonenumber;
  12.  
  13. public:
  14. void fillvalues()
  15. {
  16. age = 20 + rand() % 41; // random: 20 - 60
  17. creditcard = 1000 + rand() % 9000; // random: 1000 - 9999
  18. phonenumber = 1000000 + rand() % 9000000; // random: 1000000 - 9999999
  19. }
  20.  
  21. void setid(int val)
  22. {
  23. id = val;
  24. }
  25.  
  26. int securitypreference()
  27. {
  28. return rand() % 2; // returns: 0 or 1
  29. }
  30.  
  31. void printsecure()
  32. {
  33. cout << "Customer id: " << id << endl;
  34. cout << "Customer age: " << age << endl;
  35. cout << endl;
  36. }
  37.  
  38. void printall()
  39. {
  40. cout << "Customer id: " << id << endl;
  41. cout << "Customer age: " << age << endl;
  42. cout << "Last 4 digits of card #: " << creditcard << endl;
  43. cout << "Customer phone number: " << phonenumber << endl;
  44. cout << endl;
  45. }
  46. };
  47.  
  48. int main()
  49. {
  50. int input;
  51. int i;
  52. customerdata myarray[50];
  53.  
  54. for (i=0; i<50; i++)
  55. {
  56. myarray[i].setid(i);
  57. myarray[i].fillvalues();
  58. }
  59.  
  60. while(1)
  61. {
  62. cout << "Enter customer id (0 to 49): ";
  63. cin >> input;
  64.  
  65. // 1: secure, 0: not_secure
  66. if (myarray[input].securitypreference() == 1)
  67. {
  68. myarray[input].printsecure();
  69. }
  70. else
  71. {
  72. myarray[input].printall();
  73. }
  74. }
  75.  
  76. return 0;
  77. }
Add Comment
Please, Sign In to add comment