Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cmath>
  6. using namespace std;
  7. class Seller
  8. {
  9. public:
  10. Seller();
  11. Seller( const char [], const char[], const char [], double );
  12.  
  13. void print();
  14.  
  15. void setFirstName( const char [] );
  16. void setLastName( const char [] );
  17. void setID( const char [] );
  18. void setSalesTotal( double );
  19.  
  20. double getSalesTotal();
  21.  
  22. private:
  23. char firstName[20];
  24. char lastName[30];
  25. char ID[7];
  26. double SalesTotal;
  27. };
  28. int main()
  29. {
  30. Seller first = Seller("Luke","Schwaller","CSCI240",1234.56);
  31. Seller second = Seller();
  32. Seller third = Seller("","Johnson","TOOBIG999",876.34);
  33. Seller fourth = Seller("James","Hellwig","ULTWAR",13579.11);
  34. Seller fifth = Seller("Roderick","Toombs","PIPER4",24680.24);
  35.  
  36.  
  37.  
  38. cout<<" **** The first Seller object ****"<<endl<<endl;
  39. first.print();
  40. cout<<"\n\n**** The second Seller object ****"<<endl<<endl;
  41. second.print();
  42. second.setFirstName("Terry") ;
  43. second.setLastName("Bollea");
  44. second.setID("HULK96");
  45. second.setSalesTotal(246.80);
  46. second.print();
  47. cout<<"\n\n*** The third Seller object ***"<<endl<<endl;
  48. third.print();
  49. third.setFirstName("Dwayne");
  50. third.setID("ROCK89");
  51. third.print();
  52. cout<<"\n\n*** The fourth Seller object ***"<<endl<<endl;
  53. fourth.print();
  54. cout<<"\n\n*** The fifth Seller object ***"<<endl<<endl;
  55. fifth.print();
  56. fifth.setFirstName("");
  57. fifth.setLastName("");
  58. fifth.setID("");
  59. fifth.setSalesTotal(-19.88);
  60.  
  61. }
  62. void Seller::print()
  63. {
  64. cout<<firstName[1]<<", "<<lastName[1]<<setw(15)<<ID[1]<<SalesTotal;
  65. }
  66. void Seller::setFirstName(const char newFirstName[])
  67. {
  68. if( strlen(newFirstName) > 0 )
  69. {
  70. strcpy(firstName, newFirstName);
  71. }
  72. else
  73. {
  74. strcpy( firstName, "None");
  75. }
  76. }
  77. void Seller::setLastName(const char newLastName[])
  78. {
  79.  
  80. if( strlen(newLastName) > 0 )
  81. {
  82. strcpy(lastName, newLastName);
  83. }
  84. else
  85. {
  86. strcpy( lastName, "None");
  87. }
  88. }
  89. void Seller::setID(const char newID[])
  90. {
  91.  
  92. if( strlen(newID) > 0 )
  93. {
  94. if (strlen(newID)< 7)
  95. {
  96.  
  97. strcpy(ID, newID);
  98. }
  99. }
  100. else
  101. {
  102. strcpy( ID, "None");
  103. }
  104. }
  105. void Seller::setSalesTotal(double newSalesTotal)
  106. {
  107. if(newSalesTotal < 0)
  108. {
  109. SalesTotal = newSalesTotal;
  110. }
  111. else
  112. {
  113. SalesTotal = 0;
  114. }
  115. }
  116. double Seller::getSalesTotal()
  117. {
  118. return SalesTotal;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement